acedCommand实现缩放到对象

转载:http://objectarx.net/home.php?mod=space&uid=20326&do=index

缩放以便尽可能大地显示一个或多个选定的对象并使其位于视图的中心

经过实验,发现该选项可以缩放任意的图形(所有基本cad图形以及自定义实体),即使自定义实体没有重载实现

virtual Acad::ErrorStatus subGetGeomExtents(AcDbExtents& extents) const;

也可以进行缩放。
注1:猜测原因可能是cad绘制图形的时候,在内部记录了图形的一些基本要素(点,线等)
注2:在arx和com接口中都提供了zoomWindow()和zoomExtents(),却没有提供“缩放到对象”的接口

尝试使用acedCommand实现对任意实体的”对象缩放“,代码片段如下:

void ZoomToEntity(const AcDbObjectId& objId)

{

        ads_name en;

        if(Acad::eOk != acdbGetAdsName(en, objId)) return;

        acedCommand(RTSTR, _T(“ZOOM”), RTSTR, _T(“O”), RTENAME, en, RTSTR, _T(“”), 0);

}

复制代码

注1:参数中的空字符串_T(“”)等价于按空格键(相当于取消继续选择对象)
注2:如果不希望在acedCommand执行的过程中,出现命令执行过程提示,可以设置cad系统变量CMDECHO等于0
注3:下面的2段引用文字来源于acedCommand命令帮助说明

An empty string (“”) or null string is equivalent to a space entered from the keyboard.

 

If the AutoCAD system variable CMDECHO is set to 0, the data sent by acedCommand() is not displayed; otherwise, the command and its input values are echoed at the AutoCAD Command prompt

【问题】
acedCommand函数不能用于非模态对话框(modeless dialog),详情参考:
arxdoc.chm->Developer’s Guide->Advanced Topics->The Multiple Document Interface->Application Execution Context->Code Differences under the Application Execution Context

如果有哪位高手知道其它的方法,欢迎回复~~

此条目发表在ObjectArx分类目录,贴了标签。将固定链接加入收藏夹。

发表评论