对于 大多数 i.dgn文件可以正常获取对象颜色,但对于一些特别的i.dgn文件,不能获取到其在msce中显示的颜色,浏览过其他提问,(https://communities.bentley.com/communities/other_communities/chinafirst/f/microstation-projectwise/136282/thread?ReplySortBy=CreatedDate&ReplySortOrder=Ascending)
发现错误的材质都有材料,样式定义这些属性,请问有没有一种方法可以在msce中获取这类数据正确的颜色?
您试试用下面代码获取看看:
SymbologyReporter symbReporter(eh); UInt32 clrId, clrIdx; bool isTrueClr; WString bookName, clrName; double transparency; UInt index = 0; while (SUCCESS == symbReporter.GetColorID(clrId, index)) index++; index--; symbReporter.GetTransparency(transparency, index); if (COLOR_BYLEVEL == clrId) { LevelId lvlID; symbReporter.GetLevelId(lvlID, index); LevelCacheR lvlCache = eh.GetDgnModelP()->GetLevelCacheR(); LevelHandle lvlHandle = lvlCache.GetLevel(lvlID); clrId = lvlHandle.GetByLevelColor().GetColor(); } DgnColorMapP pClrMap = DgnColorMap::GetForDisplay(eh.GetDgnModelP()); IntColorDef clrDef = pClrMap->GetColor(clrId); pClrMap->ExtractElementColorInfo(&clrDef, &clrIdx, &isTrueClr, &bookName, &clrName, clrId, *eh.GetDgnFileP()); value["colors"].append((double)clrDef.m_rgb.red/255); value["colors"].append((double)clrDef.m_rgb.green/255); value["colors"].append((double)clrDef.m_rgb.blue/255); value["colors"].append(1.0 - transparency);
目前已找到错误颜色原因,是由于获取颜色时忽略了面材质导致的,多谢各位帮助!
总结一下:
1、在FacetOptions中不要将SetIgnoreFaceMaterialAttachment设置为true,应该设置为false。何为FaceMaterial?面材质。我们在对一个三维实体附材质时可以整体赋,也可以选中某个面赋,面材质优先于体材质,Attached的材质优先于Assigned的材质。其中的Attachment即表示该种材质是Attached而非Assigned。有关Attached和Assigned材质的解释参看如下文章:
附材质的两种方式
2、通过ElementGraphicsProcessor接口中的_AnnounceElemMatSymb传入的参数matSymb可正确获得元素的显示颜色。方法是:
UInt32 tbgr = matSymb->GetLineColorTBGR();
其中获得的tbgr就是transparency、blue、green和red四个字节组成的一个32位的无符号整型数。可以用C的移位操作获得每个分量的值。
Answer Verified By: jizhou lv