tongtong 发表于 2007-2-2 11:28:00

批量把所有图层放入到0层

如何批量把所有的图层放入到0层并进行CAD中的“pu”命令

tongtong 发表于 2007-2-3 18:26:00

<p>删除一个图层上的所有实体是用如下代码的,那么放在0层是怎么操作的呢</p><p>void lcdlg::delSS(char* nLayerName,AcDbObjectIdArray&amp; nIDs)<br/>{<br/>&nbsp;//AfxMessageBox(nLayerName);<br/>&nbsp;Acad::ErrorStatus es = Acad::eOk;<br/>&nbsp;ads_name ents;<br/>&nbsp;struct resbuf *rb;<br/>&nbsp;rb=acutNewRb(AcDb::kDxfLayerName);<br/>&nbsp;rb-&gt;restype=8;<br/>&nbsp;rb-&gt;resval.rstring=(char*)nLayerName;<br/>&nbsp;rb-&gt;rbnext=NULL;<br/>&nbsp;acedSSGet("X",NULL,NULL,rb,ents);<br/>&nbsp;long entNums=0;<br/>&nbsp;acedSSLength(ents,&amp;entNums);<br/>&nbsp;if (entNums == 0)<br/>&nbsp;&nbsp;es = Acad::eInvalidInput;<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;for (long a = 0; a &lt; entNums ; a ++)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;AcDbObjectId&nbsp; objId;<br/>&nbsp;&nbsp;&nbsp;ads_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ent;<br/>&nbsp;&nbsp;&nbsp;AcDbObject* obj;<br/>&nbsp;&nbsp;&nbsp;acedSSName(ents,a,ent);<br/>&nbsp;&nbsp;&nbsp;acdbGetObjectId(objId, ent);<br/>&nbsp;&nbsp;&nbsp;acdbOpenObject((AcDbObject *&amp;) obj,objId,AcDb::kForWrite);<br/>&nbsp;&nbsp;&nbsp;nIDs.append(objId);<br/>&nbsp;&nbsp;&nbsp;obj-&gt;erase();<br/>&nbsp;&nbsp;&nbsp;nIDs.append(objId);<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;acedSSFree(ents);<br/>&nbsp;acutRelRb(rb);<br/>}<br/></p>

tongtong 发表于 2007-2-6 20:52:00

<p>我将上面代码做了如下修改,没有提示错误,但是没有执行。有人帮忙看下吗?</p><p>void lcdlg::delSS(char* nLayerName,AcDbObjectIdArray&amp; nIDs)<br/>{<br/>&nbsp;//AfxMessageBox(nLayerName);<br/>&nbsp;Acad::ErrorStatus es = Acad::eOk;<br/>&nbsp;ads_name ents;<br/>&nbsp;struct resbuf *rb;</p><p>&nbsp;rb=acutNewRb(AcDb::kDxfLayerName);<br/>&nbsp;rb-&gt;restype=8;<br/>&nbsp;rb-&gt;resval.rstring=(char*)nLayerName;<br/>&nbsp;rb-&gt;rbnext=NULL;<br/>&nbsp;acedSSGet("X",NULL,NULL,rb,ents);<br/>&nbsp;long entNums=0;<br/>&nbsp;acedSSLength(ents,&amp;entNums);<br/>&nbsp;if (entNums == 0)<br/>&nbsp;&nbsp;es = Acad::eInvalidInput;<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;for (long a = 0; a &lt; entNums ; a ++)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;AcDbObjectId&nbsp; objId;<br/>&nbsp;&nbsp;&nbsp;ads_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ent;<br/>&nbsp;&nbsp;&nbsp;AcDbObject* obj;<br/>&nbsp;&nbsp;&nbsp;AcDbEntity *pE;<br/>&nbsp;&nbsp;&nbsp;acedSSName(ents,a,ent);<br/>&nbsp;&nbsp;&nbsp;acdbGetObjectId(objId, ent);<br/>&nbsp;&nbsp;&nbsp;acdbOpenObject(pE,objId,AcDb::kForWrite,false);<br/>&nbsp;&nbsp;//&nbsp;nIDs.append(objId);<br/>&nbsp;&nbsp;&nbsp;pE-&gt;setLayer("0");<br/>&nbsp;&nbsp;&nbsp;pE-&gt;close;<br/>&nbsp;&nbsp;//&nbsp;nIDs.append(objId);<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;acedSSFree(ents);<br/>&nbsp;acutRelRb(rb);<br/>}</p>

tongtong 发表于 2007-2-7 20:15:00

<p>人呢,没有人回答下的吗?</p>

fpiw 发表于 2007-2-8 09:41:00

看代码好像应该没什么问题啊,看一下你所选的图层是不是一个锁定的图层,锁定图层上的对象是不允许修改的

fpiw 发表于 2007-2-8 09:51:00

本帖最后由 作者 于 2007-2-8 9:54:39 编辑 <br /><br /> void DelSS(const char *sLay)<br/>{<br/>&nbsp;ads_name ss;<br/>&nbsp;struct resbuf *rb=acutBuildList(8,sLay,NULL);<br/>&nbsp;long nLen=0;<br/>&nbsp;if(acedSSGet("X",NULL,NULL,rb,ss)!=RTNORM)<br/>&nbsp;{<br/>&nbsp;&nbsp;acutRelRb(rb);<br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;&nbsp;acutRelRb(rb);<br/><br/>&nbsp;acedSSLength(ss,&amp;nLen);<br/>&nbsp;for(long n=0L;n&lt;nLen;n++)<br/>&nbsp;{<br/>&nbsp;&nbsp;ads_name ent;<br/>&nbsp;&nbsp;acedSSName(ss,n,ent);<br/>&nbsp;&nbsp;AcDbObjectId idEnt;<br/>&nbsp;&nbsp;acdbGetObjectId(idEnt,ent);<br/>&nbsp;&nbsp;AcDbEntity *pEnt=NULL;<br/>&nbsp;&nbsp;if(acdbOpenObject(pEnt,idEnt,AcDb::kForWrite)==Acad::eOk)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pEnt-&gt;setLayer("0");<br/>&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;acedSSFree(ss);<br/>}

tongtong 发表于 2007-2-8 20:21:00

<p>为什么还是不行呢</p><p>void lcdlg::delSS(char* nLayerName,AcDbObjectIdArray&amp; nIDs)<br/>{<br/>&nbsp;Acad::ErrorStatus es = Acad::eOk;<br/>&nbsp;ads_name ents;<br/>&nbsp;struct resbuf *rb;<br/>&nbsp;struct resbuf blc;<br/>&nbsp;AcDbEntity *pE;</p><p>&nbsp;rb=acutNewRb(AcDb::kDxfLayerName);<br/>&nbsp;rb-&gt;restype=8;<br/>&nbsp;rb-&gt;resval.rstring=(char*)nLayerName;<br/>&nbsp;rb-&gt;rbnext=NULL;<br/>&nbsp;acedSSGet("X",NULL,NULL,rb,ents);</p><p>//&nbsp;long entNums=0;<br/>&nbsp;long entNums;</p><p>&nbsp;acedSSLength(ents,&amp;entNums);<br/>&nbsp;if (entNums == 0)<br/>&nbsp;&nbsp;es = Acad::eInvalidInput;<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;for (long a = 0; a &lt; entNums ; a ++)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;AcDbObjectId&nbsp; objId;<br/>&nbsp;&nbsp;&nbsp;ads_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ent;<br/>&nbsp;&nbsp;&nbsp;AcDbObject* obj;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;acedSSName(ents,a,ent);<br/>&nbsp;&nbsp;&nbsp;acdbGetObjectId(objId, ent);<br/>&nbsp;&nbsp;&nbsp;acdbOpenObject(pE,objId,AcDb::kForWrite,false);<br/>&nbsp;&nbsp;&nbsp;nIDs.append(objId);</p><p>&nbsp;&nbsp;&nbsp;pE-&gt;setLayer("0");<br/>&nbsp;&nbsp;&nbsp;pE-&gt;close;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj-&gt;close;<br/>&nbsp;&nbsp;&nbsp;nIDs.append(objId);<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;acedSSFree(ents);<br/>&nbsp;blc.restype = RTSTR;<br/>&nbsp;&nbsp;&nbsp; blc.resval.rstring = "0";<br/>&nbsp;&nbsp;&nbsp; acedSetVar("CLAYER",&amp;blc);//设置当前图层为0层&nbsp; </p><p>&nbsp;AcDbLayerTable * pLayerTbl;//定义层表指针<br/>&nbsp;&nbsp;&nbsp; acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getSymbolTable(pLayerTbl, AcDb::kForWrite);<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; AcDbLayerTableRecord * pLayerTblRcd; //定义层表记录指针<br/>&nbsp;&nbsp;&nbsp; if ( Acad::eOk == pLayerTbl-&gt;getAt((char*)nLayerName, pLayerTblRcd , AcDb::kForWrite))<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;erase(true);//删除图层<br/>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;close(); <br/>&nbsp;&nbsp;&nbsp; pLayerTbl-&gt;close();<br/>&nbsp;&nbsp;&nbsp; acutRelRb(rb);<br/>}</p>

tongtong 发表于 2007-2-8 20:46:00

<p>按照上面的方法没有出任何错误,但是也没有执行任何操作,包括最后最后从层表中删除图层也没有执行,为什么呢</p>

fpiw 发表于 2007-2-9 12:30:00

<p>前面给你的代码是可以的啊,我试过了</p><p>但是不能应用于被锁定的层,锁定的层是不允许修改的</p>

老牛 发表于 2007-2-9 12:41:00

<p>我按照你的代码试过了,结果是可以改变图层的。看来你不能从代码找问题了,可能是别的问题。</p>
页: [1] 2
查看完整版本: 批量把所有图层放入到0层