How to get the pixel coordinates of the drawing point on the screen

How to get the pixel coordinates of the drawing point on the screen

lzs013
Advocate Advocate
1,435 Views
4 Replies
Message 1 of 5

How to get the pixel coordinates of the drawing point on the screen

lzs013
Advocate
Advocate

How to get the pixel coordinates of the drawing point(as shown in the figure) on the screen。Snipaste_2018-11-19_17-09-09.png

0 Likes
1,436 Views
4 Replies
Replies (4)
Message 2 of 5

JamieVJohnson2
Collaborator
Collaborator

If the user clicks the point on the screen, a hit test can be used to compare with the pixels of the click event.  However, I can't find a way to translate the document position (can get sheet position from any sketch point) to the graphics editor's pixel position (sheet relative to window).  It is not exposed in the standard API (there's a challenge for somebody to prove me wrong).

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 5

lzs013
Advocate
Advocate

I think that the following method should be able to get the pixel coordinates of the endpoint on the drawing, but I failed because of my limited level.

 

1. Get the coordinates of the curve endpoint in the sheet

DrawingCurve.EndPoint()

2. Get the line of the point in the model space

DrawingView.DrawingViewToModelSpace()

3. Get the model vertice that are crossed by the line

AssemblyComponentDefinition.FindUsingRay()

4. Get the pixel coordinates of the vertex on the screen

Camera.ModelToViewSpace()

0 Likes
Message 4 of 5

BrianEkins
Mentor
Mentor

It's not clear from your question where the points are coming from.  In the end, you need to get the point in 3D model space, so if the point is from a drawing, or from a sketch, or from a part in an assembly or subassembly, there are different approaches to get that position in model space.  Once you have the correct 3D coordinate, you can get the corresponding screen coordinate using:

 

Dim viewPoint As Point2D
Set viewPoint = ThisApplication.ActiveView.Camera.ModelToViewSpace(modelPoint)
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 5 of 5

lzs013
Advocate
Advocate

The point I want comes from drawing

0 Likes