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