Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Measure the Length of 3D Sketch Helix / Spiral

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
petestrycharske
2504 Views, 16 Replies

Measure the Length of 3D Sketch Helix / Spiral

All,

 

Good morning!  I think I've got a relatively simple question, but I've got a mind block and cannot seem to get it worked out.  I'm trying to determine the length of the helical spiral in the attached part's 3DSketch2.  I can figure out how to select the helicalcurve object that I want, but I cannot seem to extract the length from it.  If I use the Measure command in the part model, I can obtain the length, but ideally I'd like to assign this to a parameter, so that if the characteristics of the spiral change, the parameter will automatically update.  Hopefully this makes sense, but please let me know if you have any questions.  Thanks in advance for any assistance, hope all is well and have a most blessed day!

 

Peace,

Pete

Just a guy on a couch...

Please give a kudos if helpful and mark as a solution if somehow I got it right.
Labels (3)
16 REPLIES 16
Message 2 of 17
C-Hoppen
in reply to: petestrycharske

Pete,

This is your way...

PartComponentDefinition -> Sketches3D -> Item1 -> SketchFixedSplines3D -> Item1 ->  : Length : 245,43 (centimeter!)

And take a look at this: https://modthemachine.typepad.com/files/mathgeometry.pdf

Regards

Christoph

Message 3 of 17

Hi @petestrycharske 

The HelicalCurve contains some sketch entities and one of these is of type SketchFixedSpline3D. This is the object we want to get the length of. Thats actually pretty simple since the object has a length property. It could be a good idea to loop through the sketch entities to find that object. If you add this rule and set it to trigger on any model parameter change I think you'll get the result you want 🙂

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim Sketch As Sketch3D
'Dim SE As SketchEntity3D
Dim SE As HelicalCurve
Sketch = oDoc.ComponentDefinition.Sketches3D(2)
'SE = ThisDoc.Document.ComponentDefinition.Sketches3D(2).SketchLines3D(1)
SE = Sketch.HelicalCurves(1)

'Get parameter
Dim oParam As Inventor.Parameter
Try
	oParam = Parameter.Param("HelicalCurveLength")
Catch
	'Parameter doesnt exist
End Try



Dim oUM As UnitsOfMeasure = oDoc.UnitsOfMeasure
For Each oEnt As SketchEntity3D In SE.SketchEntities
	If oEnt.Type = ObjectTypeEnum.kSketchFixedSpline3DObject
		Dim oSpline As SketchFixedSpline3D = oEnt
		MsgBox(oUM.GetStringFromValue(oSpline.Length, oUM.LengthUnits))
		If oParam Is Nothing
			oParam = oDoc.ComponentDefinition.Parameters.UserParameters.AddByExpression("HelicalCurveLength", _
			oUM.GetStringFromValue(oSpline.Length, oUM.LengthUnits), oUM.LengthUnits)
		Else
			Parameter("HelicalCurveLength") = oUM.GetStringFromValue(oSpline.Length, oUM.LengthUnits)
		End If
	End If
Next
iLogicVb.UpdateWhenDone = True
Message 4 of 17
cadman777
in reply to: JhoelForshav

@JhoelForshav 

Can you direct me to the info that informed you what a 'HelicalCurve' is and where to find it in the Inventor VBA ObjectsBrowser?

Thanx...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 5 of 17
WCrihfield
in reply to: cadman777

Hi @cadman777.  First of all, the HelicalCurves & HelicalCurve objects and some of the other objects related to them were created within the Inventor API back in 2019.  So, if you have an earlier version of Inventor, you may not have access to them yet.  In 2019 the HelicalCurves property was added to the Sketch3d object.  It returned a HelicalCurves object.  For some reason, pretty much all of the browser addresses or URL's for the HelicalCurve related stuff seems to be incomplete right now, much like all the links to the newer ModelState related stuff.  That HelicalCurves object has an Add method (among others) and an Item property (among others), both of which return a HelicalCurve object.  Then this HelicalCurve object has a property called SketchEntities, which just returns a SketchEntities3DEnumerator object.  That collection could be looped through, and you could use one of the various techniques to identify what specific Type of object each item was, which would lead you towards looking into the more specific object types.

 

Another technique for looking into such things would be to scroll down through all the available Sketch related objects in the online help home page, then expand the "Programming Interface" node, then expand the "Inventor API Reference Manual" node, then expand the "Objects" node, then scroll down through all the objects who's names start with "Sketch".  When you see something that sounds about right, click on it to learn more.  For instance, if I wanted to learn more about what a SketchFixedSpline3D object was, I could follow those steps to find its online help page.  Unfortunately, this doesn't exactly point you back to the HelicalCurves direction, so it can be difficult to connect the two from this end.

WCrihfield_0-1650380841028.png

