Rule to measure an edge and asign to a parameter

Rule to measure an edge and asign to a parameter

kostremEEC7J
Enthusiast Enthusiast
343 Views
3 Replies
Message 1 of 4

Rule to measure an edge and asign to a parameter

kostremEEC7J
Enthusiast
Enthusiast

So I set up a rule to select a face of an object and export the area of the face to a parameter. I would like to do something similar except I want to measure an edge of a part, and export that selected length as a parameter. I am unable to figure out what code I need to export the measured distance of an edge select.

I figured this was the code I needed to select the edge but I don't know how to get that to a parameter:

ThisApplication.CommandManager.Pick(SelectionfilterEnum.kPartEdgeFilter, "Length_1")

I am extremely novice when it come to writing ilogic rules and code. I can take something someone else has wrote and manipulate it to do what I want closely but I fail often writing from scratch. Any pointers or well written guides you can direct me to with common code templates etc.?

Thank you.

0 Likes
344 Views
3 Replies
Replies (3)
Message 2 of 4

dalton98
Collaborator
Collaborator

The easiest way to do this would be to use the measure tool. See below code. I tried to comment my thought process when writing it

'find the object type of the selected part
'it returned a number so look up that number
'inventor top right (?) icon -> programming/api help -> search the number

'test = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Length_1")
'MessageBox.Show(test.Type.ToString)


'the selection was and Edge or EdgeProxy in assembly enviroment
Dim oEdge As EdgeProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, "Length_1")
'measure tool using the start and end point of the edge
Dim oLength As Double = ThisApplication.MeasureTools.GetMinimumDistance(oEdge.StartVertex.Point, oEdge.StopVertex.Point)

'i used 'Document' so it would work for 'PartDocument' and 'AssemblyDocument' Dim oDoc As Document = ThisDoc.Document Dim oUserParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim oUserParam As UserParameter
'try to get user parameter "Length_1"
'if it fails then create that parameter with the Catch Try oUserParam = oUserParams.Item("Length_1") Catch oUserParam = oUserParams.AddByValue("Length_1", oLength, UnitsTypeEnum.kInchLengthUnits) End Try
0 Likes
Message 3 of 4

kostremEEC7J
Enthusiast
Enthusiast

iLogic Rule Error.png

@dalton98I used that rule and I couldn't get it to work. It gives me an error which I'll attach. Regardless I appreciate your efforts.

0 Likes
Message 4 of 4

dalton98
Collaborator
Collaborator

What is on line 10? If its "Dim oEdge As EdgeProxy = ...." you would have to use "Dim oEdge as Edge" for a part document. Or just leave out the As Object "Dim oEdge = ...."

 

 

0 Likes