I am trying to iterate through the components of an assembly and get the title of each of them. Using an example in the API help file I can get the name of the component but we put what is essentially a part description into the title property of the model so I need to get that also.
The snag that I am running into is that the example file makes the child component a Component2 object, which doesn't have a GetTitle. I've tried converting it into a ModelDoc2 but that crashed at the conversion.
Any help is appreciated.
In case it matters I am using SW2009 and VSTA (VB).
Dan

what code are you using to convert the Component2 to ModelDoc2
If I understand correctly you are trying to get the title of a sub part, but the title is what shows at the top of your active SolidWorks window as the part that you are working on. So only the active part in SolidWorks has a title. Depending on how you have Windows Explorer set the title may or may not show the file extension.
It sounds to me that what you are looking for is the custom property called “Title” and to get this you need to get the modeldoc2 of the component using GetModeldoc then get the custom property.
Dan Miel
I tried two ways:
1. theNewModelDoc2=swChildComp
&
2. theNewModelDoc2=swChildComp.GetModelDoc2
and they both gave me the same error.
the 2 is correct
try
set theNewModelDoc2=swChildComp.GetModelDoc2
or
set theNewModelDoc2=swChildComp.GetModelDoc2()
What exactly do you mean by "title"? File name, perhaps?
OK I thought that GetTitle would get the value from the Title field when you go to File->Properties, but it does just get the file name without the path. I would like to get the value in the File->Properties: Title
swModel.SummaryInfo(swSummInfoField_e.swSumInfoTitle)
swModel.SummaryInfo(0)
That property is an embedded property common to many documents. There is a Microsoft library that needs to be registered to get this field. Search the MSDN for DSOFile.dll. There is also info and an example in the SW API help.
Edit: Or you can do what Jacob has stated it seems.
Here is a way to traverse through all of the components, get the modeldoc2 for each and get the description property using the old GetCustomInfoValue. You should use the new CustomPropertyManager to get the custom properties.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swComp As SldWorks.Component2
Dim CompDoc As SldWorks.ModelDoc2
Dim VatComp As Variant
Dim I As Integer
Sub main()
Dim CompDoc As SldWorks.ModelDoc2
Dim FileName As String
Dim Prop As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
VatComp = swApp.ActiveDoc.GetComponents(False)
For I = 0 To UBound(VatComp)
Set swComp = VatComp(I)
Set CompDoc = swComp.GetModelDoc2
FileName = swComp.Name2
Prop = CompDoc.GetCustomInfoValue("", "Description")
Debug.Print FileName & " = " & Prop
Next
End Sub
Dan Miel
This is exactly what I needed.
Thanks to everyone but especially you Jacob.
Dan