"Help needed: Auto diameter dimensioning on shaft in Inventor drawing using iLogic"

"Help needed: Auto diameter dimensioning on shaft in Inventor drawing using iLogic"

cinemediatamil
Participant Participant
135 Views
0 Replies
Message 1 of 1

"Help needed: Auto diameter dimensioning on shaft in Inventor drawing using iLogic"

cinemediatamil
Participant
Participant

I want to write an i Logic rule to add a diameter dimension automatically on a shaft in my drawing view. The rule tries to find a cylindrical edge and add the dimension, but it doesn’t work and shows an error or nothing happens. Can someone please help me with the right code or way to do this in i Logic?

cinemediatamil_0-1748452196456.png

my code

Dim oDrawDoc = ThisApplication.ActiveDocument

If oDrawDoc.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("This rule works only in Drawing documents.", vbExclamation, "Wrong Document")
Return
End If

Dim oSheet = oDrawDoc.ActiveSheet
If oSheet.DrawingViews.Count = 0 Then
MsgBox("No drawing views found.", vbExclamation, "No Views")
Return
End If

Dim oView = oSheet.DrawingViews(1)

Dim oRefDoc As Inventor.PartDocument = Nothing
Try
oRefDoc = CType(oView.ReferencedDocumentDescriptor.ReferencedDocument, Inventor.PartDocument)
Catch ex As Exception
MsgBox("Referenced document is not a Part document.", vbExclamation, "Wrong View Type")
Return
End Try

Dim oCompDef = oRefDoc.ComponentDefinition

' Find first cylindrical circular edge
Dim foundEdge As Inventor.Edge = Nothing
For Each oBody In oCompDef.SurfaceBodies
For Each oFace In oBody.Faces
If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kCylinderSurface Then
For Each oEdge In oFace.Edges
If oEdge.GeometryType = Inventor.CurveTypeEnum.kCircleCurve Then
foundEdge = oEdge
Exit For
End If
Next
End If
If foundEdge IsNot Nothing Then Exit For
Next
If foundEdge IsNot Nothing Then Exit For
Next

If foundEdge Is Nothing Then
MsgBox("No cylindrical circular edge found.")
Return
End If

Try
' Get 2D projected curve in drawing view
Dim oGeom2d = oView.GetProjectedCurve(foundEdge)
Dim midParam = (oGeom2d.StartParameter + oGeom2d.EndParameter) / 2
Dim midPoint2d = oGeom2d.Evaluate(midParam)

' Try to add diameter dimension
Dim dimConstraint = oView.Sketch.DimensionConstraints.AddDiameterDimension(foundEdge, midPoint2d)
MsgBox("Diameter dimension added successfully.")
Catch ex As Exception
' If fail, try alternate method: add diameter dimension at origin point of sketch
Try
Dim originPoint = oView.Sketch.ModelToSketchSpace(ThisApplication.TransientGeometry.CreatePoint(0, 0, 0))
Dim altDim = oView.Sketch.DimensionConstraints.AddDiameterDimension(foundEdge, originPoint)
MsgBox("Diameter dimension added at sketch origin as fallback.")
Catch ex2 As Exception
MsgBox("Failed to add diameter dimension: " & ex2.Message)
End Try
End Try

0 Likes
136 Views
0 Replies
Replies (0)