TrueSweepLength (GetTruePath) in the API help reference is a good sample to calculate the true length of a sweep feature. If the centroid of the sweep profile does not lie on the sweep path, the true length of the sweep feature is not the same as the sum of lengths of the path entities.
In some cases, this code may not work well.even though the centroid of the sweep profile is on the sweep path. e.g. in the screenshots below, the sketch arc is actually the bend from two lines. The curves from SweepFeatures.GetTruePath returns the original length of the lines, instead of the current length after the bend. So the total length is different to what is measured in the UI.
This is an issue we have logged. To work around it, we need to check the SweepFeature.Path and calculate the total length of the paths.
Sub TrueSweepLength_bySweepPath() _InvApplication = _ Runtime.InteropServices.Marshal. _ GetActiveObject("Inventor.Application") ' assumes you have had Inventor application 'Set a reference to the active part document Dim oDoc As PartDocument = _ _InvApplication.ActiveDocument Dim oDef As PartComponentDefinition = _ oDoc.ComponentDefinition ' Check to make sure a sweep feature is selected. If Not TypeOf oDoc.SelectSet.Item(1) _ Is SweepFeature Then MsgBox("A sweep feature must be selected.") Exit Sub End If ' Set a reference to the selected feature. Dim oSweep As SweepFeature = _ oDoc.SelectSet.Item(1) Dim oPaths As Inventor.Path = _ oSweep.Path Dim TotalLength As Double = 0 Dim oPathEnt As PathEntity For Each oPathEnt In oPaths ' get the evaluator of this path Dim oCurveEval As CurveEvaluator = _ oPathEnt.Curve.Evaluator Dim MinParam As Double Dim MaxParam As Double Dim Length As Double ' get params extents Call oCurveEval.GetParamExtents(MinParam, _ MaxParam) ' get length of the path Call oCurveEval.GetLengthAtParam(MinParam, _ MaxParam, _ Length) TotalLength = TotalLength + Length Next ' Display total sweep length MsgBox("Total sweep length = " & _ _InvApplication.UnitsOfMeasure.GetStringFromValue( _ TotalLength, _ UnitsTypeEnum.kMillimeterLengthUnits)) End Sub


Leave a Reply