Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing color of IfcBuildingElementProxy #552

Open
wojtpl opened this issue Mar 18, 2024 · 4 comments
Open

Changing color of IfcBuildingElementProxy #552

wojtpl opened this issue Mar 18, 2024 · 4 comments

Comments

@wojtpl
Copy link

wojtpl commented Mar 18, 2024

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");

}
@martin1cerny
Copy link
Member

It is what it says - invalid assignment. Style should not be assigned to an instance of the building element, but to its geometrical representation items. You need to drill down to element.Representation.Representations.Items to find the items you want to style:
IfcStyledItem

@andyward
Copy link
Member

Backing up a bit

It's probably worth checking what you're hoping to do here in terms of a use case. This code is amending the styling of a representation of an item in a model. If you save and re-open the IFC file it will should have changed to orange. But it won't change instantly. If you just wanted to highlight the element in real-time this would probably be the wrong approach.

i.e. 2 use cases:

  1. the client wants to permanently change all the walls to be orange in the handover model - satisfied by this approach
  2. Highlight in orange all elements that meet some external criteria - not satisfied by this approach There are better ways but we would need to know your use case & UI tech choices.

@wojtpl
Copy link
Author

wojtpl commented Mar 19, 2024

The idea is that I have a drawing program, which can generate IFC but I guess no color representation. I want to write c# standalone app to create copy (modyfied) IFC with IFCBuildingElementProxy named i.e. "Beam, Column, Plate" and then assign color to geometry name to make my IFC easier to read. I am static engineer, not professional programmer. But i guess I have to get deeper in IFC structure. If you know any sources where I can improve my skill please send a link and wish me luck :)

@martin1cerny
Copy link
Member

So, you want to create a kind-off analytical view of the IFC? When you say it can generate IFC, is that your code, already written using the Toolkit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants