pengxuan 发表于 2009-10-5 15:38:00

[求助]GetCurrentView()的执行中断?

本帖最后由 作者 于 2009-10-8 16:08:23 编辑 <br /><br /> <p>向高手求助!这个函数用于获得当前视图,在VS2005+<br/>CAD2007通过了编译,执行下面ZoomScale自定义命令时却引发中断,</p><p>这是什么原因?.</p><p>static AcDbViewTableRecord GetCurrentView()<br/>{<br/>&nbsp;AcDbViewTableRecord view; <br/>&nbsp;struct resbuf rb; <br/>&nbsp;struct resbuf wcs, ucs, dcs; // 转换坐标时使用的坐标系统标记&nbsp;<br/>&nbsp;&nbsp;wcs.restype = RTSHORT; <br/>&nbsp;wcs.resval.rint = 0; <br/>&nbsp;ucs.restype = RTSHORT; <br/>&nbsp;ucs.resval.rint = 1; <br/>&nbsp;dcs.restype = RTSHORT; <br/>&nbsp;dcs.resval.rint = 2; <br/>&nbsp;&nbsp;<br/>&nbsp;// 获得当前视口的“查看”模式 <br/>&nbsp;acedGetVar(_T("VIEWMODE"), &amp;rb); <br/>&nbsp;view.setPerspectiveEnabled(rb.resval.rint &amp; 1); <br/>&nbsp;view.setFrontClipEnabled(rb.resval.rint &amp; 2); <br/>&nbsp;view.setBackClipEnabled(rb.resval.rint &amp; 4); <br/>&nbsp;view.setFrontClipAtEye(!(rb.resval.rint &amp; 16));&nbsp; <br/>&nbsp;// 当前视口中视图的中心点(UCS坐标) <br/>&nbsp;acedGetVar(_T("VIEWCTR"), &amp;rb); <br/>&nbsp;acedTrans(rb.resval.rpoint, &amp;ucs, &amp;dcs, 0, rb.resval.rpoint); <br/>&nbsp;view.setCenterPoint(AcGePoint2d(rb.resval.rpoint,rb.resval.rpoint)); <br/>&nbsp;// 当前视口透视图中的镜头焦距长度(单位为毫米) <br/>&nbsp;acedGetVar(_T("LENSLENGTH"), &amp;rb); <br/>&nbsp;view.setLensLength(rb.resval.rreal); <br/>&nbsp;<br/>&nbsp;// 当前视口中目标点的位置(以 UCS 坐标表示) <br/>&nbsp;acedGetVar(_T("TARGET"), &amp;rb); <br/>&nbsp;acedTrans(rb.resval.rpoint, &amp;ucs, &amp;wcs, 0, rb.resval.rpoint); <br/>&nbsp;view.setTarget(AcGePoint3d(rb.resval.rpoint,rb.resval.rpoint, rb.resval.rpoint));<br/>&nbsp;// 当前视口的观察方向(UCS) <br/>&nbsp;acedGetVar(_T("VIEWDIR"), &amp;rb); <br/>&nbsp;acedTrans(rb.resval.rpoint, &amp;ucs, &amp;wcs, 1, rb.resval.rpoint); <br/>&nbsp;view.setViewDirection(AcGeVector3d(rb.resval.rpoint, rb.resval.rpoint, rb.resval.rpoint)); <br/>&nbsp;<br/>&nbsp;// 当前视口的视图高度(图形单位) <br/>&nbsp;acedGetVar(_T("VIEWSIZE"), &amp;rb); <br/>&nbsp;view.setHeight(rb.resval.rreal); <br/>&nbsp;double height = rb.resval.rreal; <br/>&nbsp;// 以像素为单位的当前视口的大小(X 和 Y 值) <br/>&nbsp;acedGetVar(_T("SCREENSIZE"), &amp;rb); <br/>&nbsp;view.setWidth(rb.resval.rpoint / rb.resval.rpoint * height); <br/>&nbsp;<br/>&nbsp;// 当前视口的视图扭转角 <br/>&nbsp;acedGetVar(_T("VIEWTWIST"), &amp;rb); <br/>&nbsp;view.setViewTwist(rb.resval.rreal); <br/>&nbsp;<br/>&nbsp;// 将模型选项卡或最后一个布局选项卡置为当前 <br/>&nbsp;acedGetVar(_T("TILEMODE"), &amp;rb); <br/>&nbsp;int tileMode = rb.resval.rint; <br/>&nbsp;// 设置当前视口的标识码 <br/>&nbsp;acedGetVar(_T("CVPORT"), &amp;rb); <br/>&nbsp;int cvport = rb.resval.rint;<br/>&nbsp;// 是否是模型空间的视图 <br/>&nbsp;bool paperspace = ((tileMode == 0) &amp;&amp; (cvport == 1)) ? true : false; <br/>&nbsp;view.setIsPaperspaceView(paperspace); <br/>&nbsp; <br/>&nbsp;if (!paperspace) <br/>&nbsp;{ <br/>&nbsp;&nbsp;// 当前视口中前向剪裁平面到目标平面的偏移量 <br/>&nbsp;&nbsp;acedGetVar(_T("FRONTZ"), &amp;rb); <br/>&nbsp;&nbsp;view.setFrontClipDistance(rb.resval.rreal); <br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;// 获得当前视口后向剪裁平面到目标平面的偏移值 <br/>&nbsp;&nbsp;acedGetVar(_T("BACKZ"), &amp;rb); <br/>&nbsp;&nbsp;view.setBackClipDistance(rb.resval.rreal); <br/>&nbsp;} <br/>&nbsp;else <br/>&nbsp;{ <br/>&nbsp;&nbsp;view.setFrontClipDistance(0.0); <br/>&nbsp;&nbsp;view.setBackClipDistance(0.0); <br/>&nbsp;} <br/>&nbsp;<br/>&nbsp;return view; <br/>}<br/><br/>&nbsp;static void CHAP4ZoomScale(void)//自定义的比例缩放命令,调用了GetCurrentView<br/>&nbsp;{<br/>&nbsp;&nbsp;// Add your code for command CHAP4.ZoomScale here<br/>&nbsp;&nbsp;// 提示用户输入缩放的比例因子 <br/>&nbsp;&nbsp;ads_real scale; <br/>&nbsp;&nbsp;if (acedGetReal(L"\n输入缩放比例因子:", &amp;scale) != RTNORM) <br/>&nbsp;&nbsp;return; <br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;// 获得当前视图 <br/>&nbsp;&nbsp;AcDbViewTableRecord view = GetCurrentView();</p><p>&nbsp;&nbsp;// 修改视图 <br/>&nbsp;&nbsp;view.setWidth(view.width() / scale); <br/>&nbsp;&nbsp;view.setHeight(view.height() / scale);<br/>&nbsp;&nbsp;// 更新视图 <br/>&nbsp;&nbsp;acedSetCurrentView(&amp;view, NULL); <br/>&nbsp;}<br/></p>

zhang007 发表于 2009-10-7 23:31:00

<p>加上一句</p><p>acdbHostApplicationServices()-&gt;workingDatabase()-&gt;updateExt(TRUE);</p>

pengxuan 发表于 2009-10-8 15:50:00

<p>可是加在什么位置呢,我试了好几个地方,还是一样的中断:</p><p>致命错误:Unhandled Access Voliation Reading 0x0004 Exception at 64576927h</p><p>还劳烦楼上相告,谢谢</p><p></p>

zhang007 发表于 2009-10-10 13:04:00

&nbsp;&nbsp;acedSetCurrentView(&amp;view, NULL); <br/>acdbHostApplicationServices()-&gt;workingDatabase()-&gt;updateExt(TRUE);

pengxuan 发表于 2009-10-11 10:44:00

谢谢楼上关注,我又试了一下,让人郁闷的是还是失败了——难道是设置有问题?

梦幻神话 发表于 2009-10-12 16:35:00

<p>根据2点缩放窗口的代码,与你比例因素缩放一个道理,可以参考下。</p><p>void Zoom(AcGePoint3d pt1, AcGePoint3d pt2)<br/>{<br/>&nbsp;&nbsp;&nbsp; AcDbViewTableRecord view; <br/>&nbsp;&nbsp;&nbsp;&nbsp; struct resbuf rb; <br/>&nbsp;&nbsp;&nbsp;&nbsp; struct resbuf wcs, dcs, ccs;&nbsp;&nbsp;&nbsp;&nbsp; // ads_trans coord system flags <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_point vpDir; <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_point wmin, wmax;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // min and max corners of the zoom window <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_point wdcsmax, wdcsmin;&nbsp; // windows corners in device coords <br/>&nbsp;&nbsp;&nbsp;&nbsp; AcGeVector3d viewDir; <br/>&nbsp;&nbsp;&nbsp;&nbsp; AcGePoint2d cenPt; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_real lenslength,viewtwist,frontz,backz; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_point target; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; int viewmode,tilemode,cvport; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // Get window to zoom to: </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_point pt3 = {pt1.x,pt1.y,pt1.z}, pt4 = {pt2.x,pt2.y,pt2.z}; </p><p><br/>&nbsp;&nbsp;&nbsp;&nbsp; // sort window corners to upper right and lower left <br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; if (pt3 &gt;= pt4) <br/>&nbsp;&nbsp;&nbsp;&nbsp; { <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmax = pt3; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmin = pt4; <br/>&nbsp;&nbsp;&nbsp;&nbsp; } <br/>&nbsp;&nbsp;&nbsp;&nbsp; else <br/>&nbsp;&nbsp;&nbsp;&nbsp; { <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmax = pt4; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmin = pt3; <br/>&nbsp;&nbsp;&nbsp;&nbsp; } </p><p>&nbsp;&nbsp;&nbsp;&nbsp; if (pt3 &gt;= pt4) <br/>&nbsp;&nbsp;&nbsp;&nbsp; { <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmax = pt3; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmin = pt4; <br/>&nbsp;&nbsp;&nbsp;&nbsp; } <br/>&nbsp;&nbsp;&nbsp;&nbsp; else <br/>&nbsp;&nbsp;&nbsp;&nbsp; { <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmax = pt4; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wmin = pt3; <br/>&nbsp;&nbsp;&nbsp;&nbsp; } </p><p>&nbsp;&nbsp;&nbsp;&nbsp; wmax = 0.0; <br/>&nbsp;&nbsp;&nbsp;&nbsp; wmin = 0.0; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; wcs.restype&nbsp;&nbsp;&nbsp;&nbsp; = RTSHORT;&nbsp;&nbsp;&nbsp;&nbsp; // WORLD coord system flag <br/>&nbsp;&nbsp;&nbsp;&nbsp; wcs.resval.rint = 0; <br/>&nbsp;&nbsp;&nbsp;&nbsp; ccs.restype&nbsp;&nbsp;&nbsp;&nbsp; = RTSHORT;&nbsp;&nbsp;&nbsp;&nbsp; // CURRENT coord system flag <br/>&nbsp;&nbsp;&nbsp;&nbsp; ccs.resval.rint = 1; <br/>&nbsp;&nbsp;&nbsp;&nbsp; dcs.restype&nbsp;&nbsp;&nbsp;&nbsp; = RTSHORT;&nbsp;&nbsp;&nbsp;&nbsp; // DEVICE coord system flag <br/>&nbsp;&nbsp;&nbsp;&nbsp; dcs.resval.rint = 2; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // Get the 'VPOINT' direction vector <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("VIEWDIR", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_trans(rb.resval.rpoint, &amp;ccs, &amp;wcs, 0, vpDir); <br/>&nbsp;&nbsp;&nbsp;&nbsp; viewDir.set(vpDir, vpDir, vpDir); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // convert upper right window corner to DCS <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_trans(wmax, &amp;ccs, &amp;dcs, 0, wdcsmax); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // convert lower left window corner to DCS <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_trans(wmin, &amp;ccs, &amp;dcs, 0, wdcsmin); <br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; // calculate and set view center point <br/>&nbsp;&nbsp;&nbsp;&nbsp; cenPt.set(wdcsmin + ((wdcsmax - wdcsmin) / 2.0), <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wdcsmin + ((wdcsmax - wdcsmin) / 2.0) ); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setCenterPoint(cenPt); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // set view height and width and direction <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setHeight(fabs(wdcsmax - wdcsmin)); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setWidth(fabs(wdcsmax - wdcsmin)); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setViewDirection(viewDir); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // get and set other properties <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("LENSLENGTH", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; lenslength = rb.resval.rreal; <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setLensLength(lenslength); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("VIEWTWIST", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; viewtwist = rb.resval.rreal; <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setViewTwist(viewtwist); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("FRONTZ", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; frontz = rb.resval.rreal; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("BACKZ", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; backz = rb.resval.rreal; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("VIEWMODE", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; viewmode = rb.resval.rint; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; view.setPerspectiveEnabled(viewmode &amp; 1); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setFrontClipEnabled(viewmode &amp; 2); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setBackClipEnabled(viewmode &amp; 4); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setFrontClipAtEye(!(viewmode &amp; 16)); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("TILEMODE", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; tilemode = rb.resval.rint; <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("CVPORT", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; cvport = rb.resval.rint; </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // Paperspace flag <br/>&nbsp;&nbsp;&nbsp;&nbsp; Adesk::Boolean paperspace = <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((tilemode == 0) &amp;&amp; (cvport == 1)) ? Adesk::kTrue : Adesk::kFalse; <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setIsPaperspaceView(paperspace); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; if (Adesk::kFalse == paperspace) <br/>&nbsp;&nbsp;&nbsp;&nbsp; { <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view.setFrontClipDistance(frontz); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view.setBackClipDistance(backz); <br/>&nbsp;&nbsp;&nbsp;&nbsp; } <br/>&nbsp;&nbsp;&nbsp;&nbsp; else <br/>&nbsp;&nbsp;&nbsp;&nbsp; { <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view.setFrontClipDistance(0.0); <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; view.setBackClipDistance(0.0); <br/>&nbsp;&nbsp;&nbsp;&nbsp; } <br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_getvar("TARGET", &amp;rb); <br/>&nbsp;&nbsp;&nbsp;&nbsp; ads_trans(rb.resval.rpoint, &amp;ccs, &amp;wcs, 0, target); <br/>&nbsp;&nbsp;&nbsp;&nbsp; view.setTarget(AcGePoint3d(target, target, target)); </p><p>&nbsp;&nbsp;&nbsp;&nbsp; // update view <br/>&nbsp;&nbsp;&nbsp;&nbsp; acedSetCurrentView( &amp;view, NULL ); <br/>}<br/></p>

pengxuan 发表于 2009-10-14 21:44:00

<p>嗯,可以,谢谢梦幻神话</p>

842986480 发表于 2011-12-13 17:06:16

顶顶顶顶顶顶

springwillow 发表于 2016-2-27 22:57:42

我也遇到了这个问题,梦幻神话 的方法是在同一个函数中解决了问题,我是将view做了全局变更解决的,应该是一个意思,想不明白的就是view值为什么不能传递,甚至连传址都不行。

vladimirputin 发表于 2016-10-25 18:36:36

不错的资料, 谢谢楼主分享啊。
页: [1]
查看完整版本: [求助]GetCurrentView()的执行中断?