Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
jonas.hoffmeisterFYFHQ
407 Views, 4 Replies

Adding dimensions to an assembly via AttributeManager.FindObjects()

Hi everyone,

 

I would like to automate a drawing using the API functionalities. I am trying to add a simple linear dimension.

 

What I found online helped me to get the below working within the ipt (parts) file. This works fine:

 

' Get the part to be inserted into the drawing.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

' Create a new drawing document using the default template.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open( "Template.idw", True)

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

' Place the base front view.
Dim oFrontView As DrawingView
oFrontView = oSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(7, 28), 0.05, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

' Place the base side view.
Dim oSideView As DrawingView
oSideView = oSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(35, 35), 0.02, ViewOrientationTypeEnum.kLeftViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

' Create the top view
Dim oTopView As DrawingView
oTopView = oSheet.DrawingViews.AddProjectedView(oSideView, oTG.CreatePoint2d(35, 20), DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

' Dimension 

Dim faceOrEdge1 As Object = oPartDoc.AttributeManager.FindObjects("*", "*", "Nutenseite1").Item(1)
Dim myCurveCandidates As DrawingCurvesEnumerator = oTopView.DrawingCurves(faceOrEdge1)
Dim myDrawingCurve As DrawingCurve = myCurveCandidates.Item(1)
Dim face1GeoIntent As GeometryIntent = oSheet.CreateGeometryIntent(myDrawingCurve)

Dim faceOrEdge2 As Object = oPartDoc.AttributeManager.FindObjects("*", "*", "Nutenseite2").Item(1)
myCurveCandidates = oTopView.DrawingCurves(faceOrEdge2)
myDrawingCurve = myCurveCandidates.Item(1)
Dim face2GeoIntent As GeometryIntent = oSheet.CreateGeometryIntent(myDrawingCurve)

Dim widthDimPoint As Point2d = oTG.CreatePoint2d(15, 10)

oSheet.DrawingDimensions.GeneralDimensions.AddLinear(widthDimPoint,face1GeoIntent,face2GeoIntent)

 

 

I am now trying to dimension the exact same faces from the very same part within an assembly. However, the above code does not work as soon as oPartDoc is an AssemblyDocument. 

 

My guess from my knowledge is that I am not in the right layer but that I have to somehow dive into the correct part within the assembly. 

 

I tried to get there using things like 

 

oPartDoc.ComponentDefinition.Occurrences.ItemByName("myPart")

instead of oPartDoc, as well as looping through it:

 

For i = 1 To oPartDoc.ReferencedDocuments.Count 
	
	MessageBox.Show(oPartDoc.ReferencedDocuments.Item(i).DisplayName())
	MessageBox.Show(oPartDoc.ReferencedDocuments.Item(i).AttributeManager.FindObjects("*", "*", "Nutenseite1").Count.ToString())
	
Next

 

but it feels like I am moving in circles.

 

Any suggestions please?

 

Thanks