How to get the position of a WorkPoint

How to get the position of a WorkPoint

Dartherick
Contributor Contributor
2,353 Views
13 Replies
Message 1 of 14

How to get the position of a WorkPoint

Dartherick
Contributor
Contributor

Hello everyone,

 

in an assembly I have workpoint, which is going to move depending of some parameters in the assembly.

 

I would like to get the position (in X,Y & Z) of the workpoint to use it in a future form.

 

Any help would be much appreciated!

Thanks.

0 Likes
Accepted solutions (2)
2,354 Views
13 Replies
Replies (13)
Message 2 of 14

JelteDeJong
Mentor
Mentor

Does this help you:

Dim wp As WorkPoint = ThisApplication.CommandManager.Pick(
    SelectionFilterEnum.kWorkPointFilter,
    "Select work point")

MsgBox(wp.Point.X & " - " & wp.Point.Y & " - " & wp.Point.Z)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 14

Dartherick
Contributor
Contributor

Hi JelteDeJong.

 

Since I would like to see the position in realtime in a form, I modified a little bit your code adding the position in user parameters.

 

Dim wp As WorkPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPointFilter,"Select work point")

X = wp.Point.X
Y = wp.Point.Y
Z = wp.Point.Z

The issue I am having right now with this code is that I can't get the position in realtime, I need to execute this code everytime I want to see it.

 

0 Likes
Message 4 of 14

Ralf_Krieg
Advisor
Advisor

Hello

 

Then you should give this workpoint a name to identify. Let's say the name in model browser is "WP_xyz". Then you create a rule like this:

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As PartComponentDefinition=oDoc.ComponentDefinition
Dim oWP As WorkPoint
For Each oWP In oDef.WorkPoints
	If oWP.Name = "WP_xyz" Then Exit For
Next

If Not oWP Is Nothing Then
	X = oWP.Point.X
	Y = oWP.Point.Y
	Z = oWP.Point.Z
End If

 

After this, add this rule to the event trigger "geometry change" in this document. This assumes the workpoint position is defined by a geometry point, so the trigger fires the rule. If it is defined as fixed point, you need to use an extra event handler for this.

Open your form with modal=false option and change the geometry. As your workpoint moves to a new position, your XYZ-values update.


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 5 of 14

Dartherick
Contributor
Contributor

Hi  Betreff,

 

I think your code is the key to get it, but when I run the rule, I get the following error message:

 

"Error in rule: Position, in document: Robotic arm.iam

Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

 

and in the "More Info tab", I get:

 

"System.InvalidCastException: Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

0 Likes
Message 6 of 14

WCrihfield
Mentor
Mentor

I think you can just change the first two lines to this:

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
oDef = oDoc.ComponentDefinition

 

Code was expecting a Part, but it was an assembly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 14

Dartherick
Contributor
Contributor

Hey,

That was causing the error message, now the rule run perfectly, but I think there is another issue, since the position that I am getting is not correct.

 

Dartherick_0-1636660668327.png

 

I am attaching the assembly created in inventor 2018.

0 Likes
Message 8 of 14

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Sorry for the mistake part vs assembly.

Your actual error is, the rule gives the position in database units (cm).

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As ComponentDefinition=oDoc.ComponentDefinition
Dim oWP As WorkPoint
For Each oWP In oDef.WorkPoints
	If oWP.Name = "WP_xyz" Then Exit For
Next

If Not oWP Is Nothing Then
	X = ThisApplication.UnitsOfMeasure.ConvertUnits(oWP.Point.X,"cm","in")
	Y = ThisApplication.UnitsOfMeasure.ConvertUnits(oWP.Point.Y,"cm","in")
	Z = ThisApplication.UnitsOfMeasure.ConvertUnits(oWP.Point.Z,"cm","in")
End If

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 9 of 14

Dartherick
Contributor
Contributor
Thanks everyone for the support, especially Krieg.
0 Likes
Message 10 of 14

Miguelbam03
Observer
Observer
Your lines of code work fine but only with workpoints, however I need to get the position of a 2D point, I tried to rewrite your lines of code but I can't get the position, can you help me please?
0 Likes
Message 11 of 14

WCrihfield
Mentor
Mentor

Hi @Miguelbam03.  How do you intend to specify which Point2d object the iLogic rule is supposed to report the position of?  Here is a simple example that just creates its own Point2d Object, then uses a MsgBox to show you its coordinates.

 

Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPoint2D As Point2d = oTG.CreatePoint2d(6, 6)
X = oPoint2D.X
Y = oPoint2D.Y
MsgBox("X = " & X & "  Y = " & Y,,"Point2d Position")

 

Or, do you mean a SketchPoint?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 14

Miguelbam03
Observer
Observer
I have a Sketch with one Circle, I want to use the "Commandmanager.Click" function to select this Circle and get a MsgBox with the center coordinates of this circle.
0 Likes
Message 13 of 14

WCrihfield
Mentor
Mentor
Accepted solution

OK, sure.  Here you go.

oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveCircularFilter, "Select a Sketch Circle.")
If IsNothing(oObj) OrElse (TypeOf oObj Is SketchCircle = False) Then Exit Sub
Dim oSketchCircle As SketchCircle = oObj
X = oSketchCircle.CenterSketchPoint.Geometry.X
Y = oSketchCircle.CenterSketchPoint.Geometry.Y
MsgBox("X = " & X & "  Y = " & Y,,"SketchCircle Center Position")

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 14 of 14

Miguelbam03
Observer
Observer
Thanks a lot for your support, it was helpful!
0 Likes