huangjianzhe 发表于 2008-6-21 13:15:00

这个程序谁帮我测一下阿

<p>在CAD里可以加载,但是输入命令之后CAD就弹出窗口说致命错误,我是初学者,谢谢你们了</p><p>.cpp文件</p><p>//包含头文件<br/>#include "stdafx.h"<br/>#include &lt;string.h&gt;<br/>#include &lt;aced.h&gt;<br/>#include &lt;dbents.h&gt;<br/>#include &lt;dbsymtb.h&gt;<br/>#include &lt;dbgroup.h&gt;<br/>#include &lt;dbapserv.h&gt;<br/>#include &lt;dbid.h&gt;<br/>#include &lt;gepnt3d.h &gt;<br/>#include &lt;rxdlinkr.h &gt;<br/>#include &lt;rxregsvc.h&gt; <br/>//函数声明<br/>AcDbObjectId createNewLine();<br/>AcDbObjectId createNewCricle();<br/>AcDbObjectId createNewLayer();<br/>void createNewGroup();<br/>Acad::ErrorStatus changeColor(AcDbObjectId,Adesk::UInt16);<br/>//创建直线对象,并返回对象ID<br/>AcDbObjectId createNewLine()<br/>{<br/>//定义直线起点,终点<br/>AcGePoint3d ptStart(5, 4, 0);<br/>AcGePoint3d ptEnd(15, 10, 0);<br/>AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);<br/>// 获得指向块表的指针<br/>AcDbBlockTable *pBlockTable;<br/>acdbHostApplicationServices()-&gt;workingDatabase()<br/>-&gt;getSymbolTable(pBlockTable, AcDb::kForRead);<br/>// 获得指向特定的块表记录(模型空间)的指针<br/>AcDbBlockTableRecord *pBlockTableRecord;<br/>pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<br/>AcDb::kForWrite);<br/>// 将AcDbLine类的对象添加到块表记录中<br/>AcDbObjectId lineId;<br/>pBlockTableRecord-&gt;appendAcDbEntity(lineId, pLine);<br/>// 关闭图形数据库的各种对象<br/>pBlockTable-&gt;close();<br/>pBlockTableRecord-&gt;close();<br/>pLine-&gt;close();<br/>return lineId;<br/>}<br/>AcDbObjectId createNewCricle()<br/>{<br/>AcGePoint3d center(10.0, 7.0, 0.0);<br/>AcGeVector3d normal(0.0, 0.0, 5.0);<br/>AcDbCircle *pCirc = new AcDbCircle(center, normal,4.5);<br/>// 获得指向块表的指针<br/>AcDbBlockTable *pBlockTable;<br/>acdbHostApplicationServices()-&gt;workingDatabase()<br/>-&gt;getSymbolTable(pBlockTable, AcDb::kForRead);<br/>// 获得指向特定的块表记录(模型空间)的指针<br/>AcDbBlockTableRecord *pBlockTableRecord;<br/>pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<br/>AcDb::kForWrite);<br/>// 将AcDbLine类的对象添加到块表记录中<br/>AcDbObjectId circleId;<br/>pBlockTableRecord-&gt;appendAcDbEntity(circleId, pCirc);<br/>// 关闭图形数据库的各种对象<br/>pBlockTable-&gt;close();<br/>pBlockTableRecord-&gt;close();<br/>pCirc-&gt;close();<br/>return circleId;<br/>}</p><p>AcDbObjectId createNewLayer()<br/>{</p><p>AcDbLayerTable *pLayerTable;<br/>acdbHostApplicationServices()-&gt;workingDatabase()<br/>-&gt;getSymbolTable(pLayerTable, AcDb::kForWrite);<br/>// 获得指向特定的块表记录(模型空间)的指针<br/>AcDbLayerTableRecord *pLayerTableRecord;<br/>pLayerTableRecord-&gt;setName("MYNewLayer");<br/>//层表记录的其他属性(例如颜色,线形等)若未设置都取缺省值<br/>//如:颜色为white,线形为Continous等<br/>//将新建的层表记录添加到层表中<br/>//并将表层记录的ID保存到pLayerId作为函数的返回值<br/>AcDbObjectId pLayerId;<br/>pLayerTable-&gt;add(pLayerId,pLayerTableRecord);<br/>//关闭层表和层表记录对象<br/>pLayerTable-&gt;close();<br/>pLayerTableRecord-&gt;close();<br/>//返回新建层表记录对象的ID<br/>return pLayerId;<br/>}<br/>void createNewGroup(AcDbObjectIdArray&amp; objIds,char* pGroupName,AcDbObjectId PlayerId)<br/>{<br/>//初始化数组对象实例,以参数pGroupName为数组名<br/>AcDbGroup *pGroup=new AcDbGroup(pGroupName);<br/>//向组对象中加入实体<br/>for(int i=0 ;i&lt;objIds.length();i++)<br/>{<br/>&nbsp;pGroup-&gt;append(objIds);<br/>}<br/>//打开组词典 (存放于对象词典中)<br/>AcDbDictionary *pGroupDict;<br/>acdbHostApplicationServices()-&gt;workingDatabase()<br/>-&gt;getGroupDictionary(pGroupDict, AcDb::kForWrite);<br/>//将新建的组词典条目加入到组词典中<br/>AcDbObjectId pGroupId;<br/>pGroupDict-&gt;setAt(pGroupName,pGroup,pGroupId);<br/>//将组pGroup的层属性修改为pLayerId所代表的层<br/>pGroup-&gt;setLayer(pGroupId);<br/>pGroupDict-&gt;close();<br/>pGroup-&gt;close();<br/>}<br/>//修改实体对象颜色,并返回一个状态码<br/>Acad::ErrorStatus<br/>changeColor(AcDbObjectId endId,Adesk::UInt16 newColor)<br/>{<br/>//定义一个实体对象,并利用参数entId打开这个实体对象<br/>&nbsp;AcDbEntity *pEntity;<br/>&nbsp;acdbOpenObject(pEntity,endId,AcDb::kForWrite);<br/>&nbsp;//修改实体对象的颜色<br/>&nbsp;pEntity-&gt;setColorIndex(newColor);<br/>&nbsp;//关闭实体对象<br/>&nbsp;pEntity-&gt;close();<br/>&nbsp;//返回Acad::eOk, 对于有容错处理的程序,可能在函数当中就返回另外的状态码<br/>&nbsp;return Acad::eOk;<br/>}<br/>//命令MakeNewEnts的执行函数<br/>void runIt()<br/>{<br/>//新建图层<br/>&nbsp;AcDbObjectId newLayerId=createNewLayer();<br/>&nbsp;//定义一个对象ID序列idArray<br/>&nbsp;AcDbObjectIdArray idArray;<br/>&nbsp;&nbsp;//创建一条直线和一个圆<br/>&nbsp;&nbsp;//将新建的直线,圆对象加入idArray中<br/>&nbsp;idArray.append(createNewLine());<br/>&nbsp;idArray.append(createNewCricle());<br/>&nbsp;//由于新建的两个对象均在0层,他们的缺省颜色值为ByLayer<br/>&nbsp;//将直线对象的颜色改为红色(1)<br/>&nbsp;//将圆对象的颜色改为绿色(3)<br/>&nbsp;changeColor(idArray.first(),1);<br/>&nbsp;changeColor(idArray.last(),3);<br/>&nbsp;//将直线和圆对象放到组"MyNewGroup"中,<br/>&nbsp;//并将组的层属性改为"MyNewGroup"层,<br/>&nbsp;//组中的两个实体对象的层属性也相应的改为"MyNewGroup"层<br/>&nbsp;//创建新层的函数也可以写成带名称参数<br/>&nbsp;createNewGroup(idArray,"MyNewGroup",newLayerId);</p><p>}<br/>//初始化函数<br/>void initApp()<br/>{<br/>acedRegCmds-&gt;addCommand("ASDK_MAKE-ENTITIES",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ASDK_MakeNewEnts",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"MakeNewEnts",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ACRX_CMD_MODAL,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;runIt);<br/>}<br/>void unloadApp()<br/>{<br/>acedRegCmds-&gt;removeGroup("ASDK_MAKE_ENTITIES");<br/>}<br/>//应用程序主函数<br/>extern "C" AcRx::AppRetCode<br/>acrxEntryPoint(AcRx::AppMsgCode msg,void *appId)<br/>{<br/>switch(msg)<br/>{<br/>case AcRx::kInitAppMsg:<br/>&nbsp;&nbsp;acrxDynamicLinker-&gt;unlockApplication(appId);<br/>&nbsp;&nbsp;acrxDynamicLinker-&gt;registerAppMDIAware(appId);<br/>&nbsp;&nbsp;initApp();<br/>&nbsp;&nbsp;break;<br/>case AcRx::kUnloadAppMsg:<br/>&nbsp;&nbsp;&nbsp;unloadApp();<br/>}<br/>return AcRx::kRetOK;<br/>}</p><p>.def文件</p><p><br/>LIBRARY&nbsp;line<br/>EXPORTS<br/>acrxEntryPoint PRIVATE<br/>acrxGetApiVersion PRIVATE<br/></p>

alfalfa 发表于 2008-6-21 16:20:00

应该是:AcDbLayerTableRecord *pLayerTableRecord=new AcDbLayerTableRecord;

huangjianzhe 发表于 2008-6-23 08:18:00

谢谢你了,你在哪,请你吃饭
页: [1]
查看完整版本: 这个程序谁帮我测一下阿