找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2674|回复: 12

[求助]:XD,tooltip找到了,但是获取鼠标坐标没有找到,

[复制链接]
发表于 2002-3-7 02:30:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
关于获取鼠标在autocad的坐标(鼠标滑动时)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-3-7 02:34:05 | 显示全部楼层

Re: [求助]:XD,tooltip找到了,但是获取鼠标坐标没有找到,

最初由 梦宁 发布
[B]关于获取鼠标在autocad的坐标(鼠标滑动时) [/B]


给你贴个资料:如何获得鼠标的在UCS下的座标

How to get the mouse cursor coordinates in UCS?  
ID    3115  
Applies to:    AutoCAD 2000I

Date    1/29/2002  

This document is part of    UCS   Processing User Input     


Question
How do I get the mouse cursor coordinates in UCS?
Answer
The following code obtains and prints the mouse coordinates in the UCS. The
coordinates are the same as the coordinates displayed in AutoCAD's status bar
(for you to see and verify).

To test it replace the filterMouse() function in
the...\ObjectARX\SAMPLES\MFCSAMPS\PRETRANSLATE sample with the one that follows,
then compile the project, load it in AutoCAD and enter the WMOUSE command.


  1. BOOL filterMouse(MSG *pMsg)
  2. {   
  3. if( pMsg->message == WM_MOUSEMOVE )   
  4. {        
  5.   acedDwgPoint cpt;        
  6.   ads_point ptDCS, ptWCS, norm;        
  7.   AcGePoint3d  origin;        
  8.   AcGeVector3d e0, e1, e2;        
  9.   AcGeMatrix3d  matUcs2Wcs, matWcs2Ucs;        
  10.   // 1: Get the Mouse coords in DCS        
  11.   CPoint cPnt (pMsg->lParam) ;        
  12.   acedCoordFromPixelToWorld (cPnt, cpt) ;        
  13.   acdbPointSet ( cpt, ptDCS );            
  14.   //acutPrintf ( "\nMouse in Ucs %f, %f, %f",  ptDCS[X], ptDCS[Y],ptDCS[Z] );      
  15.    //return FALSE;        
  16.   // 2: Transform the Mouse coords from DCS to WCS        
  17.   // For this we use the    acdbEcs2Ucs  function with the         
  18.   // value of the VIEWDIR system variable as the input normalvector of ECS        
  19.   // (Sure we have to transform the VIEWDIR value from UCS to WCS        
  20.   struct resbuf rbview;        
  21.   acedGetVar( "viewdir", &rbview );        
  22.   ads_point_set( rbview.resval.rpoint, norm );        
  23.   // If the view direction is 0, 0, 1, then acedCoordFromPixelToWorld()        
  24.   // needs special handling -> we only have to translate the thepoint      
  25.    // by the distance the origin of the current UCS was moved        
  26.   double tol = 1e-10;        
  27.   if ((fabs(norm[X]) < tol) && (fabs(norm[Y]) < tol) &&((fabs(norm[Z]) - 1.0) < tol))
  28.   {            
  29.    AcGePoint3d acadPt;            
  30.    acadPt.x = cpt[0];            
  31.    acadPt.y = cpt[1];            
  32.    acadPt.z = cpt[2];            
  33.    acdbUcsMatrix ( matUcs2Wcs );                     
  34.    matUcs2Wcs.invert();            
  35.    matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);            
  36.    acadPt += origin.asVector();            
  37.    acutPrintf ( "\nMouse in Ucs %f, %f, %f",  acadPt[X],acadPt[Y], acadPt[Z] );            
  38.    return FALSE;        
  39.   }        
  40.   //transfoming VIEWDIR  to WCS        
  41.   acdbUcs2Wcs ( norm, norm, Adesk::kTrue );        
  42.   // Transforming the mouse coords from DCS to WCS        
  43.   acdbEcs2Wcs( ptDCS, ptWCS, norm, Adesk::kTrue );        
  44.   // 3: Get the Mouse coordinates in UCS        //        
  45.   // For this we have to project the WCS coordinates to the UCSplane using         
  46.   // the VIEWDIR vector as projection direction.        //        
  47.   // Getting the UCS->WCS transformation matrix        
  48.   acdbUcsMatrix ( matUcs2Wcs );                 
  49.   matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);        
  50.   // Creating a plane which lies on the current UCS        
  51.   //        
  52.   AcGePlane thePlane ( origin, e0, e1);        
  53.   AcGePoint3d  pntMouseInWCS( ptWCS[X], ptWCS[Y], ptWCS[Z] );        
  54.   AcGeVector3d vecViewdir( norm [X], norm [Y], norm [Z] );        
  55.   // Making the projection        
  56.   AcGePoint3d resPnt = pntMouseInWCS.project (thePlane, vecViewdir);        
  57.   // Transforming the point coordinates to UCS.        
  58.   matWcs2Ucs = matUcs2Wcs.inverse();        
  59.   resPnt.transformBy ( matWcs2Ucs );        
  60.   //this line prints the same coordinates as the coordinates         
  61.   //shown in  AutoCAD's status bar        
  62.   acutPrintf ( "\nMouse in Ucs %f, %f, %f",  resPnt[X], resPnt[Y],resPnt[Z] );    }   
  63.   return FALSE; // continue
  64. }


