我在编写创建图层时遇到了一个匪夷所思的问题,和大家分享一下,希望能有高手帮忙解决! 另外 我初学ARX 希望大家多指点! 这是我编写的创建图层的函数,放在自己添加的 CCreateEnt 类中 AcDbObjectId CCreateEnt::CreatLayer (char layername[100],int nNewColor, int Weight,char linetype[50]) { // 获得当前图形的层表 AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getLayerTable(pLayerTbl, AcDb::kForWrite); // 创建新的层表记录 AcDbObjectId layerTblRcdId; AcDbLayerTableRecord *pLayerTblRcd; pLayerTblRcd = new AcDbLayerTableRecord(); pLayerTblRcd->setName(layername); AcCmColor color; color.setColorIndex(nNewColor); pLayerTblRcd->setColor(color); AcDb:ineWeight lineWeight =(AcDb:ineWeight)Weight; pLayerTblRcd->setLineWeight(lineWeight); AcDbLinetypeTable *pLinetypeTbl; acdbHostApplicationServices()->workingDatabase() ->getLinetypeTable(pLinetypeTbl, AcDb::kForWrite); AcDbObjectId linetypeId; pLinetypeTbl->getAt(linetype, linetypeId); pLayerTblRcd->setLinetypeObjectId(linetypeId); pLinetypeTbl->close(); // 将新建的层表记录添加到层表中 pLayerTbl->add(layerTblRcdId, pLayerTblRcd); pLayerTbl->close(); pLayerTblRcd->close(); return layerTblRcdId; } 以下是我在acrxEnryPoint 中调用的 函数: static void ShipMyrun(void) { // Add your code for command ShipMy.run here char name1[]="中心线"; char name2[]="虚线"; char name3[]="粗实线"; char linetype1[]="CENTER"; char linetype2[]="DASHED"; char linetype3[]="Continuous"; AcDbLayerTable *pLayerTbl; AcDbObjectId layerTblRcdId; acdbHostApplicationServices()->workingDatabase() ->getLayerTable(pLayerTbl, AcDb::kForRead); if ((pLayerTbl->getAt(name1,layerTblRcdId))!=Acad::eOk) { CCreateEnt::CreatLayer(name1,1,0,linetype1); }else{ acutPrintf("\n图层以创建!");} if ((pLayerTbl->getAt(name2,layerTblRcdId))!=Acad::eOk) { CCreateEnt::CreatLayer(name2,50,0,linetype2); }else{ acutPrintf("\n图层以创建!");} if ((pLayerTbl->getAt(name3,layerTblRcdId))!=Acad::eOk) { CCreateEnt::CreatLayer(name3,100,30,linetype3); }else{ acutPrintf("\n图层以创建!");} acutPrintf("\n创建图层任务已完成!"); pLayerTbl->close(); } 编译没有问题,但在CAD中无法运行,导致CAD致命错误。而且我试过了: static void ShipMyrun(void) { // Add your code for command ShipMy.run here char name1[]="中心线"; char name2[]="虚线"; char name3[]="粗实线"; char linetype1[]="CENTER"; char linetype2[]="DASHED"; char linetype3[]="Continuous"; //AcDbLayerTable *pLayerTbl; //AcDbObjectId layerTblRcdId; //acdbHostApplicationServices()->workingDatabase() //->getLayerTable(pLayerTbl, AcDb::kForRead); //if ((pLayerTbl->getAt(name1,layerTblRcdId))!=Acad::eOk) //{ CCreateEnt::CreatLayer(name1,1,0,linetype1); //}else{ //acutPrintf("\n图层以创建!");} //if ((pLayerTbl->getAt(name2,layerTblRcdId))!=Acad::eOk) //{ CCreateEnt::CreatLayer(name2,50,0,linetype2); //}else{ //acutPrintf("\n图层以创建!");} //if ((pLayerTbl->getAt(name3,layerTblRcdId))!=Acad::eOk) //{ CCreateEnt::CreatLayer(name3,100,30,linetype3); //}else{ //acutPrintf("\n图层以创建!");} //acutPrintf("\n创建图层任务已完成!"); //pLayerTbl->close(); } 注释掉 判断语句后 却可以正确执行,另外我也试过 注释掉 创建图层的函数 加一条输出字符 函数,也运行成功了, 这使我我感到匪夷所思,请哪位高手指点一下! static void ShipMyrun(void) { // Add your code for command ShipMy.run here char name1[]="中心线"; char name2[]="虚线"; char name3[]="粗实线"; char linetype1[]="CENTER"; char linetype2[]="DASHED"; char linetype3[]="Continuous"; AcDbLayerTable *pLayerTbl; AcDbObjectId layerTblRcdId; acdbHostApplicationServices()->workingDatabase() ->getLayerTable(pLayerTbl, AcDb::kForRead); if ((pLayerTbl->getAt(name1,layerTblRcdId))!=Acad::eOk) { //CCreateEnt::CreatLayer(name1,1,0,linetype1); acutPrintf("\n图层以创建!"); }else{ acutPrintf("\n图层以创建!");} if ((pLayerTbl->getAt(name2,layerTblRcdId))!=Acad::eOk) { //CCreateEnt::CreatLayer(name2,50,0,linetype2); acutPrintf("\n图层以创建!"); }else{ acutPrintf("\n图层以创建!");} if ((pLayerTbl->getAt(name3,layerTblRcdId))!=Acad::eOk) { //CCreateEnt::CreatLayer(name3,100,30,linetype3); acutPrintf("\n图层以创建!"); }else{ acutPrintf("\n图层以创建!");} acutPrintf("\n创建图层任务已完成!"); pLayerTbl->close(); } |