<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic &amp;quot;Help needed: Auto diameter dimensioning on shaft in Inventor drawing using iLogic&amp;quot; in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/quot-help-needed-auto-diameter-dimensioning-on-shaft-in-inventor/m-p/13654551#M16</link>
    <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cinemediatamil_0-1748452196456.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1538206iC68C684A0394916B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cinemediatamil_0-1748452196456.png" alt="cinemediatamil_0-1748452196456.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;my code&lt;/P&gt;&lt;P&gt;Dim oDrawDoc = ThisApplication.ActiveDocument&lt;/P&gt;&lt;P&gt;If oDrawDoc.DocumentType &amp;lt;&amp;gt; Inventor.DocumentTypeEnum.kDrawingDocumentObject Then&lt;BR /&gt;MsgBox("This rule works only in Drawing documents.", vbExclamation, "Wrong Document")&lt;BR /&gt;Return&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Dim oSheet = oDrawDoc.ActiveSheet&lt;BR /&gt;If oSheet.DrawingViews.Count = 0 Then&lt;BR /&gt;MsgBox("No drawing views found.", vbExclamation, "No Views")&lt;BR /&gt;Return&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Dim oView = oSheet.DrawingViews(1)&lt;/P&gt;&lt;P&gt;Dim oRefDoc As Inventor.PartDocument = Nothing&lt;BR /&gt;Try&lt;BR /&gt;oRefDoc = CType(oView.ReferencedDocumentDescriptor.ReferencedDocument, Inventor.PartDocument)&lt;BR /&gt;Catch ex As Exception&lt;BR /&gt;MsgBox("Referenced document is not a Part document.", vbExclamation, "Wrong View Type")&lt;BR /&gt;Return&lt;BR /&gt;End Try&lt;/P&gt;&lt;P&gt;Dim oCompDef = oRefDoc.ComponentDefinition&lt;/P&gt;&lt;P&gt;' Find first cylindrical circular edge&lt;BR /&gt;Dim foundEdge As Inventor.Edge = Nothing&lt;BR /&gt;For Each oBody In oCompDef.SurfaceBodies&lt;BR /&gt;For Each oFace In oBody.Faces&lt;BR /&gt;If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kCylinderSurface Then&lt;BR /&gt;For Each oEdge In oFace.Edges&lt;BR /&gt;If oEdge.GeometryType = Inventor.CurveTypeEnum.kCircleCurve Then&lt;BR /&gt;foundEdge = oEdge&lt;BR /&gt;Exit For&lt;BR /&gt;End If&lt;BR /&gt;Next&lt;BR /&gt;End If&lt;BR /&gt;If foundEdge IsNot Nothing Then Exit For&lt;BR /&gt;Next&lt;BR /&gt;If foundEdge IsNot Nothing Then Exit For&lt;BR /&gt;Next&lt;/P&gt;&lt;P&gt;If foundEdge Is Nothing Then&lt;BR /&gt;MsgBox("No cylindrical circular edge found.")&lt;BR /&gt;Return&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Try&lt;BR /&gt;' Get 2D projected curve in drawing view&lt;BR /&gt;Dim oGeom2d = oView.GetProjectedCurve(foundEdge)&lt;BR /&gt;Dim midParam = (oGeom2d.StartParameter + oGeom2d.EndParameter) / 2&lt;BR /&gt;Dim midPoint2d = oGeom2d.Evaluate(midParam)&lt;/P&gt;&lt;P&gt;' Try to add diameter dimension&lt;BR /&gt;Dim dimConstraint = oView.Sketch.DimensionConstraints.AddDiameterDimension(foundEdge, midPoint2d)&lt;BR /&gt;MsgBox("Diameter dimension added successfully.")&lt;BR /&gt;Catch ex As Exception&lt;BR /&gt;' If fail, try alternate method: add diameter dimension at origin point of sketch&lt;BR /&gt;Try&lt;BR /&gt;Dim originPoint = oView.Sketch.ModelToSketchSpace(ThisApplication.TransientGeometry.CreatePoint(0, 0, 0))&lt;BR /&gt;Dim altDim = oView.Sketch.DimensionConstraints.AddDiameterDimension(foundEdge, originPoint)&lt;BR /&gt;MsgBox("Diameter dimension added at sketch origin as fallback.")&lt;BR /&gt;Catch ex2 As Exception&lt;BR /&gt;MsgBox("Failed to add diameter dimension: " &amp;amp; ex2.Message)&lt;BR /&gt;End Try&lt;BR /&gt;End Try&lt;/P&gt;</description>
    <pubDate>Wed, 28 May 2025 17:12:07 GMT</pubDate>
    <dc:creator>cinemediatamil</dc:creator>
    <dc:date>2025-05-28T17:12:07Z</dc:date>
    <item>
      <title>"Help needed: Auto diameter dimensioning on shaft in Inventor drawing using iLogic"</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/quot-help-needed-auto-diameter-dimensioning-on-shaft-in-inventor/m-p/13654551#M16</link>
      <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cinemediatamil_0-1748452196456.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1538206iC68C684A0394916B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cinemediatamil_0-1748452196456.png" alt="cinemediatamil_0-1748452196456.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;my code&lt;/P&gt;&lt;P&gt;Dim oDrawDoc = ThisApplication.ActiveDocument&lt;/P&gt;&lt;P&gt;If oDrawDoc.DocumentType &amp;lt;&amp;gt; Inventor.DocumentTypeEnum.kDrawingDocumentObject Then&lt;BR /&gt;MsgBox("This rule works only in Drawing documents.", vbExclamation, "Wrong Document")&lt;BR /&gt;Return&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Dim oSheet = oDrawDoc.ActiveSheet&lt;BR /&gt;If oSheet.DrawingViews.Count = 0 Then&lt;BR /&gt;MsgBox("No drawing views found.", vbExclamation, "No Views")&lt;BR /&gt;Return&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Dim oView = oSheet.DrawingViews(1)&lt;/P&gt;&lt;P&gt;Dim oRefDoc As Inventor.PartDocument = Nothing&lt;BR /&gt;Try&lt;BR /&gt;oRefDoc = CType(oView.ReferencedDocumentDescriptor.ReferencedDocument, Inventor.PartDocument)&lt;BR /&gt;Catch ex As Exception&lt;BR /&gt;MsgBox("Referenced document is not a Part document.", vbExclamation, "Wrong View Type")&lt;BR /&gt;Return&lt;BR /&gt;End Try&lt;/P&gt;&lt;P&gt;Dim oCompDef = oRefDoc.ComponentDefinition&lt;/P&gt;&lt;P&gt;' Find first cylindrical circular edge&lt;BR /&gt;Dim foundEdge As Inventor.Edge = Nothing&lt;BR /&gt;For Each oBody In oCompDef.SurfaceBodies&lt;BR /&gt;For Each oFace In oBody.Faces&lt;BR /&gt;If oFace.SurfaceType = Inventor.SurfaceTypeEnum.kCylinderSurface Then&lt;BR /&gt;For Each oEdge In oFace.Edges&lt;BR /&gt;If oEdge.GeometryType = Inventor.CurveTypeEnum.kCircleCurve Then&lt;BR /&gt;foundEdge = oEdge&lt;BR /&gt;Exit For&lt;BR /&gt;End If&lt;BR /&gt;Next&lt;BR /&gt;End If&lt;BR /&gt;If foundEdge IsNot Nothing Then Exit For&lt;BR /&gt;Next&lt;BR /&gt;If foundEdge IsNot Nothing Then Exit For&lt;BR /&gt;Next&lt;/P&gt;&lt;P&gt;If foundEdge Is Nothing Then&lt;BR /&gt;MsgBox("No cylindrical circular edge found.")&lt;BR /&gt;Return&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;Try&lt;BR /&gt;' Get 2D projected curve in drawing view&lt;BR /&gt;Dim oGeom2d = oView.GetProjectedCurve(foundEdge)&lt;BR /&gt;Dim midParam = (oGeom2d.StartParameter + oGeom2d.EndParameter) / 2&lt;BR /&gt;Dim midPoint2d = oGeom2d.Evaluate(midParam)&lt;/P&gt;&lt;P&gt;' Try to add diameter dimension&lt;BR /&gt;Dim dimConstraint = oView.Sketch.DimensionConstraints.AddDiameterDimension(foundEdge, midPoint2d)&lt;BR /&gt;MsgBox("Diameter dimension added successfully.")&lt;BR /&gt;Catch ex As Exception&lt;BR /&gt;' If fail, try alternate method: add diameter dimension at origin point of sketch&lt;BR /&gt;Try&lt;BR /&gt;Dim originPoint = oView.Sketch.ModelToSketchSpace(ThisApplication.TransientGeometry.CreatePoint(0, 0, 0))&lt;BR /&gt;Dim altDim = oView.Sketch.DimensionConstraints.AddDiameterDimension(foundEdge, originPoint)&lt;BR /&gt;MsgBox("Diameter dimension added at sketch origin as fallback.")&lt;BR /&gt;Catch ex2 As Exception&lt;BR /&gt;MsgBox("Failed to add diameter dimension: " &amp;amp; ex2.Message)&lt;BR /&gt;End Try&lt;BR /&gt;End Try&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 17:12:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/quot-help-needed-auto-diameter-dimensioning-on-shaft-in-inventor/m-p/13654551#M16</guid>
      <dc:creator>cinemediatamil</dc:creator>
      <dc:date>2025-05-28T17:12:07Z</dc:date>
    </item>
  </channel>
</rss>

