Find an entity under the cursor position using Win32 and ObjectARX

<?xml encoding=”UTF-8″>By Fenton Webb

Issue

How do I find the entity under the cursor position using raw Win32?

Solution

The best way to find the entity under the cursor/crosshair is to use the AcEdInputPointMonitor class. However, if you must find the entity under the cursor using raw Win32, here’s how…

First, to catch a mouse event before any “normal” AutoCAD’s action (such as, pressing mouse down/up) takes place, you can register your own event-handling function, using acedRegisterFilterWinMsg(). ObjectARX 2008 SDK comes with a good sample about this (objectarxsampleseditormfcsampspretranslate). Please refer it for the detail about capturing AutoCAD Window’s messaging.

Secondly, in the actual event-handling function of your own, you can use acedSSGet() with the option “_:E” (select everything within the cursor’s object selection pickbox option). By specifying only the first point, you can make a selection window as the same as the cursor position.

The following code defines a function that you can register with acedRegisterFilterWinMsg(). To test this code, simply replace the function named FilterMouse() in the sample project (objectarxsampleseditormfcsampspretranslate) with the following one.

BOOL filterMouse(MSG *pMsg)<br>{<br> if( pMsg->message == WM_MOUSEMOVE   || <br>  pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP ) {
<p>  acedDwgPoint cpt={ 0, 0, 0 };<br>  CPoint cPnt(pMsg->lParam);<br>  acedCoordFromPixelToWorld(cPnt, cpt) ;<br>  ads_point pt={ cpt[X], cpt[Y], 0 } ;<br>  ads_name ss;<br>  acedSSGet(L"_:E", pt, NULL, NULL, ss) ;<br>  long len =0 ;<br>  acedSSLength(ss, &len) ;<br>  acutPrintf(L"nThe ss length is %d", len) ;<br>  acedSSFree(ss) ;<br>  if ( pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP )<br>   unmouse ();<br> }<br> return (FALSE) ; //----- continue<br>}</p>

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading