@Coen said:
Could you please share this python code? Highly interested in how to make IFC elements transparent with code.
There is more than one way to style an IFC Product (a Wall, Space etc..), @moult recently added a whole bunch of shader stuff that I haven't even looked at yet, so the below is how I have been doing it so far.
Typically you would create a Surface Style, assign it to a Material, and then assign the Material to the Product or Type Product you want to style, but in this case assigning a Material to a Space doesn't make much sense, so you may as well do it directly. The thing to remember is that you don't assign the style to the Product directly; a Product can have zero or more Shape Representations, so you assign it to one of these.
Ideally you loop through the Representations and style only those that have a RepresentationIdentifier of Body, but assuming there is only one Shape Representation for your Space, you can grab it like this:
my_shape_representation = my_space.Representation.Representations[0]
Create a Surface Style, file
is your IfcOpenShell model:
my_style = ifcopenshell.api.run("style.add_style", file, name="My Style")
..and give it a Surface Style Rendering (note that blenderbim can now do Surface Style Shading, which is much more sophisticated and has lots more bells and whistles):
ifcopenshell.api.run(
"style.add_surface_style",
file,
style=my_style,
attributes={
"SurfaceColour": {
"Name": "Orange",
"Red": 1.0,
"Green": 0.5,
"Blue": 0.0,
},
"Transparency": 0.5,
"ReflectanceMethod": "MATT",
},
)
(Note Transparency = 0.5 means that the shape is half transparent, 0.0 would be opaque, 1.0 would be invisible) All you have to do now is assign this Surface Style to your Shape Representation. If you are assigning this Surface Style to a Material, you use style.assign_material_style
instead:
ifcopenshell.api.run(
"style.assign_representation_styles",
file,
shape_representation=my_shape_representation,
styles=[my_style],
)
If you are doing this in blenderbim, this won't update in the viewport, I'm not really sure how to do this correctly. In the Homemaker add-on I just delete the Blender collection (along with all the blender 3D versions of your IFC elements) overwrite blenderbim.bim.ifc.IfcStore.file
with my file
and trigger ifc_importer.execute()
, it seems to work.