Using Named Entities to Automate Dimension using Inventor API.

Using Named Entities to Automate Dimension using Inventor API.

basavaraj.bFBQWV
Participant Participant
69 Views
1 Reply
Message 1 of 2

Using Named Entities to Automate Dimension 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 or iLogic.

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)

Thank you in advance for your time and support!

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
70 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

I created an idw and added a first view with your model. Then I added the following iLogic rule to the idw:

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

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

Dim genDims = Sheet_1.DrawingDimensions.GeneralDimensions

ThisDrawing.BeginManage()
If True Then 
	Dim linDim1 = genDims.AddLinear("Dimension 1", VIEW1.SheetPoint(1.1, 0.5), namedGeometry1)
	Dim linDim2 = genDims.AddLinear("Dimension 2", VIEW1.SheetPoint(-0.1, 0.5), namedGeometry2)
	Dim linDim3 = genDims.AddLinear("Dimension 3", VIEW1.SheetPoint(0.5, 1.2), namedGeometry1, namedGeometry2)
End If
ThisDrawing.EndManage()

 This is the result:

JelteDeJong_0-1753888868793.png

 

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.

EESignature


Blog: hjalte.nl - github.com

0 Likes