dogarila
Mechanical
- Oct 28, 2001
- 594
How can I get and set the values of "Author" and "Comments" properties from a macro in SolidWorks?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
' Get and Set Summary Info----------------------- 04/13/11
'
' Will not overwrite existing values for Author and Comemnts
'
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta ([URL unfurl="true"]http://gupta9665.wordpress.com/)[/URL]
' ------------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim value As String
Dim svalue As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Debug.Print "File = " + swModel.GetPathName
'Get and set the Author KeyWord in the File Summary Info
value = swModel.SummaryInfo(swSumInfoAuthor)
If value = "" Then
swModel.SummaryInfo(swSumInfoAuthor) = "Author name here"
'Get and set the Comment KeyWord in the File Summary Info
svalue = swModel.SummaryInfo(swSumInfoComment)
If svalue = "" Then
swModel.SummaryInfo(swSumInfoComment) = "Comments Here"
Else
End If
End If
End Sub
' Get and Set Summary Info----------------------- 04/13/11
'
' Will not overwrite existing values for Author and Comemnts
'
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta ([URL unfurl="true"]http://gupta9665.wordpress.com/)[/URL]
' ------------------------------------------------------------------------------
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim bRet As Boolean
Dim value As String
Dim svalue As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Debug.Print "File = " + swModel.GetPathName
'Get and set the Author KeyWord in the File Summary Info
value = swModel.SummaryInfo(swSumInfoAuthor) ' this lines gets the info
If value = "" Then
swModel.SummaryInfo(swSumInfoAuthor) = "Author name here" ' this line sets the info, so put the author name what you want to display
'Get and set the Comment KeyWord in the File Summary Info
svalue = swModel.SummaryInfo(swSumInfoComment)
If svalue = "" Then
swModel.SummaryInfo(swSumInfoComment) = "Comments Here"
Else
End If
End If
End Sub
' Similarly you can use codes for setting up info for
' Title = swModel.SummaryInfo(swSumInfoTitle)
' Subject = swModel.SummaryInfo(swSumInfoSubject)
' Keywords = swModel.SummaryInfo(swSumInfoKeywords)
' For getting the info for follwoing information
' SavedBy = swModel.SummaryInfo(swSumInfoSavedBy)
' CreateDate = swModel.SummaryInfo(swSumInfoCreateDate)
' SaveDate = swModel.SummaryInfo(swSumInfoSaveDate)
Sub main()
Dim swApp As Object
Dim MyProp(1, 5) As String ' If you add more properties, just increment the second number in the bracket
Dim m As Integer
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
'Define custom property names here and add more line for more properties. Just increment the second number in the bracket
MyProp(0, 0) = "File Name"
MyProp(0, 1) = "Material"
MyProp(0, 2) = "Finish"
MyProp(0, 3) = "Weight"
MyProp(0, 4) = "Description"
'Define Property values here add more line for more properties values added above. Just increment the second number in the bracket
MyProp(1, 0) = "$PRP:" & Chr(34) & "SW-File Name" & Chr(34)
MyProp(1, 1) = Chr(34) & "SW-Material" & Chr(34)
MyProp(1, 2) = "-"
MyProp(1, 3) = Chr(34) & "SW-Mass" & Chr(34)
MyProp(1, 4) = "Plate"
For m = 0 To 5 ' If you add more properties, just increment the second number i.e 5 here
retval = Part.AddCustomInfo3("", MyProp(0, m), 30, MyProp(1, m))
Next m
End Sub