Message 1 of 2
Using Named Entities to Automate Dimension using Inventor API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
.