Align cursor position with preview Revit snap

Align cursor position with preview Revit snap

test.arent
Explorer Explorer
277 Views
1 Reply
Message 1 of 2

Align cursor position with preview Revit snap

test.arent
Explorer
Explorer

Hi all,

Currently, I get the mouse position in the Revit environment as follows

 

 

var uiView = uiDocument.GetOpenUIViews().First(x => x.ViewId == uiDocument.ActiveView.Id);
var corners = uiView.GetZoomCorners();
var rect = uiView.GetWindowRectangle();
var position = System.Windows.Forms.Cursor.Position;
var dx = (double)(position.X - rect.Left) / (rect.Right - rect.Left);
var dy = (double)(position.Y - rect.Bottom) / (rect.Top - rect.Bottom);
var minPoint = corners[0];
var maxPoint = corners[1];
var vector = maxPoint - minPoint;
var mousePoint = minPoint + dx * vector.X * XYZ.BasisX + dy * vector.Y * XYZ.BasisY;

 

 

Because of the snap, in Revit, 2 points (snap, cursor position) as shown below are considered the same, how to get the mouse position at the snap position before clicking.
Thanks

 

A.png

0 Likes
278 Views
1 Reply
Reply (1)
Message 2 of 2

RPTHOMAS108
Mentor
Mentor

Not straightforward if you want the position of the snap cursor rather than the current cursor position before selection.

 

My only suggestion would be to test for local candidates based on locality to the cursor position i.e. in terms of the 'nearest' snap you could use Curve.Project for the items you are most interested in within the view. Then the item with the smallest distance to cursor will indicate the snap point location.

 

However regarding the 'Distance' and 'Project' methods you have to be mindful of the conditions under which they will fail and throw an exception.

0 Likes