ship120 发表于 2009-2-20 20:43:00

[求助]还是创建图层的问题

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

easypower 发表于 2009-2-20 21:31:00

<p>你在CreatLayer函数中</p><p>acdbHostApplicationServices()-&gt;workingDatabase()<br/>&nbsp;&nbsp;-&gt;getLayerTable(pLayerTbl, AcDb::kForWrite);<br/></p><p>而在你外面调用</p><p>acdbHostApplicationServices()-&gt;workingDatabase()<br/>&nbsp;&nbsp;-&gt;getLayerTable(pLayerTbl, AcDb::kForRead);</p><p>当然要崩溃!</p><p>你创建之间的判断可以放到函数里面去判断</p>

ship120 发表于 2009-2-20 22:05:00

<p>嗯&nbsp; 我按你说的把 判断 放在 CreateLayer 里面了</p><p>AcDbObjectId CCreateEnt::CreatLayer (char layername,int nNewColor,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int Weight,char linetype)<br/>{</p><p>&nbsp;// 获得当前图形的层表<br/>&nbsp;AcDbLayerTable *pLayerTbl;<br/>&nbsp;&nbsp;AcDbObjectId layerTblRcdId;<br/>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<br/>&nbsp;&nbsp;-&gt;getLayerTable(pLayerTbl, AcDb::kForWrite);<br/>&nbsp;if &nbsp;((pLayerTbl-&gt;getAt(layername,layerTblRcdId))!=Acad::eOk)&nbsp;<br/>&nbsp;{<br/>&nbsp;<br/>&nbsp;// 创建新的层表记录<br/>&nbsp;&nbsp;AcDbObjectId layerTblRcdId;<br/>&nbsp;&nbsp;AcDbLayerTableRecord *pLayerTblRcd;<br/>&nbsp;&nbsp;pLayerTblRcd = new AcDbLayerTableRecord();</p><p>&nbsp;&nbsp;pLayerTblRcd-&gt;setName(layername);<br/>&nbsp;&nbsp;AcCmColor color;<br/>&nbsp;&nbsp;color.setColorIndex(nNewColor);<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;setColor(color);<br/>&nbsp;&nbsp;AcDb::LineWeight lineWeight =(AcDb::LineWeight)Weight;<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;setLineWeight(lineWeight);</p><p>&nbsp;&nbsp;AcDbLinetypeTable *pLinetypeTbl;<br/>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<br/>&nbsp;&nbsp;-&gt;getLinetypeTable(pLinetypeTbl, AcDb::kForWrite);<br/>&nbsp;&nbsp;AcDbObjectId linetypeId;<br/>&nbsp;&nbsp;pLinetypeTbl-&gt;getAt(linetype, linetypeId);<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;setLinetypeObjectId(linetypeId);<br/>&nbsp;&nbsp;pLinetypeTbl-&gt;close();<br/>&nbsp;</p><p>&nbsp;&nbsp;// 将新建的层表记录添加到层表中<br/>&nbsp;<br/>&nbsp;&nbsp;pLayerTbl-&gt;add(layerTblRcdId, pLayerTblRcd);</p><p>&nbsp;&nbsp;pLayerTbl-&gt;close();<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;close();<br/>&nbsp;&nbsp;acutPrintf("\n图层创建成功!");</p><p>&nbsp;&nbsp;return layerTblRcdId;<br/>&nbsp;&nbsp;}else{<br/>&nbsp;&nbsp;acutPrintf("\n图层以创建!");}<br/>}</p><p>但编译时 有这么个 警告&nbsp; warning C4715: “CCreateEnt::CreatLayer” : 不是所有的控件路径都返回值。</p><p>会对程序造成影响么?</p>

ship120 发表于 2009-2-20 22:33:00

<p>嗯&nbsp; 这次 彻底解决了 谢谢!</p><p>AcDbObjectId CCreateEnt::CreatLayer (char layername,int nNewColor,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int Weight,char linetype)<br/>{</p><p>&nbsp;// 获得当前图形的层表<br/>&nbsp;AcDbLayerTable *pLayerTbl;<br/>&nbsp;&nbsp;AcDbObjectId layerTblRcdId;<br/>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<br/>&nbsp;&nbsp;-&gt;getLayerTable(pLayerTbl, AcDb::kForWrite);<br/>&nbsp;if &nbsp;((pLayerTbl-&gt;getAt(layername,layerTblRcdId))!=Acad::eOk)&nbsp;<br/>&nbsp;{<br/>&nbsp;<br/>&nbsp;// 创建新的层表记录<br/>&nbsp;&nbsp;AcDbObjectId layerTblRcdId;<br/>&nbsp;&nbsp;AcDbLayerTableRecord *pLayerTblRcd;<br/>&nbsp;&nbsp;pLayerTblRcd = new AcDbLayerTableRecord();</p><p>&nbsp;&nbsp;pLayerTblRcd-&gt;setName(layername);<br/>&nbsp;&nbsp;AcCmColor color;<br/>&nbsp;&nbsp;color.setColorIndex(nNewColor);<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;setColor(color);<br/>&nbsp;&nbsp;AcDb::LineWeight lineWeight =(AcDb::LineWeight)Weight;<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;setLineWeight(lineWeight);</p><p>&nbsp;&nbsp;AcDbLinetypeTable *pLinetypeTbl;<br/>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<br/>&nbsp;&nbsp;-&gt;getLinetypeTable(pLinetypeTbl, AcDb::kForWrite);<br/>&nbsp;&nbsp;AcDbObjectId linetypeId;<br/>&nbsp;&nbsp;pLinetypeTbl-&gt;getAt(linetype, linetypeId);<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;setLinetypeObjectId(linetypeId);<br/>&nbsp;&nbsp;pLinetypeTbl-&gt;close();<br/>&nbsp;</p><p>&nbsp;&nbsp;// 将新建的层表记录添加到层表中<br/>&nbsp;<br/>&nbsp;&nbsp;pLayerTbl-&gt;add(layerTblRcdId, pLayerTblRcd);</p><p>&nbsp;&nbsp;pLayerTbl-&gt;close();<br/>&nbsp;&nbsp;pLayerTblRcd-&gt;close();<br/>&nbsp;&nbsp;acutPrintf("\n [%s层] 创建成功!",layername);</p><p>&nbsp;&nbsp;return layerTblRcdId;<br/>&nbsp;&nbsp;}else{<br/>&nbsp;&nbsp;&nbsp;AcDbObjectId layerTblRcdId;<br/>&nbsp;&nbsp;&nbsp;pLayerTbl-&gt;getAt(layername,layerTblRcdId);<br/>&nbsp;&nbsp;&nbsp;return&nbsp; layerTblRcdId;<br/>&nbsp;&nbsp;&nbsp;acutPrintf("\n [%s层] 以创建!",layername);<br/>&nbsp;&nbsp;}<br/>}</p><p>生成:1 已成功, 0 已失败, 0 已跳过</p>
页: [1]
查看完整版本: [求助]还是创建图层的问题