Get Custom Property Values on Weldment Cut-list Folders Example (VBA)
This example shows how to get all of the custom property values on the
weldment cut-list folders of a part in an assembly.
'-------------------------------------------------------
' Preconditions:
' 1. Assembly is open.
' 2. At least one part in
the assembly
' has a weldment cut-list folder
' that
has custom properties.
'
' Postconditions: None
'-------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub VisitFeatureCustomProperties(docFeat As SldWorks.Feature)
Dim
custPropMgr As SldWorks.CustomPropertyManager
Dim
propNames As Variant
Dim
vName As Variant
Dim
propName As String
Dim
Value As String
Dim
resolvedValue As String
Set
custPropMgr = docFeat.CustomPropertyManager
If
Not custPropMgr Is Nothing Then
propNames
= custPropMgr.GetNames
If
Not IsEmpty(propNames) Then
Debug.Print
docFeat.Name, docFeat.GetTypeName
For
Each vName In propNames
propName
= vName
Call
custPropMgr.Get2(propName, Value,
resolvedValue)
Debug.Print
"", "", propName, Value, resolvedValue
Next
vName
End
If
End
If
End Sub
Sub VisitDocWeldmentProperties(compDoc As SldWorks.ModelDoc2)
Dim
thisFeat As SldWorks.Feature
Dim
thisSubFeat As SldWorks.Feature
Dim
cutFolder As SldWorks.BodyFolder
Set
thisFeat = compDoc.FirstFeature
Do
While Not thisFeat Is Nothing
Set
thisSubFeat = thisFeat.GetFirstSubFeature
Do
While Not thisSubFeat Is Nothing
If
thisSubFeat.GetTypeName = "CutListFolder"
Then
Set
cutFolder = thisSubFeat.GetSpecificFeature2
End
If
If
Not cutFolder Is Nothing Then
If
cutFolder.GetBodyCount > 0
Then
Call
VisitFeatureCustomProperties(thisSubFeat)
End
If
End
If
Set
thisSubFeat = thisSubFeat.GetNextSubFeature
Loop
Set
thisFeat = thisFeat.GetNextFeature
Loop
End Sub
Sub main()
Set swApp = Application.SldWorks
Set
Part = swApp.ActiveDoc
Set
SelMgr = Part.SelectionManager
boolstatus
= Part.Extension.SelectByID2("1-1@Assemblage",
"COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Dim
selComp As SldWorks.Component2
Dim
refConfig As String
Dim
compDoc As SldWorks.ModelDoc2
Set
selComp = SelMgr.GetSelectedObject6(1,
-1)
Set
compDoc = selComp.GetModelDoc
Dim
configNames As Variant
Dim
vName As Variant
Dim
configName As String
configNames
= compDoc.GetConfigurationNames()
For
Each vName In configNames
configName
= vName
Debug.Print
"-----------------------------------------------"
Debug.Print
"Configuration: " + configName
boolstatus
= compDoc.ShowConfiguration2(configName)
Call
VisitDocWeldmentProperties(compDoc)
Next
vName
End Sub