[IfcOpenShell-Python] How do I change the color from an ifc entity?
Hi all
so here i have a simple cube in an ifc file.
When i open it in an ifc-viewer, the cube is gray like in the image above in the spoiler tag.
So how can i change the color from this cube with ifcopenshell-python?
Thanks for the reply :)
Comments
Hey @Martin156131, I don't know how to do it with just IfcOpenShell, but with Blenderbim that would be about changing the IfcStyle:
Here's a thread with the same request:
https://community.osarch.org/discussion/comment/8780/#Comment_8780
You change the colour in the viewport display tab and then click update IFCstyle to save it
Here is a red ifc cube for example:
Thanks for the feedback!
So it is possible to change the color, however I search the method how to do it in python.
Because i am trying to write a script to make from different obj files one ifc file, so it could be nice when the different ifc entity have a different color, instead having all uniformly gray shading.
If I look at your cube Ifc written out vs the red one you need to include these elements:
I don't code so my usefulness ends here
@Martin156131
You could try this code snippet, I copied it from @brunopostle
There are two ways for an object to receive a colour: 1) its geometry could directly have a style, or 2) it can be associated with a material, and that material can have a style. @Coen's code snippet shows the latter. The former, however, is more appropriate for your usecase as you don't have any materials it seems.
Thank you all for your awesome help!
The jupyternotebook code, that i used:
My yellow cube ?:
@Coen Thanks for the snippet ! Just as a heads up AFAIK unless you're working with HDR images you should not set the color channels with values > 1.0, the result may not be physically correct or may be clamped by the software you'll open it in. For instance Blender technically supports RGB channels with values > 1 (you have to type it in the fields since the slider doesn't let you) but I'm not sure how it will be handled by other softs. Cheers :)
I am a bit confused why this happens, I've made an IfcWallType instance and added to a project with this script:
Creates a beautiful red wall




Now when I open the BIM tool in BlenderBIM, and want to add another IfcWallType instance, this happens:
When trying to save the project Blender crashes, when I remove the colours I just get a grey colour and BlenderBIM works
When I open the project in BIM Vision I see this:
My aim is to create a library of different coloured WallType instances.
This is the line where BIMVision claims there is an error
Some further experimenting, when I use this for assigning a colour:
Instead of this like my previous post:
It creates also a colour, and when I try to add an IfcWallType instance it preserves the colour:

However I am unable to open it in BIMVision, BIM Vision gives this log:
When I try to save the IFC project when adding another wall I get this weird error when I ran Blender form the command prompt:
Don't understand why the IfcWallType instance suddenly is transparant and why it crashes :(
Even when I remove all the style lines and the
load_ifc_automaticaly
method, then manullay loading it in Blender. Like so:Then, I close Blender, open it in BIMVision:



Opening it in BlenderBIM
Then trying to add a wall, this works, when when trying to Miter join with Shift+Y or Shift+T
I get this crash
I can replicate your problem.
That's all i got. ;)
At least it's excluded it's not some funny add-on on my end which is causing this :-)
When I use python to create an IfcProjectLibrary instead of IfProject and load them into BlenderBIM, everything works fine. Just wondering how I would use python to load IFC files from the IfcProjectLibrary automatically.