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: 

3D Measurement between mouse pick points in model space, through iLogic rule

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
tbrausen
371 Views, 6 Replies

3D Measurement between mouse pick points in model space, through iLogic rule

My goal is to add a custom Content Center part and programmatically size it based on a measurement between user selected faces or points in a 3D model. All code I could find that probably would help me get to that was incomplete, when cut & pasted, they resulted in errors. I'm not familiar enough with this code to figure out why, so they lead to more questions. I know how to add the part, just need code to get the measurement. In ACAD AutoLisp, getpoint & distance would do what I'm looking for. I would appreciate any help.

6 REPLIES 6
Message 2 of 7
Michael.Navara
in reply to: tbrausen

For measuring in inventor you can use MeasureTools Object and its methods especially MeasureTools.GetMinimumDistance Method Here is short sample which measure distance between two planar faces and print additional information from context object. You can modify this rule to measure distance between different objects (edges, vertices, workpoints, etc.) 

 

Dim pick1 As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick face 1")
Dim pick2 As Object = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick face 2")

Dim entityOneInferredType As InferredTypeEnum = InferredTypeEnum.kNoInference
Dim entityTwoInferredType As InferredTypeEnum = InferredTypeEnum.kNoInference
Dim context As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()

Dim distance As Double = ThisApplication.MeasureTools.GetMinimumDistance(
    pick1,
    pick2,
    entityOneInferredType,
    entityTwoInferredType,
    context)

Logger.Debug(distance)

For i As Integer = 1 To context.Count
    Dim key = context.Name(i)
    Dim value = context.Value(key)
    Logger.Debug("{0}: {1}", key, value)
Next

 

Message 3 of 7
tbrausen
in reply to: tbrausen

Hi Michael, My guess is that your code will work if I just plug it into my Add Content Center part rule and use distance as the lenght value as I believe you intended but I wanted to see how it worked before continuing. I added the LENGTH parameter to the assembly and "LENGTH = distance" to your code to get an output. How do I avoid running it twice to get the LENGTH parameter to update? I tried adding "Dim LENGTH As Double" just before "LENGTH = distance" but got a bunch of errors. My guess is that there is a better way to do this, but the output was wrong. The measurement I took face to face in Inventor was 53.5" and LENGTH  was set to 135.89".

Thank you for your help.

Message 4 of 7
A.Acheson
in reply to: tbrausen

Hi @tbrausen 

You can use the parameter function to update the parameter while the rule runs.

Parameter("Length") = distance
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 7
Michael.Navara
in reply to: tbrausen

You can't use syntax LENGTH = distance because this iLogic shortcut expects the the numerical value in units specified in parameter LENGTH. But the value of variable distance is in internal units which is cm

Here is sample how you can set the parameter value and which units of the value are expected.

 

 

LENGTH = 5 ' - Document units
Parameter("LENGTH") = 5 ' - Document units
ThisDoc.Document.ComponentDefinition.Parameters("LENGTH").Value = 5 ' - Database units
ThisDoc.Document.ComponentDefinition.Parameters("LENGTH").Expression = "5" ' - Document units

 

 

EDIT:

Fixed comments according to @WCrihfield post below

 

Message 6 of 7
WCrihfield
in reply to: Michael.Navara

Hi @Michael.Navara.  I'm sure you are already aware of this, but I wanted to correct the terminology "parameter units" used here to "document units", as it pertains to using those blue, unquoted parameter names, or the 'Parameter()' iLogic methods.  Just because it is a detail that I have had to deal with on so many occasions for years. 🙄

 

If your document settings are set to Inches for length/distance units, and you create a UserParameter, set its Units to Feet, then set its value to 2, then those two iLogic tools mentioned for working with that Parameter will return that parameter's value as 24 (inches), instead of 2 (feet).  This has been a minor pain for as far back as I can remember using those iLogic tools.  Don't get me wrong, they are great tools, and I really like them, because they are super convenient and useful...but just not 'perfect' in my opinion, because they seem to be missing this small additional functionality.

 

I even created a post on the Inventor Ideas forum, wanting there to be a 'Property' or 'Method' added into the Inventor API for the Parameter type objects that would help us retrieve the parameter's value, in the same units that that parameter was currently set to, instead of always in 'database' units.  I even used the wrong terminology in parts of my Idea post. 😂  After Mike Deck discussed this topic with me, I doubt something like this will ever be implemented, because it must be a lot more complex to implement behind the scenes than I had in mind, and may simply not be in that high of demand.

https://forums.autodesk.com/t5/inventor-ideas/add-property-method-to-api-for-parameter-type-objects-... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7
tbrausen
in reply to: A.Acheson

Thank you for the input.

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

Post to forums  

Autodesk Design & Make Report