XbimEssentials icon indicating copy to clipboard operation
XbimEssentials copied to clipboard

Changing color of IfcBuildingElementProxy

Open wojtpl opened this issue 3 months ago • 4 comments

I want to set color to my existing ifc file by element name. I stucked on " Cannot implicitly convert type 'Xbim.Ifc2x3.ProductExtension.IfcBuildingElementProxy' to 'Xbim.Ifc2x3.GeometryResource.IfcRepresentationItem' " Please give me a clue or an example how should I fix it.

using (var model = IfcStore.Open(fileName))
{

    var element = model.Instances.FirstOrDefault<IfcBuildingElementProxy>();

    //add color to the proper
    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 = "MyStale";
    newStyledItem.Item = element;   //Here something is wrong.
    newStyledItem.Styles.Add(newStyleAssignment);

    

    using (var txn = model.BeginTransaction(""))
    {


       element.Name = "SomeName";



        txn.Commit();
    }




    model.SaveAs(fileName + "_mod.ifc");

}

wojtpl avatar Mar 18 '24 15:03 wojtpl