Hi,
I need some helpt on my below requirement.
I’m looking to retrieve custom property value of suppressed components using VBA programming in an Assembly file and display them in the listbox of a dialogue form. Can anyone please help with some example code?
I’m able to retrieve the values when the components are “unsuppressed” using the below syntax:
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
VatComp = swApp.ActiveDoc.GetComponents(True)
For I = 0 To UBound(VatComp)
Set swComp = VatComp(I)
Set swCompDoc = swComp.GetModelDoc2
FileName = swComp.Name
Set swCPM = swCompDoc.Extension.CustomPropertyManager("")
swCPM.Get4 "description", False, DescValOut, DescResolvedOut
Prop = DescResolvedOut
ListboxAllGroups.AddItem FileName & " - [" & Prop & "]"
Next
Thanks in advance.
Thanks,
Kamalesh.

Hi Kamaleswaran,
You can achieve this using the Document Manager API:
Component2::GetPathName to get the path to the file and then
SwDMDocument::GetCustomPropertyNames
SwDMDocument::GetCustomProperty.
to retrieve the custom properties
Check this article of how to access Document Manager API: http://intercad.com.au/solidworks-document-api/
____________________________________________________
Regards,
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
myIntercad – an integrated tool for SolidWorks Professionals
LinkedIn SolidWorks API Education Group
Hi Artem,
Thanks for the reply. Will these commands work along in Soldiworks VBA codes? I did not used these advanced codes before. I tried as below, but I think I'm doing some thing wrong. Can you please help me?
Private Sub UserForm_Activate()
Dim swComp As SwDMDocument
Dim Value As Object
Dim FileName As String
Dim Prop As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
VatComp = swApp.ActiveDoc.GetComponents(True)
For I = 0 To UBound(VatComp)
Set swComp = VatComp(I)
Value = swComp:: GetCustomPropertyNames
FileName = swComp:: GetCustomProperty ("Number")
Prop = swComp:: GetCustomProperty ("Description")
ListboxAllGroups.AddItem FileName & " - [" & Prop & "]"
Next
End Sub
Thanks!
Hi,
SwDMDocument::GetCustomPropertyNames means that the method/property GetCustomPropertyNames can be invoked from the object of type SwDMDocument. For example in your code
swComp is a type of IComponent2. So it can be represented as IComponent2::GetModelDoc2. Please note that such notation is only for specifying the method (tech. documentation) it cannot be used directly in the code.
Take a look at this VB.NET example: http://help.solidworks.com/2013/English/api/swdocmgrapi/get_configuration_information_example_vbnet.htm
____________________________________________________
Regards,
Artem Taturevych, Application Engineer at Intercad (Australia)
translationXpert – add-in to translate SolidWorks models
myIntercad – an integrated tool for SolidWorks Professionals
LinkedIn SolidWorks API Education Group
I have used something to traverse assemblies like below. Maybe you can find some idea to your needs.
First run like:
Dim swRootComp As SldWorks.Component2
Set swConf = swModel2.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
TraverseComponent swRootComp, -1
Sub TraverseComponent(swComp As SldWorks.Component2, ByVal iLev As Integer)
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim i As Long
Dim iLevel As Integer
iLevel = iLev + 1 ' This variable is meant to show the sub-level the macro currently works in
' Debug.Print iLevel & "|" & swComp.Name
' Debug.Print iLevel & "|" & swComp.GetPathName
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
If swChildComp.IsSuppressed Then ' Don't traverse if suppressed
Debug.Print "Suppressed: " & swChildComp.name
ElseIf (iLevel < SearchDeep Or SearchDeep = -1) Then
TraverseComponent swChildComp, iLevel
End If
Next i
End Sub