guliande 发表于 2010-6-22 17:10:00

[求助]如何获得CAD视图的左下角和右上角的坐标(ObjectARX)

<font face="Verdana">比如在cad上画了很多图形,然后绘图过程中会用到很多次缩放.我的目标是给一个命令,可以让所有的图形摆放到界面的中心,并且比例合适。<br/>所以,要首先获得所有图形的左下角和右上角的坐标,请问高手如何做到那,谢谢。PS我现在用的是ObjectARX 2007</font>

rongyifei 发表于 2010-6-22 19:00:00

这个简单,让我帮你写一个!

rongyifei 发表于 2010-6-22 19:52:00

<p><font face="Verdana">static void ROYMyTest_Test2(void)<br/>&nbsp;{<br/>&nbsp;&nbsp;// Add your code for command ROYMyTest._Test2 here<br/>&nbsp;&nbsp;ads_name ssName;<br/>&nbsp;&nbsp;long ssLength;<br/>&nbsp;&nbsp;if (acedSSGet(_T("A"),NULL,NULL,NULL,ssName)!=RTNORM<br/>&nbsp;&nbsp;&nbsp;|| acedSSLength(ssName,&amp;ssLength)!=RTNORM)<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;AcDbObjectId EntID;<br/>&nbsp;&nbsp;ads_name eName;<br/>&nbsp;&nbsp;AcDbEntity *pEnt;<br/>&nbsp;&nbsp;AcDbExtents extent;<br/>&nbsp;&nbsp;AcGePoint3d MaxPt,MinPt;<br/>&nbsp;&nbsp;Adesk::Boolean isFirstSet=Adesk::kTrue;<br/>&nbsp;&nbsp;for (long i=0;i&lt;ssLength;i++)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;if (acedSSName(ssName,i,eName)!=RTNORM<br/>&nbsp;&nbsp;&nbsp;&nbsp;|| acdbGetObjectId(EntID,eName)!=Acad::eOk<br/>&nbsp;&nbsp;&nbsp;&nbsp;|| acdbOpenAcDbEntity(pEnt,EntID,AcDb::kForRead)!=Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;&nbsp;continue;<br/>&nbsp;&nbsp;&nbsp;if (pEnt-&gt;getGeomExtents(extent)!=Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;continue;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;if (isFirstSet)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;MaxPt=extent.maxPoint();<br/>&nbsp;&nbsp;&nbsp;&nbsp;MinPt=extent.minPoint();<br/>&nbsp;&nbsp;&nbsp;&nbsp;isFirstSet=Adesk::kFalse;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (MaxPt.x&lt;extent.maxPoint().x)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxPt.x=extent.maxPoint().x;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (MaxPt.y&lt;extent.maxPoint().y)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxPt.y=extent.maxPoint().y;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (extent.minPoint().x&lt;MinPt.x)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MinPt.x=extent.minPoint().x;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (extent.minPoint().y&lt;MinPt.y)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MinPt.y=extent.minPoint().y;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;acedSSFree(ssName);</font></p>
<p><font face="Verdana">&nbsp;&nbsp;acedCommand(RTSTR,_T("ZOOM"),<br/>&nbsp;&nbsp;&nbsp;RTSTR,_T("W"),<br/>&nbsp;&nbsp;&nbsp;RTPOINT,asDblArray(MinPt),<br/>&nbsp;&nbsp;&nbsp;RTPOINT,asDblArray(MaxPt),<br/>&nbsp;&nbsp;&nbsp;RTNONE);<br/>&nbsp;}</font></p>

rongyifei 发表于 2010-6-22 19:53:00

以上代码仅适用于CAD2008,仅作参考!

guliande 发表于 2010-6-23 11:17:00

<p>rongyifei 兄,谢谢啦,我拿回去钻研一下。</p>

guliande 发表于 2010-6-23 11:18:00

加你为好友,多向你学习。

rongyifei 发表于 2010-6-25 21:39:00

QQ:<font face="Verdana">1258433045</font>,有空聊聊!

BDYCAD 发表于 2010-6-28 10:15:00

<p>已阅!</p>

why1025 发表于 2014-12-13 01:13:05

rongyifei 发表于 2010-6-22 19:52 static/image/common/back.gif
static void ROYMyTest_Test2(void)&nbsp;{&nbsp;&nbsp;// Add your code for command ROYMyTest._Test2 he ...

HAO好!!!!!!!!!!!!!!!
页: [1]
查看完整版本: [求助]如何获得CAD视图的左下角和右上角的坐标(ObjectARX)