TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
AutoCAD API 提供了 AcEdInputPointManager。输入点监视器(Inputpointmonitor )能够监视用户的任何输入,包括鼠标。API还能够监视WINDOWS的消息,有时你需要不通过事件来获取鼠标的位置,下面代码是一个示例,获得当前鼠标光标的位置并转换到AutoCAD的坐标系(考虑了UCS).
- 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]);
- }
复制代码 |
|