NOTE: This doesn't work in perspective view because acedCoordFromPixelToWorld()
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-3-7 02:38:06 | 显示全部楼层

Re: Re: [求助]:XD,tooltip找到了,但是获取鼠标坐标没有找到,

最初由 XDSoft 发布
[B]

给你贴个资料:如何获得鼠标的在UCS下的座标

How to get the mouse cursor coordinates in UCS?  
ID    3115... [/B]


把上面的函数定义成“钩子”就可以了,获得ACAD的消息
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2002-3-7 05:58:01 | 显示全部楼层
谢谢晓东
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-3-7 06:04:20 | 显示全部楼层
最初由 梦宁 发布
[B]谢谢晓东 [/B]


不必客气,欢迎常来,你才发了3个帖子:),多帮助大家。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-6-16 23:41:08 | 显示全部楼层
帮了我大忙了,谢谢~~~
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-6-17 12:36:53 | 显示全部楼层
一个根据acad屏幕坐标获取当前窗口的象素坐标,可以提供给CView用

  1. CPoint GetScreenPoint( AcGePoint3d  aptIns)
  2. {
  3. AcGePoint3d scrSize;
  4.     AcGePoint3d viewctr;
  5.   double viewSizeH,viewSizeW;
  6.     CPoint pt;

  7.    oxaGetVar("SCREENSIZE",scrSize);
  8.    oxaGetVar("viewSize" , viewSizeH);
  9.    oxaGetVar("viewctr" , viewctr);
  10.    viewSizeW=viewSizeH*scrSize.x/scrSize.y;  //获取水平宽度

  11.   pt.x=scrSize.x*( aptIns.x-viewctr.x+0.5*viewSizeW)/viewSizeW;
  12.   pt.y=scrSize.y*( viewctr.y-aptIns.y+0.5*viewSizeH)/viewSizeH;
  13. return pt;
  14. }
复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 145个

财富等级: 日进斗金

