Using named Entity for Drawing Automation using inventor API

Using named Entity for Drawing Automation using inventor API

basavaraj.bFBQWV
Participant Participant
360 Views
9 Replies
Message 1 of 10

Using named Entity for Drawing Automation using inventor API

basavaraj.bFBQWV
Participant
Participant

Hello Developers,

I’ve recently started working with iLogic and the Inventor API, and I’m currently trying to automate the process of adding drawing dimensions and annotations using named entities—specifically Faces, Edges, and Vertices.

However, I’m facing issues getting the code to work as expected. I suspect I’m missing something fundamental, but I haven’t been able to pinpoint the problem. I’ve attached both the iLogic code and the corresponding Inventor geometry for reference.

I would greatly appreciate it if someone could provide a working example that demonstrates how to use named Faces, Edges, and Vertices to create drawing dimensions using the Inventor API

Thank you in advance for your time and support!

here is my code 

"

Dim doc = ThisApplication.ActiveDocument
Dim osheet = doc.ActiveSheet
Dim oview = osheet.DrawingViews.Item(1)

' Get the referenced document from the drawing view
Dim refDoc
Try
	refDoc = oview.ReferencedDocumentDescriptor.ReferencedDocument
Catch ex As Exception
	MessageBox.Show("Unable to get referenced document: " & ex.Message)
	Return
End Try

If refDoc Is Nothing Then
	MessageBox.Show("Referenced document not available.")
	Return
End If

' Get named entities from the referenced document
Dim namedEntities
Try
	namedEntities = iLogicVb.Automation.GetNamedEntities(refDoc)
Catch ex As Exception
	MessageBox.Show("Failed to get named entities: " & ex.Message)
	Return
End Try

' Find named entities
Dim ent1 = namedEntities.FindEntity("BottomEdge")
Dim ent2 = namedEntities.FindEntity("TopEdge")

If ent1 Is Nothing Or ent2 Is Nothing Then
	MessageBox.Show("Named entity 'BottomEdge' or 'TopEdge' not found.")
	Return
End If

' Create geometry intents for dimensioning
Dim wp1 = osheet.CreateGeometryIntent(ent1)
Dim wp2 = osheet.CreateGeometryIntent(ent2)

' Set position of dimension
Dim tg = ThisApplication.TransientGeometry
Dim dimpos = tg.CreatePoint2d(oview.Position.X / 2, oview.Position.Y + 1)

' Add linear dimension
osheet.DrawingDimensions.GeneralDimensions.AddLinear(dimpos, wp1, wp2)"

 

0 Likes
361 Views
9 Replies
Replies (9)
Message 2 of 10

CGBenner
Community Manager
Community Manager

@basavaraj.bFBQWV 

Welcome to the Community!  Thank you for sharing the code and the drawing file.  Hopefully this will inspire some of our experts to help you find a solution.  Good luck!

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!


Chris Benner
Community Manager

0 Likes
Message 3 of 10

Curtis_Waguespack
Consultant
Consultant

Hi @basavaraj.bFBQWV ,
See the short video at this link that shows a quick overview of how to do this.

https://autode.sk/4m3vkvl

 

I created this last summer for someone at Autodesk and then they abandoned the effort ( wasted my time 🙄 ) so I suppose we might as well make use of it here 🙂

 

Hope that helps,

Curtis

 

 

 

EESignature

Message 4 of 10

Curtis_Waguespack
Consultant
Consultant

Code example for your part

Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim GenDims = Sheet_1.DrawingDimensions.GeneralDimensions

Dim FrontFace = VIEW1.GetIntent("FrontFace")
Dim BackFace = VIEW1.GetIntent("BackFace")

Dim PlacementPt = VIEW1.SheetPoint(1.1, 0.5)
GenDims.AddLinear("Dimension 1", PlacementPt, FrontFace)

PlacementPt = VIEW1.SheetPoint(0.5, -0.1)
GenDims.AddLinear("Dimension 2", PlacementPt, BackFace, FrontFace)

 

EESignature

Message 5 of 10

basavaraj.bFBQWV
Participant
Participant

Thanks, Curtis_Waguespack. I’m familiar with this method of achieving the dimensioning goal—it appears to rely on iLogic interfaces (if I’m not mistaken). However, my objective is to implement the same functionality using the pure Inventor API, ideally in C# via Visual Studio, without referencing any iLogic-specific components.

That said, I truly appreciate your input—thank you

0 Likes
Message 6 of 10

basavaraj.bFBQWV
Participant
Participant

That's really nice and Handy way to get snippet right from the geometry, but am afraid i might looking at inventor API way rather than ilogic way.

0 Likes
Message 7 of 10

Curtis_Waguespack
Consultant
Consultant

ah, gotcha... I missed that you were wanting to do straight API, I'm in a meeting and don't have time to look at your example again, but here are a couple of examples online that you might be able to glean from.

https://transientgeometry.co.uk/automating-dimension-placement-in-inventor-drawings/
http://hjalte.nl/40-hole-position-dimensions

 

EESignature

Message 8 of 10

basavaraj.bFBQWV
Participant
Participant

thanks for the help, later when you get time please do have look at my code, my goal to understand how to different type of named entities for drawing dimensioning using API. once again really appreciate 🙂

0 Likes
Message 9 of 10

Curtis_Waguespack
Consultant
Consultant

@basavaraj.bFBQWV , It's been a bit since I've looked at this with straight API, but I think you would need to use the iLogic namedentites to do it by name, which you can use from an addin, by referencing the iLogic addin.

 

otherwise you would work with drawing curves ( see example below)

or use attributes as shown in one of the previous links. 

sample from here: https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=BaselineDimensionSets_Add_Sample

Curtis_Waguespack_0-1752773482502.png

Curtis_Waguespack_1-1752773507121.png

' a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' a reference to the active sheet.
Dim oActiveSheet As Sheet
oActiveSheet = oDrawDoc.ActiveSheet

Dim oIntentCollection As ObjectCollection
oIntentCollection = ThisApplication.TransientObjects.CreateObjectCollection

' Get all the selected drawing curve segments.
Dim oDrawingCurveSegment As DrawingCurveSegment
Dim oDrawingCurve As DrawingCurve
For Each oDrawingCurveSegment In oDrawDoc.SelectSet

	' a reference to the drawing curve.
	oDrawingCurve = oDrawingCurveSegment.Parent

	Dim oDimIntent As GeometryIntent
	oDimIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
	
		Call oIntentCollection.Add(oDimIntent)
Next

Dim oDrawingView As DrawingView
oDrawingView = oActiveSheet.DrawingViews.Item(1)

' a reference to the baseline dimension sets collection.
Dim oBaselineSets As BaselineDimensionSets
oBaselineSets = oActiveSheet.DrawingDimensions.BaselineDimensionSets

' Determine the placement point
Dim oPlacementPoint As Point2d
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oDrawingView.Left - 5, oDrawingView.Center.Y)

' Create a vertical baseline dimension.
Dim oBaseline As BaselineDimensionSet
oBaseline = oBaselineSets.Add(oIntentCollection, oPlacementPoint, kVerticalDimensionType)

 

 

 

EESignature

Message 10 of 10

CGBenner
Community Manager
Community Manager

@basavaraj.bFBQWV 

 

Did the information provided answer your question? If so, please use Accept Solution so that others may find this in the future. Thank you very much!

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!


Chris Benner
Community Manager

0 Likes