Incomplete result of official 'True length of sweep feature' Code Sample

Incomplete result of official 'True length of sweep feature' Code Sample

Maxim-CADman77
Advisor Advisor
346 Views
5 Replies
Message 1 of 6

Incomplete result of official 'True length of sweep feature' Code Sample

Maxim-CADman77
Advisor
Advisor

I've discovered that official 'True length of sweep feature' Code Sample returns wrong (?path length to one direction from the profile?) value on some samples (see attached for 2024)

Here is the code converted from VBA to iLogic (the sweep feature is supposed to be pre-selected):

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

' If Not TypeOf oDoc.SelectSet.Item(1) Is SweepFeature Then
If Not TypeOf oDoc.SelectSet.Item(1) Is SweepFeature Then
	MsgBox("A sweep feature must be selected.")
	Exit Sub
End If

Dim oSweep As SweepFeature
oSweep = oDoc.SelectSet.Item(1)

Dim oProfileOrigin As Point2d
oProfileOrigin = oSweep.Profile.RegionProperties.Centroid

Dim oProfileOrigin3D As Point
oProfileOrigin3D = oSweep.Profile.Parent.SketchToModelSpace(oProfileOrigin)

Dim oCurves As ObjectsEnumerator
oCurves = oDef.Features.SweepFeatures.GetTruePath(oSweep.Path, oProfileOrigin3D)

Dim TotalLength As Double
TotalLength = 0

Dim oCurve As Object
For Each oCurve In oCurves
	
	Dim oCurveEval As CurveEvaluator
	oCurveEval = oCurve.Evaluator
	
	Dim MinParam As Double
	Dim MaxParam As Double
	Dim Length As Double
	
	Call oCurveEval.GetParamExtents(MinParam, MaxParam)
	Call oCurveEval.GetLengthAtParam(MinParam, MaxParam, Length)
	
	TotalLength = TotalLength + Length
Next

MsgBox("Total sweep length, mm = " & ThisApplication.UnitsOfMeasure.GetStringFromValue(TotalLength, kMillimeterLengthUnits)) ' kInchLengthUnits))


It returns value ~161mm (while expected value is ~300mm)

MaximCADman77_0-1730226770893.png

 


What I'm missing? How should the code be modified to return full sweep path length?

Dear @MjDeck  could you, please, study this case?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
347 Views
5 Replies
Replies (5)
Message 2 of 6

Scott_Parker
Autodesk
Autodesk

Hi,

My understanding is that the TruePath method gets the path from the input point to the end of the path.  In this example the point,  specified is near the middle of the path.  If you specify the end of the path, it will get the whole length.

Scott



Scott Parker
Principal Software Engineer
Message 3 of 6

patrick.schlambHPACQ
Participant
Participant

Here is something I have used successfully in the past. Using the sweep path rather than the truePath. 

Function GetSweepLength(sweepPath As Path) As Double
    
	Dim sweepTotalLength As Double = 0
    Dim sweepCurve As Object
	
    For i As Integer = 1 To sweepPath.Count
        sweepCurve = sweepPath.Item(i).Curve 
        Dim sweepCurveEval As CurveEvaluator = sweepCurve.Evaluator
        Dim minParam As Double
        Dim maxParam As Double
        Dim length As Double
        Call sweepCurveEval.GetParamExtents(minParam, maxParam)
        Call sweepCurveEval.GetLengthAtParam(minParam, maxParam, length)
        sweepTotalLength = sweepTotalLength + length
    Next i
	
	Return sweepTotalLength
	
End Function 'GetSweepLength

 

Message 4 of 6

Maxim-CADman77
Advisor
Advisor

@patrick.schlambHPACQ well done!

This solves my task but I've recalled the "mark as solution" because the subject is still true and sample code mentioned should definitely be updated.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

I agree.  I can not even find the last version of Inventor that showed any online hep documentation about that SweepFeatures.GetTruePath method.  I searched every version all the way back into 2017 help, where I could find some 'iLogic' help, but could not even find the 'Inventor API' help section anymore.  So, that method might still exist, but if so, it must have been 'hidden' from us at some point, for some reason.  Hard telling how old that VBA sample code may be, like many of them.  Since they have not even included VBA in standard installations of Inventor since 2021 version, due to security issues, it would be nice if they either started including iLogic samples in the 'help' area, instead of VBA samples, or converted the existing VBA samples to (iLogic &/or vb.net) for us...and updated the ones that contain outdated objects &/or methods.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

MjDeck
Autodesk
Autodesk

@WCrihfield , SweepFeatures.GetTruePath might have been hidden by mistake. If so, we can unhide it in future updates. But it might have been hidden because we added new capabilities to the sweep feature, and it does not cover all cases.
We're looking at the possibility of unhiding it and updating the sample code.


Mike Deck
Software Developer
Autodesk, Inc.