马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
我们知道,CAD里面是没有命令可以将3DSOLID每个面设置不同的颜色的,我们可以通过ACBR API做到。
使用ACBRAPI,遍历每个面(FACE),然后通过子实体路径的子实体ID设置每个面的颜色
下面是ARX代码:
[C++] 纯文本查看 复制代码
void TestBrep(void)
{
Adesk::Int32 len;
ads_name ssname0;
struct resbuf *buffer;
buffer = acutBuildList(-4, _T("<AND"),
RTDXF0, _T("3DSOLID"),
-4, _T("AND>"), RTNONE);
acutPrintf(_T("\nSelect a box:"));
acedSSGet(NULL, NULL, NULL, buffer, ssname0);
acutRelRb(buffer);
if (RTNORM == acedSSLength(ssname0, &len))
{
ads_name ent;
AcDbObjectId entId;
for(long k = 0; k < len; k++)
{
acedSSName(ssname0, k, ent);
acdbGetObjectId(entId, ent);
settingDifferentColorToEachFace(entId);
}
acedSSFree(ssname0);
}
}
void settingDifferentColorToEachFace(AcDbObjectId solidId)
{
AcCmColor specialColor;
AcDb3dSolid* pSolid;
if (Acad::eOk == acdbOpenObject(pSolid, solidId, AcDb::kForRead))
{
AcDbFullSubentPath path(solidId, AcDbSubentId());
AcBrBrep brep;
AcBr::ErrorStatus bs = brep.setSubentPath(path);
if (bs != AcBr::eOk)
return;
//Initialize the BrepFace traverser
AcBrBrepFaceTraverser bft;
bs = bft.setBrep(brep);
if (bs != AcBr::eOk)
return;
AcArray<AcDbSubentId> arrSubentId;
// Traverse all faces
for (;!bft.done();bft.next())
{
AcBrFace face;
bs = bft.getFace(face);
if (bs != Acad::eOk)
{
acutPrintf(L"\ngetFace failed");
break;
}
AcDbFullSubentPath Path(kNullSubent);
AcDbSubentId subentId;
AcBr::ErrorStatus bss = face.getSubentPath(Path);
subentId = Path.subentId();
arrSubentId.append(subentId);
}
pSolid->upgradeOpen();
for (int i = 0; i < arrSubentId.length(); i++)
{
specialColor.setColorIndex(i);
pSolid->setSubentColor(arrSubentId[i],specialColor);
}
pSolid->downgradeOpen();
}
pSolid->close();
}
下面是XDRX API的AcBr库函数实现的LISP代码:
 - (defun c:tt ()
- (defun _traversface (e)
- (setq br (xdbr::constructor e))
- (setq tr (xdbr::constructor "brepfacetraverser" br))
- ;;FACE遍历
- (setq ids nil)
- (while (not (xdbr::traverser:done tr));遍历面
- (if (setq face (xdbr::getpropertyvalue tr "face"));获得当前遍历指针位置的面AcBrFace
- (progn (setq SubEntPath (xdbr::getpropertyvalue face "subentpath");获得面的子实体路径
- SubEntId (xdrx_getpropertyvalue SubEntPath "subentid");;获得子实体ID
- ids (cons SubEntId ids);保存到全局表
- )
- (xdrx_object_release SubEntPath);;释放子实体路径变量
- )
- )
- (xdbr::traverser:next tr);;遍历器指向下个位置
- )
- (xdrx_object_release tr br);;释放遍历器和BREP变量
- (setq i 0)
- (repeat (length ids);设置子实体面颜色
- (xdrx_setpropertyvalue
- e
- "subentcolor"
- (list (setq SubEntId (nth i ids)) (setq i (1+ i)))
- )
- (xdrx_object_release SubEntId);;释放子实体ID变量
- (xdrx_prompt
- (xdrx_string_format "\n - 面[%d]-颜色[%d]" i i)
- )
- ) ;
- )
- (if (setq e (car (xdrx_entsel "\n选取3DSOLID<退出>:" '((0 . "3DSOLID")))
- )
- )
- (progn (xdrx_begin) (_traversface e) (xdrx_end))
- )
- (princ)
- )
|