How can I modify the code below to work in a SolidWorks drawing instead of a part?
Sub Main()
Set swApp = CreateObject("SldWorks.Application")
Set CurrentDoc = swApp.ActiveDoc
Set Part = swApp.ActiveDoc
' No document loaded error handler
If Part Is Nothing Then
MsgBox "No document loaded!", vbCritical
End
Else
End If
Part.ClearSelection2 True
' Assign custom properties
PropName(0) = "Die Number"
PropName(1) = "Plant"
PropName(2) = "File Name"
PropName(3) = "Press"
PropName(4) = "Drawn Date"
PropName(5) = "Del Date"
PropName(6) = "Bolster"
PropName(7) = "Cavities"
' Add custom properties (won't overwrite if they already exist)
Prop = CurrentDoc.AddCustomInfo3("", PropName(0), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(1), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(2), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(3), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(4), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(5), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(6), swCustomInfoText, " ")
Prop = CurrentDoc.AddCustomInfo3("", PropName(7), swCustomInfoText, " ")
Call CheckProps
End Sub
SolidworksApi macros
Here are the updated codes
<p>Option Explicit</p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim Part As ModelDoc2</p><p>Dim PropName(8) As String</p><p>Dim Prop As Boolean</p><p>Sub Main()</p><p></p><p>Set swApp = CreateObject("SldWorks.Application")</p><p>'Set CurrentDoc = swApp.ActiveDoc 'Not sure why you have this line when next line does the same thing</p><p>Set Part = swApp.ActiveDoc</p><p></p><p>' No document loaded error handler</p><p> If Part Is Nothing Then</p><p> MsgBox "No document loaded!", vbCritical</p><p> End</p><p> Else</p><p> End If</p><p>Part.ClearSelection2 True</p><p></p><p>' Assign custom properties</p><p> PropName(0) = "Die Number"</p><p> PropName(1) = "Plant"</p><p> PropName(2) = "File Name"</p><p> PropName(3) = "Press"</p><p> PropName(4) = "Drawn Date"</p><p> PropName(5) = "Del Date"</p><p> PropName(6) = "Bolster"</p><p> PropName(7) = "Cavities"</p><p></p><p>' Add custom properties (won't overwrite if they already exist)</p><p> Prop = <strong>Part.AddCustomInfo2</strong>(PropName(0), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(1), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(2), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(3), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(4), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(5), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(6), swCustomInfoText, " ")</p><p> Prop = Part.AddCustomInfo2(PropName(7), swCustomInfoText, " ")</p><p></p><p>Call CheckProps</p><p>End Sub</p>Deepak,
What is the difference between AddCustomInfo2 and AddCustomInfo3 ?
AddCustomInfo2 is for custom specific properties and AddCustomInfo3 is for configuration specific properties.