WCrihfield_1-1650380868985.png

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 17
WCrihfield
in reply to: WCrihfield

I have no idea why Autodesk still has not fixed these web page addresses after this many years.  Those objects were made available in the 2019 release of Inventor, and now Inventor 2023 is out and available, and they still have not fixed the online help web pages for these objects.

WCrihfield_0-1650381733561.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 17
cadman777
in reply to: WCrihfield

Thanx for the clear and concise explanation!

 

Yes, I have 2010, so none of this is available to me...bummer!

 

FYI, I tried searching online for "HelicalCurve" and the only relevant link I found after 1/2 an hour of reading was the link for this thread. I will refrain from the usual RANT.

 

I want to give you a GreenCheckMark b/c you answered my question, but this isn't my thread. Maybe Johnson can do it for me?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 8 of 17

I have a number of situations where this rule would be helpful, but I could not get it to run. What changes to the code do I need to make? I keep getting these errors:

 

2023-01-02 581.jpg2023-01-02 582.jpg

Line 5 is 

Sketch = oDoc.ComponentDefinition.Sketches3D(2)

 Measure tool reports a 3.068686928 in. length.

 

TIA

Message 9 of 17
A.Acheson
in reply to: b.mccarthy

Hi @b.mccarthy 

That line there is looking for the second 3d sketch as per the OP setup. If you have only one sketch change the index to 1.

Sketch = oDoc.ComponentDefinition.Sketches3D(1)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 10 of 17
b.mccarthy
in reply to: A.Acheson

@A.Acheson Thank you for responding.

 

I made the correction you indicated. This error then presented:

 

2023-01-03 584.jpg2023-01-03 585.jpg

 

After running this, perhaps I am incorrect in thinking that this rule will work for a non-periodic curve aka 3D spline. If not, what do I change for that use case?

Message 11 of 17
WCrihfield
in reply to: b.mccarthy

Hi @b.mccarthy.  That is a tough question to answer, because how to fix it depends on what type of sketch geometry you have within your 3D sketch.  There are many possible types of objects that could be found within it, and we don't know for sure which type you may have, so it would be a guessing game for us to suggest something.  If you pre-define the variable's Type ahead of time within the code, like the example above, then try to set a value to that variable by attempting to retrieve one from the sketch, and there is none of them in the sketch, it will throw another error.  There are a couple of commented out lines of code in the last example that would help make your code a bit more generic (useful in more scenarios).  Instead of looking specifically for a HelicalCurve Type object, you could try looking for the first SketchEntity3d Type object, which would cover much more possible Types of objects.  However, that would still be error prone, because some things, such as SketchPoint3d (and others) can not be measured for length.  You may have to use a much larger block of code there, which would attempt to loop through all of the entities in the sketch, check what Type they are, then only attempt to 'measure' certain ones.  But from the sounds of it, you are describing a SketchSpline3d Type object.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 17
cadman777
in reply to: WCrihfield

I can't remember where I saw it, but I believe there's a snippet of code on here that can be used to identify the type of sketch entity in a sketch. Then the OP can use that to determine what sketch entity type he has, so he can adjust his iLogic descriptor to access it. He can do this on a case-by-case-basisfor each new sketch he creates, and then change his code accordingly to suit that entity type. How does that sound? I just can't find the snippet of code used to ID the sketch entity. Maybe you know it off the top of your head?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 13 of 17
b.mccarthy
in reply to: cadman777

That sounds like a great approach. I vaguely remember a post like that. 

Message 14 of 17
WCrihfield
in reply to: b.mccarthy

@b.mccarthy@cadman777 

Hi guys.  If you are looking for ways to identify object Type by code, I wrote an article about that early last year that you might find helpful.  It points out several of the most popular/easy ways of identifying things.

Identify The 'Type' And/Or ObjectTypeEnum Name Of Selected Objects 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 17
b.mccarthy
in reply to: WCrihfield

@WCrihfield

 

Thank you. That will be helpful, especially since I am a coding newb...

Message 16 of 17

@JhoelForshavI ran your code verbatim, and it generates this for the "HelicalCurveLength" parameter:

:

2023-01-08 596.jpg

 

However, the Measure tool displays the length as this:

 

2023-01-08 595.jpg

 

2 questions:

  • Why do these values vary?
  • Why does the code round to 3 decimal places?

 

I can post the part, if you wish, but it is a simple helix.

TIA

Message 17 of 17

Update...

 

I found a rule that will calculate the length of a sweep, and generated a basic sweep using the same sketch. Except for the rounding of @JhoelForshav's code, the values are similar:

 

2023-01-08 598.jpg

 

Since 2 different rules return basically the same value, this would appear that the Measure tool is functioning incorrectly, at least for some 3d curves, yes?

 

Can anyone verify this?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report