Instructions
View a component's custom properties without opening the part.
- Preconditions
- component or component's face is selected
- Result
- Message box displays the component's custom properties
Files
Display selected component's custom properties
Code
Module: mMain
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim SelObj As Object
Dim swComp As SldWorks.Component2
Dim swCompModel As SldWorks.ModelDoc2
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim FinalData As New Collection
Dim strFinalText As String
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swSelMgr.GetSelectedObjectCount2(-1) = 0 Then
swApp.SendMsgToUser "Please select a component."
Exit Sub
End If
If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES And swSelMgr.GetSelectedObjectType3(1, -1) <> swSelCOMPONENTS Then
swApp.SendMsgToUser "Please select a component."
Exit Sub
End If
Set SelObj = swSelMgr.GetSelectedObject6(1, -1)
If TypeOf SelObj Is SldWorks.Component2 Then Set swComp = swSelMgr.GetSelectedObject6(1, -1)
If TypeOf SelObj Is SldWorks.Face2 Then Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, -1)
Set swCompModel = swComp.GetModelDoc2
Set FinalData = CustPropData(swCompModel)
strFinalText = Empty
For i = 1 To FinalData.Count
strFinalText = strFinalText & FinalData.Item(i) & vbCrLf
If i Mod 25 = 0 Then
swApp.SendMsgToUser strFinalText
strFinalText = Empty
End If
Next i
swApp.SendMsgToUser strFinalText
End Sub
Module: mCustPropData
Function CustPropData(swModel As SldWorks.ModelDoc2) As Collection
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim vConfigNamesArray As Variant
Dim vConfigName As Variant
Dim vName As Variant
Dim strValue As String
'clear collection
Set CustPropData = New Collection
While CustPropData.Count <> 0
CustPropData.Remove 1
Wend
CustPropData.Add "CUSTOM"
'doc level
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)
vCustPropNames = swCustPropMgr.GetNames
If IsEmpty(vCustPropNames) = False Then
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, Empty, strValue
If vName <> "UNIT_OF_MEASURE" Then CustPropData.Add " " & vName & " // " & strValue
Next vName
End If
CustPropData.Add "CONFIG SPECIFIC"
'config specific
vConfigNamesArray = swModel.GetConfigurationNames
For Each vConfigName In vConfigNamesArray
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(vConfigName)
vCustPropNames = swCustPropMgr.GetNames
If IsEmpty(vCustPropNames) = False Then
CustPropData.Add " Configuration: " & vConfigName
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, Empty, strValue
If vName <> "UNIT_OF_MEASURE" Then CustPropData.Add " " & vName & " // " & strValue
Next vName
End If
Next vConfigName
End Function