- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
AutoCAD API 提供了 AcEdInputPointManager。输入点监视器(Inputpointmonitor )能够监视用户的任何输入,包括鼠标。API还能够监视WINDOWS的消息,有时你需要不通过事件来获取鼠标的位置,下面代码是一个示例,获得当前鼠标光标的位置并转换到AutoCAD的坐标系(考虑了UCS).
![](source/plugin/imc_colorcode/images/loading.gif) - static void getMousePosition(void)
- {
- //get cursor position by Windows API
- POINT CursorPos;
- GetCursorPos(&CursorPos);
- acedGetAcadDwgView()->ScreenToClient(&CursorPos);
- //Returns the viewport number based on
- // Windows client coordinates.
- int vpNum = acedGetWinNum(CursorPos.x, CursorPos.y);
- //Converts coordinates from AutoCAD
- // drawing window
- //to current active viewport's coordinates
- acedDwgPoint acPt, newPt;
- acedCoordFromPixelToWorld(vpNum,
- CursorPos,
- acPt);
- double worldPoint[3];
- acedCoordFromPixelToWorld(vpNum,
- CPoint(CursorPos.x,
- CursorPos.y) ,
- worldPoint);
- acutPrintf(
- L"\nModel Position (no UCS): [%f, %f, %f]\n",
- worldPoint[0],
- worldPoint[1],
- worldPoint[2]);
- //Take UCS translation in consideration
- AcGeMatrix3d mat;
- acedGetCurrentUCS(mat);
- AcGePoint3d ptUcs(worldPoint[0],
- worldPoint[1],
- worldPoint[2]);
- ptUcs.transformBy(mat.inverse());
- resbuf wcs;
- wcs.restype = RTSHORT;
- wcs.resval.rint = 0;
- resbuf dcs;
- dcs.restype = RTSHORT;
- dcs.resval.rint = 2;
- //translate the WCS coordinate to UCS
- double result[3];
- acedTrans(asDblArray(ptUcs),
- &wcs,
- &dcs,
- 0,
- result);
- acutPrintf(
- L"\nModel Position (with UCS): [%f, %f, %f]\n",
- result[0], result[1], result[2]);
- }
|
|