Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Properties

Status
Not open for further replies.

maurelius

Electrical
Joined
Oct 15, 2008
Messages
27
Location
GB
Does anyone know how to access custom properties of a part through a drawing?

I am writing some code which runs on a drawing but I also need to access some of the properties of the part/assembly that it references.

Any ideas?

Thanks
 
What will make this complicated for you is that there is not necessarily a unique model associated with a drawing. Drawings have sheets. Sheets have views, and views are associated with models. Assuming that drawing is a SldWorks.DrawingDoc for the current drawing and the first view of the active sheet references the desired model then the following code will set model to the SldWorks.ModelDoc2 object for the referenced model and configName to the referenced config of the model.

This code is pieced together from an old project, so it may not work without some fixing, but it should get you headed in the right direction though.

Eric

Code:
Dim currentView As SldWorks.view
Dim model As SldWorks.ModelDoc2
Dim configName as String

Set currentView = drawing.GetFirstView()
If Not currentView Is Nothing Then
    Set currentView = currentView.GetNextView
End If

If Not currentView Is Nothing Then
    Set model = currentView.ReferencedDocument
    configName = currentView.ReferencedConfiguration
End If
 
Thanks for a point in the right direction Eric :)
 
A drawing connects to parts and assemblies through the views. You need to get the view, then get the associated part or assembly. Likewise, BOMs are associated with views, not entire drawings. To get a BOM's model, you need to find its view and then access the model.

If you add a view of a single part and the BOM of interest is attached to a view of a parent assembly, there probably won't be an association of the BOM item number. If the view is of the same assembly with all other parts invisible, the association may hold.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top