Using the Measure.MinimumDistance command

Using the Measure.MinimumDistance command

Anonymous
Not applicable
3,443 Views
4 Replies
Message 1 of 5

Using the Measure.MinimumDistance command

Anonymous
Not applicable

Hi guys and gals,

 

I want to pick 2 points in a part file (IPT, not IAM) and get the minimum distance, and pass this value to a variable, all within an iLogic rule. Sounds fairly straightforward, right? Wrong. The command will not give me the value. I can pick 2 faces, but get this error : "No entity named "System.__ComObject" was found."

 

I created WorkPoints, WorkPlanes, Sketches and tried using filters, no result. I've seen some code to be used in assemblies, but that does not apply here. 

 

Here's what I have, and if you ask me, it should be this simple: 

 

SyntaxEditor Code Snippet

Dim Face1 as Face
Dim Face2 as Face
Dim DistPoints as Double

Dim oDoc As PartDocument 
oDoc = ThisApplication.ActiveDocument 
Face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 1 : ") 
Face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 2 : ") 
DistPoints = Measure.MinimumDistance(Face1, Face2)
'  Do something with DistPoints

 

Can anyone help me please?

 

Thank you

0 Likes
Accepted solutions (1)
3,444 Views
4 Replies
Replies (4)
Message 2 of 5

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi,

 

I am able to recreate the error using the code in an iLogic rule.

 

I find that if something is not working in iLogic it is very useful to try it in VBA.  One thing is that it is easy to debug and see where the error is and the VBA Watch window is helpful to see what is going on in the variables. To use in VBA I had to change the method names. iLogic is using the Inventor API under the hood and in the API the object for measuring is called MeasureTools. (not Measure) Here is the VBA code that gets the distance between two faces:

 

Sub measureBetweenFaces()
    Dim Face1 As Face
    Dim Face2 As Face
    Dim DistPoints As Double
    
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Set Face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 1 : ")
    Set Face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 2 : ")
    DistPoints = ThisApplication.MeasureTools.GetMinimumDistance(Face1, Face2)
End Sub

 

I see in the iLogic snippet. It seems that it does not support faces in a part:

iLogic_snippet_Measure.jpg

 

Becuase the VBA code works I just moved it over to the iLogic rule and it is working in my tests. Keep in mind that the API is going to return the distance in internal units which is centimeters for length.  (there are methods in the API to translate values between different units)

 

iLogic code:

Dim Face1 as Face
Dim Face2 as Face
Dim DistPoints as Double

Dim oDoc As PartDocument 
oDoc = ThisApplication.ActiveDocument 
Face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 1 : ") 
Face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 2 : ") 
'DistPoints = Measure.MinimumDistance(Face1, Face2)
DistPoints = ThisApplication.MeasureTools.GetMinimumDistance(Face1, Face2)
MessageBox.Show("DistPoints = " & DistPoints.ToString(), "Title")

 

Thanks,

Wayne

 

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 5

Anonymous
Not applicable

Awesome! It's exactly what I wanted! 

 

Is there a place where all the Methods and Commands are listed? Where can I sign up for this class or buy a book? iLogic is so much more powerful than what is usually shown on the internet forums. 

 

Thank you so much. Another nugget in the ol' Bag-O-Tricks 🙂

0 Likes
Message 4 of 5

wayne.brill
Collaborator
Collaborator

Hi,

 

The last page in the Inventor "My First Plug-In" has a list of resoruces for learning the Inventor API.

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17329549

 

Also the Programming help should be a first place to look.  (I refer to it often)

Programming_Help.jpg

 

 

I am not sure if there are other resources for iLogic.

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 5 of 5

Anonymous
Not applicable

Hi Wayne, this is great and would make a very repetitive task in my application much simpler but I can't get it to work right in my application.

 

In my application I work within an assembly. My goal is to edit a component in place and with the code within the part measure two faces of an assembly and have the part update length based on the measurement.

 

Some things I had to do with your code to have it run at all. First I commented out line 4 as with this it did not want to work within an assembly. Second I commented out the result box as it is not needed and last I applied the measured value to the length parameter of the part.

 

The issue is that once I run the code it will keep asking me to select face 1 and face 2 until hit the regenerate button at which point the part length is updated. I've tried adding an update command at the end but the face 1/2 selection keeps looping.

 

Thank you in advance for your help

 

SyntaxEditor Code Snippet

Dim Face1 as Face
Dim Face2 as Face
Dim DistPoints as Double
'Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 1 : ")
Face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick Face 2 : ")
'DistPoints = Measure.MinimumDistance(Face1, Face2)
DistPoints = ThisApplication.MeasureTools.GetMinimumDistance(Face1, Face2)
'MessageBox.Show("DistPoints = " & DistPoints.ToString(), "Title")
length = DistPoints

 

 

 

0 Likes