发表于 2004-6-17 12:59:24 | 显示全部楼层
最初由 fylinwater 发布
[B]一个根据acad屏幕坐标获取当前窗口的象素坐标,可以提供给CView用
[code]
CPoint GetScreenPoint()
{
AcGePoint3d scrSize;
    AcGePoint3d viewctr;
  double viewSizeH,viewSizeW;
    CPoint pt;

   ... [/B]


谢谢!请把函数 oxaGetVar 代码也贴上来吧。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-6-20 20:05:23 | 显示全部楼层
个人时间有限 oxarx一直没有整理,暂时贴出oxaGetVar    (应该比acedGetVar简化了很多,但是还不完善,写着自己用的,有些检查没有做,只好谨慎着用了)


  1. ///////////////////////////////////////////////////////////////
  2. //        函 数 名 : oxaGetVar
  3. //        函数功能 :
  4. //        处理过程 :
  5. //        备    注 :
  6. //        作    者 : user
  7. //        时    间 : 2004年6月16日
  8. //        返 回 值 : int
  9. //        参数说明 : const CString strSym,
  10. //                                 AcGePoint3d &vOut
  11. ///////////////////////////////////////////////////////////////
  12. int oxaGetVar(const CString strSym, AcGePoint3d &vOut )
  13. {   
  14.         resbuf  rbVar ;
  15.         int iRt=acedGetVar(strSym,  &rbVar) ;
  16.         if (iRt!=RTNORM)
  17.         {
  18.                 return iRt;
  19.         }
  20.         //oxaPrint(&rbVar);  
  21.        
  22.     if (rbVar.restype==RTPOINT)
  23.         {
  24.                 vOut.x=rbVar.resval.rpoint[0];
  25.                 vOut.y=rbVar.resval.rpoint[1];
  26.         }       
  27.         if (rbVar.restype==RT3DPOINT)
  28.         {
  29.                 vOut.x=rbVar.resval.rpoint[0];
  30.                 vOut.y=rbVar.resval.rpoint[1];
  31.                 vOut.z=rbVar.resval.rpoint[2];
  32.         }       
  33.     return RTNORM;
  34. }



  35. /////////////////////////////////////////////////////////////////////////////////
  36. //#  DOC.BEGIN
  37. //#  函数名称: oxaGetVar
  38. //#  函数编号: OXA
  39. //#  函数声明:
  40. //#  函数参数: const CString strSym,
  41. //                                 int &vOut
  42. //#  返回值:   int
  43. //#  函数分类:
  44. //#  函数功能: 获取系统变量, 封装acedGetVar()
  45. //#  注意事项:
  46. //#  涉及的全局变量:
  47. //#  调用的OXARX函数:
  48. //#  函数算法:  
  49. //#  ACAD版本:R14  R15  R16
  50. //#  配合函数:
  51. //#  类似函数:
  52. //#  替换函数:
  53. //#  现存缺陷:
  54. //#  示例程序:
  55. //#  测试要求:
  56. //#  历史记录: 2003年11月10日 , zjw ,完成
  57. //
  58. //#  DOC.END
  59. //////////////////////////////////////////////////////////////////////////

  60. int oxaGetVar(const CString strSym, int &vOut )
  61. {   
  62.         resbuf rbVar;
  63.         int iRt=acedGetVar(strSym, &rbVar) ;
  64.         if (iRt!=RTNORM)
  65.         {
  66.                 return iRt;
  67.         }
  68.        
  69.     if (rbVar.restype==RTLONG)
  70.         {
  71.                 vOut=rbVar.resval.rlong;
  72.         }
  73.     if (rbVar.restype==RTSHORT)
  74.         {
  75.                 vOut=rbVar.resval.rint;
  76.     }

  77.     return RTNORM;
  78. }

  79. /////////////////////////////////////////////////////////////////////////////////
  80. //#  DOC.BEGIN
  81. //#  函数名称: oxaGetVar
  82. //#  函数编号: OXA
  83. //#  函数声明:
  84. //#  函数参数: const CString strSym,
  85. //                                 double &vOut
  86. //#  返回值:   int
  87. //#  函数分类:
  88. //#  函数功能: 获取系统变量, 封装acedGetVar()
  89. //#  注意事项:
  90. //#  涉及的全局变量:
  91. //#  调用的OXARX函数:
  92. //#  函数算法:  
  93. //#  ACAD版本:R14  R15  R16
  94. //#  配合函数:
  95. //#  类似函数:
  96. //#  替换函数:
  97. //#  现存缺陷:
  98. //#  示例程序:
  99. //#  测试要求:
  100. //#  历史记录: 2003年11月24日 , zjw ,完成
  101. //
  102. //#  DOC.END
  103. int oxaGetVar(const CString strSym, double &vOut )
  104. {   
  105.         resbuf rbVar;
  106.         int iRt=acedGetVar(strSym, &rbVar) ;
  107.         if (iRt!=RTNORM)
  108.         {
  109.                 return iRt;
  110.         }
  111.        
  112.     if (rbVar.restype==RTREAL)
  113.         {
  114.                 vOut=rbVar.resval.rreal;
  115.         }       
  116.     return RTNORM;
  117. }

  118. /////////////////////////////////////////////////////////////////////////////////
  119. //#  DOC.BEGIN
  120. //#  函数名称: oxaGetVar
  121. //#  函数编号: OXA
  122. //#  函数声明:
  123. //#  函数参数: const CString strSym,
  124. //                                 CString &vOut
  125. //#  返回值:   int
  126. //#  函数分类:
  127. //#  函数功能:获取系统变量, 封装acedGetVar()
  128. //#  注意事项:
  129. //#  涉及的全局变量:
  130. //#  调用的OXARX函数:
  131. //#  函数算法:  
  132. //#  ACAD版本:R14  R15  R16
  133. //#  配合函数:
  134. //#  类似函数:
  135. //#  替换函数:
  136. //#  现存缺陷:
  137. //#  示例程序:
  138. //#  测试要求:
  139. //#  历史记录: 2003年11月24日 , zjw ,完成
  140. //
  141. //#  DOC.END
  142. int oxaGetVar(const CString strSym, CString &vOut )
  143. {   
  144.         resbuf rbVar;
  145.         int iRt=acedGetVar(strSym, &rbVar) ;
  146.         if (iRt!=RTNORM)
  147.         {
  148.                 return iRt;
  149.         }
  150.        
  151.     if (rbVar.restype==RTSTR)
  152.         {
  153.                 vOut=rbVar.resval.rstring;
  154.         }       
  155.     return RTNORM;
  156. }

复制代码
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-9-28 11:06:28 | 显示全部楼层
不错,顶。顺便问下 BOOL filterMouse(MSG *pMsg) 这个函数获得的坐标怎么不精确?谢谢
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2005-9-14 21:30:56 | 显示全部楼层
谢谢大家,我对ARX又有了更深的了解
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1个

财富等级: 恭喜发财

发表于 2006-5-30 09:32:01 | 显示全部楼层
书上讲要程序来释放字符串内存,不知是否?
free(rbVar.resval.rstring);
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-7-16 19:37:50 | 显示全部楼层

Re: Re: [求助]:XD,tooltip找到了,但是获取鼠标坐标没有找到,

最初由 XDSoft 发布
[B]

给你贴个资料:如何获得鼠标的在UCS下的座标

How to get the mouse cursor coordinates in UCS?  
ID    3115... [/B]


我编译的时候,acdbUcs2Wcs等几个函数都没有,是怎么回事
需要另外包涵什么头文件吗?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-23 16:16 , Processed in 0.445174 second(s), 56 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表