我成功地将新墙 (IfcWallStandardCase) 添加到现有 IFC 模型并在 DrawingControl3D 中显示 - 在XBim Toolkit 的Proper Wall 3D示例的帮助下,这是我为墙添加颜色的代码:
//add color to the proper wall
var orange = model.Instances.New<IfcColourRgb>();
orange.Red = (255.0 / 255.0);
orange.Green = (69.0 / 255.0);
orange.Blue = (0.0 / 255.0);
var newStyleRendering = model.Instances.New<IfcSurfaceStyleRendering>();
newStyleRendering.SurfaceColour = orange;
var newSurfaceStyle = model.Instances.New<IfcSurfaceStyle>();
newSurfaceStyle.Styles.Add(newStyleRendering);
var newStyleAssignment = model.Instances.New<IfcPresentationStyleAssignment>();
newStyleAssignment.Styles.Add(newSurfaceStyle);
var newStyledItem = model.Instances.New<IfcStyledItem>();
newStyledItem.Name = "Standard Wall Styling";
newStyledItem.Item = body;
newStyledItem.Styles.Add(newStyleAssignment);
现在,我尝试使用最初添加样式(颜色)的方式在单击按钮时更改那面墙的颜色,这是我的尝试:
var walls = model.Instances.OfType<IfcStyledItem>();
var _newWall = walls.Where(w => w.Name == "Standard Wall Styling").FirstOrDefault();
if (_newWall != null)
{
var newColour = model.Instances.New<IfcColourRgb>();
newColour.Red = (24 / 255.0);
newColour.Green = (24 / 255.0);
newColour.Blue = (24 / 255.0);
var newStyleRendering = model.Instances.New<IfcSurfaceStyleRendering>();
newStyleRendering.SurfaceColour = newColour;
_newWall.Styles[0].SurfaceStyles.FirstOrDefault().Styles.Clear();
_newWall.Styles[0].SurfaceStyles.FirstOrDefault().Styles.Add(newStyleRendering);
txn.Commit();
DrawingControl.ReloadModel();
}
我通过名称查询得到名为“IfcStyledItem”,并遍历它的“SurfaceStyle”来替换之前设置的“ColourRGB”,然后重新加载DrawingControl3D模型。但并不成功。
我一直在网上寻找如何正确执行此操作,但找不到任何内容。非常感谢任何有关如何实现这一目标的线索。