- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
some time ago I wrote a blog about creating dimensions. In the background, I (and Autodesk) used the AttributeManager. maybe it is some help to you. have a look at this page. from there you will find other pages with more information. www.hjalte.nl
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you Jelte.
I looked through your blog and it looks like you already have your GeometryIntent in most cases. I want to obtain there GeometryIntent via the AttributeManager. It works fine for Parts but it doesnt for an Assembly.
I was in the meantime trying to use the GetIntent() method which is what you did here: http://www.hjalte.nl/24-ilogic-adds-dimensions-to-drawings
My first draft looks like this:
Dim Sheet_1 = oSheet Dim VIEW1 As DrawingView For i = 1 To Sheet_1.DrawingViews.Count MessageBox.Show(Sheet_1.DrawingViews.Item(i).Name.ToString()) If Sheet_1.DrawingViews.Item(i).Name.ToString() = "ANSICHT72" Then VIEW1 = Sheet_1.DrawingViews.Item(i) End If Next Dim namedGeometry1 = VIEW1.GetIntent("Nutenseite1") Dim namedGeometry2 = VIEW1.GetIntent("Nutenseite2")
But I get the error that GetIntent() is not found for DrawingView.
I feel like I am really close with my original code to a solution its just that I struggle to move from the assembly level to the parts level - especially being able to execute
oPartDoc.AttributeManager.FindObjects("*", "*", "Nutenseite1").Item(1)
with oPartDoc already being the correct PartDocument within my AssemblyDocument but I do not know how I can access that part (I could do a search by name but I dont know how to do that)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Got this working!
Final code below:
Dim oModelDoc As Document Dim Face1 As Object Dim Face2 As Object For i = 1 To oAssDoc.ReferencedDocuments.Count oModelDoc = oAssDoc.ReferencedDocuments(i) If oModelDoc.AttributeManager.FindObjects("*", "*", "Kante0").Count > 0 Then Logger.Debug("Found Model: " & oModelDoc.DisplayName()) If oModelDoc.DisplayName() = "93400005.ipt" Then Face1 = oModelDoc.AttributeManager.FindObjects("*", "*", "Kante0").Item(1) 'Logger.Debug("Found Face 1: " & Face1.InternalName()) End If End If If oModelDoc.AttributeManager.FindObjects("*", "*", "Kante1").Count > 0 Then If oModelDoc.DisplayName() = "93400005.ipt" Then Face2 = oModelDoc.AttributeManager.FindObjects("*", "*", "Kante1").Item(1) ' Logger.Debug("Found Face 2: " & Face2.InternalName()) End If End If Next