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
Solved! Go to Solution.
Solved by JhoelForshav. Go to Solution.
Solved by C-Hoppen. Go to Solution.
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
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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...
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.
Wesley Crihfield
(Not an Autodesk Employee)
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.
Wesley Crihfield
(Not an Autodesk Employee)
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?
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:
Line 5 is
Sketch = oDoc.ComponentDefinition.Sketches3D(2)
Measure tool reports a 3.068686928 in. length.
TIA
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)
@A.Acheson Thank you for responding.
I made the correction you indicated. This error then presented:
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?
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
(Not an Autodesk Employee)
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?
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
(Not an Autodesk Employee)
@JhoelForshavI ran your code verbatim, and it generates this for the "HelicalCurveLength" parameter:
:
However, the Measure tool displays the length as this:
2 questions:
I can post the part, if you wish, but it is a simple helix.
TIA
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:
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.