''This macro wil calculate the length of a 2D sketch line ''Copyright by Inventor Wizard (http://www.inventorwizard.be) ''Use this macro at your own risk. ''You may only copy/modify this or part of the code if you leave this header! Public Sub Sketchlength() ' Get the first item in the select set. This assumes ' something is selected and that it's a 2D or 3D sketch entity. Dim oSketch As Object Dim osketchent As SketchEntity Dim osketchent3D As SketchEntity3D Dim total_length As Double Dim PI As Double PI = 4# * Atn(1#) On Error GoTo nothing_selected Set oSketch = ThisApplication.ActiveDocument.SelectSet.Item(1) If oSketch.Type = kPlanarSketchObject Then For Each osketchent In oSketch.SketchSplines Dim oSpline As SketchSpline Set oSpline = osketchent total_length = total_length + oSpline.Length Next osketchent For Each osketchent In oSketch.SketchCircles Dim oCircle As SketchCircle Set oCircle = osketchent total_length = total_length + oCircle.Area * 2 / oCircle.Radius Next osketchent For Each osketchent In oSketch.SketchEllipses Dim oEllipse As SketchEllipse Set oEllipse = osketchent Dim minparam As Double Dim maxparam As Double Dim lengthellipse As Double Call oEllipse.Geometry.Evaluator.GetParamExtents(minparam, maxparam) Call oEllipse.Geometry.Evaluator.GetLengthAtParam(minparam, maxparam, lengthellipse) total_length = total_length + lengthellipse Next osketchent For Each osketchent In oSketch.SketchArcs Dim oArc As SketchArc Set oArc = osketchent total_length = total_length + oArc.Length Next osketchent For Each osketchent In oSketch.SketchEllipticalArcs Dim oEllipticalArc As SketchEllipticalArc Set oEllipticalArc = osketchent total_length = total_length + oEllipticalArc.Length Next osketchent For Each osketchent In oSketch.SketchLines Dim oLine As SketchLine Set oLine = osketchent total_length = total_length + oLine.Length Next osketchent End If If oSketch.Type = kSketch3DObject Then For Each osketchent3D In oSketch.SketchSplines3D Dim oSpline3D As SketchSpline3D Set oSpline3D = osketchent3D total_length = total_length + oSpline3D.Length Next osketchent3D For Each osketchent3D In oSketch.SketchCircles3D Dim oCircle3D As SketchCircle3D Set oCircle3D = osketchent3D total_length = total_length + 2 * PI * oCircle3D.Geometry.Radius Next osketchent3D For Each osketchent3D In oSketch.SketchEllipses3D Dim oEllipse3D As SketchEllipse3D Set oEllipse3D = osketchent3D Dim minparam3D As Double Dim maxparam3D As Double Dim lengthellipse3D As Double Call oEllipse3D.Geometry.Evaluator.GetParamExtents(minparam3D, maxparam3D) Call oEllipse3D.Geometry.Evaluator.GetLengthAtParam(minparam3D, maxparam3D, lengthellipse3D) total_length = total_length + lengthellipse3D Next osketchent3D For Each osketchent3D In oSketch.SketchArcs3D Dim oArc3D As SketchArc3D Set oArc3D = osketchent3D total_length = total_length + oArc3D.Length Next osketchent3D For Each osketchent3D In oSketch.SketchEllipticalArcs3D Dim oEllipticalArc3D As SketchEllipticalArc3D Set oEllipticalArc3D = osketchent3D total_length = total_length + oEllipticalArc3D.Length Next osketchent3D For Each osketchent3D In oSketch.SketchLines3D Dim oLine3d As SketchLine3D Set oLine3d = osketchent3D total_length = total_length + oLine3d.Length Next osketchent3D End If If (oSketch.Type <> kPlanarSketchObject) And (oSketch.Type <> kSketch3DObject) Then nothing_selected: MsgBox "Select a sketch first before running this macro" End End If Dim oUOM As UnitsOfMeasure Set oUOM = ThisApplication.ActiveDocument.UnitsOfMeasure MsgBox "The sketch length or circumference is " + oUOM.GetStringFromValue(total_length, kDefaultDisplayLengthUnits) End Sub