tongtong 发表于 2006-10-27 16:18:00

[ARX]如何把一幅图像中所有的图形颜色变成白色

<P>如题</P>

tongtong 发表于 2006-10-27 16:26:00

Acad::ErrorStatus changeColor(AcDbObjectId entId,Adesk::UInt16 newColor)<BR>{<BR>&nbsp;&nbsp; //打开对象,用于编辑<BR>&nbsp;&nbsp; AcDbEntity *pEntity;<BR>&nbsp;&nbsp; acdbOpenObject(pEntity,entId,AcDb::kForWrite);<BR>&nbsp;&nbsp; //设置新的颜色<BR>&nbsp;&nbsp; pEntity-&gt;setColorIndex(newColor);<BR>&nbsp;&nbsp; pEntity-&gt;close;<BR>&nbsp;&nbsp; return Acad::eOk;<BR>}<BR>改变一个实体的颜色如上图所示,改变全部的呢?

HuaiYu 发表于 2006-10-27 20:24:00

本帖最后由 作者 于 2006-10-27 22:29:49 编辑 <br /><br /> <P>要对 AcDbBlockTableRecord 中的 ACDB_MODEL_SPACE进行遍历啊</P>
<P>void TEST()<BR>{<BR>&nbsp;// TODO: Implement the command<BR>&nbsp;//&nbsp;假设 newColor=1(红色)<BR>&nbsp;int newColor=1;<BR>&nbsp;//&nbsp;取 模型空间=pMS<BR>&nbsp;AcDbBlockTable *pBlockTable;<BR>&nbsp;Acad::ErrorStatus es;<BR>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getSymbolTable(pBlockTable,AcDb::kForRead);<BR>&nbsp;AcDbBlockTableRecord *pMS;<BR>&nbsp;pBlockTable-&gt;getAt(ACDB_MODEL_SPACE,pMS,AcDb::kForRead);<BR>&nbsp;pBlockTable-&gt;close();</P>
<P>&nbsp;//&nbsp;新建迭代器<BR>&nbsp;AcDbBlockTableRecordIterator *pIter=NULL;<BR>&nbsp;pMS-&gt;newIterator(pIter);<BR>&nbsp;if (pIter==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;acutPrintf("\n** Error on the newIterator...");<BR>&nbsp;&nbsp;pMS-&gt;close();<BR>&nbsp;&nbsp;return;<BR>&nbsp;}<BR>&nbsp;//&nbsp;遍历迭代器中的 Entity 来 改变颜色<BR>&nbsp;for(pIter-&gt;start();!pIter-&gt;done();pIter-&gt;step())<BR>&nbsp;{<BR>&nbsp;&nbsp;acutPrintf("\n****");<BR>&nbsp;&nbsp;AcDbEntity *pEnt=NULL;<BR>&nbsp;&nbsp;//&nbsp;得到 Entity=pEnt 为 读<BR>&nbsp;&nbsp;pIter-&gt;getEntity(pEnt,AcDb::kForRead);<BR>&nbsp;&nbsp;if(pIter==NULL)<BR>&nbsp;&nbsp;&nbsp;continue;<BR>&nbsp;&nbsp;//&nbsp;将状态 升级<BR>&nbsp;&nbsp;if(pEnt-&gt;upgradeOpen()!=Acad::eOk)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;acutPrintf("\n** one object can't upgradeOpen");<BR>&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<BR>&nbsp;&nbsp;&nbsp;continue;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;//&nbsp;改变颜色<BR>&nbsp;&nbsp;es=pEnt-&gt;setColorIndex(newColor);<BR>&nbsp;&nbsp;if(es!=Acad::eOk)<BR>&nbsp;&nbsp;&nbsp;acutPrintf("\none object can't change the color");<BR>&nbsp;&nbsp;pEnt-&gt;close();<BR>&nbsp;}</P>
<P>&nbsp;delete pIter;<BR>&nbsp;pMS-&gt;close();<BR>}<BR></P>

tongtong 发表于 2006-10-29 20:23:00

<P>谢谢楼上的兄弟</P>

wzz1968 发表于 2006-10-31 09:48:00

<P>更简单的方法是用AcedCommandh函数调用AUTOCAD的change命令.</P>
<P>&nbsp;</P>

tongtong 发表于 2006-11-4 13:33:00

<P>楼上的兄弟能给个代码看吗?</P>

wrw830820 发表于 2012-10-15 10:45:28

这不是全选就可以了吗?
页: [1]
查看完整版本: [ARX]如何把一幅图像中所有的图形颜色变成白色