找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1153|回复: 1

[求助]:请教xd:见内!谢谢!

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

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

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

×
一:获得块的相关坐标。见附件
    因为我要对块进行管理,如相关块统计、各个块端点的属性等
二:关于钩子问题。
  昨天从您处获得的代码加入钩子后所获得的坐标不对,麻烦帮我看看,谢谢!
  生成钩子:
  m_hHook=::SetWindowsHookEx(WH_MOUSE,MouseHookProc,(HINSTANCE)NULL,GetCurrentThreadId());
  钩子函数:
LRESULT CALLBACK MouseHookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
acedDwgPoint cpt;        
ads_point ptDCS, ptWCS, norm;        
AcGePoint3d  origin;        
AcGeVector3d e0, e1, e2;        
AcGeMatrix3d  matUcs2Wcs, matWcs2Ucs;        
// 1: Get the Mouse coords in DCS        
CPoint cPnt (lParam) ;        
acedCoordFromPixelToWorld (cPnt, cpt) ;        
acdbPointSet ( cpt, ptDCS );            
//acutPrintf ( "\nMouse in Ucs %f, %f, %f",  ptDCS[X], ptDCS[Y],ptDCS[Z] );      
//return FALSE;        
// 2: Transform the Mouse coords from DCS to WCS        
// For this we use the    acdbEcs2Ucs  function with the         
// value of the VIEWDIR system variable as the input normalvector of ECS        
// (Sure we have to transform the VIEWDIR value from UCS to WCS        
struct resbuf rbview;        
acedGetVar( "viewdir", &rbview );        
ads_point_set( rbview.resval.rpoint, norm );        
// If the view direction is 0, 0, 1, then acedCoordFromPixelToWorld()        
// needs special handling -> we only have to translate the thepoint      
// by the distance the origin of the current UCS was moved        
double tol = 1e-10;        
if ((fabs(norm[X]) < tol) && (fabs(norm[Y]) < tol) &&((fabs(norm[Z]) - 1.0) < tol))
{            
AcGePoint3d acadPt;            
acadPt.x = cpt[0];            
acadPt.y = cpt[1];            
acadPt.z = cpt[2];            
acdbUcsMatrix ( matUcs2Wcs );                     
matUcs2Wcs.invert();            
matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);            
acadPt += origin.asVector();            
acutPrintf ( "\nMouse in Ucs %f, %f, %f",  acadPt[X],acadPt[Y], acadPt[Z] );            
          }        
  //transfoming VIEWDIR  to WCS        
acdbUcs2Wcs ( norm, norm, Adesk::kTrue );        
// Transforming the mouse coords from DCS to WCS        
acdbEcs2Wcs( ptDCS, ptWCS, norm, Adesk::kTrue );        
// 3: Get the Mouse coordinates in UCS        //        
// For this we have to project the WCS coordinates to the UCSplane using         
// the VIEWDIR vector as projection direction.        //        
// Getting the UCS->WCS transformation matrix        
acdbUcsMatrix ( matUcs2Wcs );                 
matUcs2Wcs.getCoordSystem( origin, e0, e1, e2);        
// Creating a plane which lies on the current UCS        
//        
AcGePlane thePlane ( origin, e0, e1);        
AcGePoint3d  pntMouseInWCS( ptWCS[X], ptWCS[Y], ptWCS[Z] );        
AcGeVector3d vecViewdir( norm [X], norm [Y], norm [Z] );        
// Making the projection        
AcGePoint3d resPnt = pntMouseInWCS.project (thePlane, vecViewdir);        
// Transforming the point coordinates to UCS.        
matWcs2Ucs = matUcs2Wcs.inverse();        
resPnt.transformBy ( matWcs2Ucs );        
//this line prints the same coordinates as the coordinates         
//shown in  AutoCAD's status bar        
acutPrintf ( "\nMouse in Ucs %f, %f, %f",  resPnt[X], resPnt[Y],resPnt[Z] );

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

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-3-8 02:54:12 | 显示全部楼层

Re: [求助]:请教xd:见内!谢谢!

最初由 梦宁 发布
[B]一:获得块的相关坐标。见附件
    因为我要对块进行管理,如相关块统计、各个块端点的属性等
二:关于钩子问题。
  昨天从您处获得的代码加入钩子后所获得的坐标不对,麻烦帮我看看,谢谢!
  生成钩子:
  m_... [/B]


1.座标怎么不对,昨天的代码是获得UCS下的座标,如要WCS下的,用转换矩阵转换下就可以,另外,ARX有自己的定义钩子的函数。acedRegisterFilterWinMsg等。

2. 你可以遍历AcDbBlockTableRecord,获得块内的每个实体的终点,起点座标,然后根据AcDbBlockRefence的插入的转换矩阵换算到INSERT示例上的点。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-21 22:57 , Processed in 0.173826 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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