如何在 WPF 中正确更改 XBim 标准墙的颜色



我成功地将新墙(IfcWallStandardCase(添加到现有的IFC模型中,并将其显示在DrawingControl3D中 - 在XBim工具包的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"以替换之前设置的"ColorRGB",然后重新加载DrawingControl3D模型。但没有成功。

我一直在网上寻找如何正确执行此操作,但找不到任何内容。 非常感谢有关如何实现这一目标的任何线索。

好的,为此,您需要为墙的IfcExtrudedAreaSolid分配一个新IfcSurfaceStyle。下面的代码适用于 Revit 2018 中的正确墙 3D 示例和 ifc 导出。

private bool AddNewSurfaceStyle(IfcBuildingElement element)
{
var representations = element.Representation.Representations;
if (representations.Count == 0) return false;
var body = representations.FirstOrDefault(a => a.RepresentationType == "SweptSolid");
if (body == null) return false;
var extrudedAreaSolid = body.Items.FirstOrDefault(a => a is IIfcExtrudedAreaSolid);
if (extrudedAreaSolid == null) return false;
var elementStyle = extrudedAreaSolid.StyledByItem.FirstOrDefault();
using (var txn = element.Model.BeginTransaction("Create Style"))
{
var styleAssignment = element.Model.Instances.New<IfcPresentationStyleAssignment>();
var surfaceStyle = element.Model.Instances.New<IfcSurfaceStyle>();
var surfaceStyleRedering = element.Model.Instances.New<IfcSurfaceStyleRendering>();
var colourRGB = element.Model.Instances.New<IfcColourRgb>();
colourRGB.Blue = 1;
colourRGB.Red = 1;
colourRGB.Green = 0;
surfaceStyleRedering.Transparency = 0;
surfaceStyleRedering.SurfaceColour = colourRGB;
surfaceStyle.Styles.Add(surfaceStyleRedering);
styleAssignment.Styles.Add(surfaceStyle);
elementStyle.Styles.Clear();
elementStyle.Styles.Add(styleAssignment);
txn.Commit();
}
return true;
}

相关内容

  • 没有找到相关文章

最新更新