I was successful enough to add a new wall (IfcWallStandardCase) to an existing IFC model and display it in the DrawingControl3D - with the help from Proper Wall 3D sample from XBim Toolkit, here's my code of adding colour to the wall:
//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);
Now I'm trying to change the color of that wall upon a button click using how the style (colour) was added in the first place, here's my attempt to do it:
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();
}
I get the named "IfcStyledItem" via name query, and traverse to it's "SurfaceStyle" to replace the "ColourRGB" that was set before, then reload the DrawingControl3D model. But not successful.
I've been looking around the net how to do this properly but couldn't find any. Any leads on how to achieve this is very much appreciated.