问题描述:
如图所示,有些三维实体从其他软件导入或者不同面有不同颜色设置的需求,一个三维实体有不同颜色的时候如何获取其颜色是个比较常见的问题。
步骤指引:
- 下面提供一段可选择独立单个面,并且获取颜色的示例代码如下:
void Test_GetFaceColorOfSolid()
{
ads_name ss;
const ACHAR* selectMode = _T("_:V:S:$");
LPCTSTR prompts[] = { _T("Pick a face:"), _T("") };
AcDb::SubentType subentType = AcDb::kFaceSubentType;
AcArray<AcDb::SubentType> subTypes;
subTypes.append(subentType);
acedSSSetSubentTypes(subTypes);
int nRet = acedSSGet(selectMode, prompts, nullptr, nullptr, ss);
if (nRet == RTNORM)
{
Adesk::Int32 nEnts = 0, nSubs = 0;
acedSSLength(ss, &nEnts);
for (int i = 0; i < nEnts; i++)
{
ads_name ent;
AcDbObjectId entId;
acedSSName(ss, i, ent);
acdbGetObjectId(entId, ent);
AcDbObjectPointer<AcDb3dSolid> solid(entId, AcDb::kForWrite);
if (solid.openStatus() != Acad::eOk) continue;
acedSSSubentLength(ss, i, &nSubs);
for (int j = 0; j < nSubs; j++)
{
AcDbFullSubentPath path;
acedSSSubentName(ss, i, j, path);
if (AcDb::kFaceSubentType == subentType)
{
// 设置颜色
//AcCmColor clr;
//clr.setColorIndex(1);
//Acad::ErrorStatus es = solid->setSubentColor(path.subentId(), clr);
//if (es != Acad::eOk)
// acutPrintf(_T("\nsetSubentColorerr:%d"), es);
// 获取颜色
AcCmColor clr;
Acad::ErrorStatus es = solid->getSubentColor(path.subentId(), clr);
if (es != Acad::eOk)
acutPrintf(_T("\ngetSubentColor error:%s"), acadErrorStatusText(es));
else
acutPrintf(_T("\nColorIndex of face:%d"), clr.colorIndex());
}
}
}
acedSSFree(ss);
}
}
拓展:
1.提供的方法是获取颜色,同样如果本身没有设置特殊颜色,可以通过注释的代码setSubentColor逐一设置颜色。
2.该方法同样适用于与曲面,只需将示例代码的AcDb3dSolid类名参数改为:AcDbSurface。
| 英文空间链接 |
|---|
★如何获取三维复杂实体单个子面的颜色?:https://confluence.zwcad.com/pages/viewpage.action?pageId=302515944
