Creating a beam correctly with IfcOpenShell (missing material and color)

I'm trying to get the following example working:
It should create a beam, 140x360mm in a material GL30c (blue color)

I have the following code:

import ifcopenshell
import ifcopenshell.util.representation
import ifcopenshell.api
import os
import numpy as np

path = os.path.expanduser("~/Desktop")

model = ifcopenshell.open(
    f"{path}/empty.ifc"
)

body = ifcopenshell.util.representation.get_context(model, "Model", "Body", "MODEL_VIEW")

ifcopenshell.version
'0.7.10'

Material


material_gl30c = ifcopenshell.api.run( "material.add_material", model, name='GL30c', category='default' ) style = ifcopenshell.api.run( "style.add_style", model, name='GL30c') ifcopenshell.api.run( "style.add_surface_style", model, style=style, attributes={ # "SurfaceColour": color, "SurfaceColour": { "Name": 'None', "Red": 0*255, "Green": 0*255, "Blue": 1*255, }, }, ) ifcopenshell.api.run( "style.assign_material_style", model, material=material_gl30c, style=style, context=body, ) # add a pset to the material pset = ifcopenshell.api.pset.add_pset( model, product=material_gl30c, name="Pset_MaterialCommon", ) ifcopenshell.api.pset.edit_pset( model, pset=pset, properties={ 'MassDensity': 480, } )
Note: API not available due to missing dependencies: geometry.add_representation - No module named 'bpy'
Note: API not available due to missing dependencies: grid.create_axis_curve - No module named 'bpy'

Profile


profile = model.create_entity( "IfcRectangleProfileDef", ProfileName='140x360', ProfileType="AREA", XDim=140, YDim=360 ) profile_set = ifcopenshell.api.run( "material.add_material_set", model, name='140x360', set_type="IfcMaterialProfileSet" ) ifcopenshell.api.run( "material.add_profile", model, profile_set=profile_set, material=material_gl30c, profile=profile ) beam_type = ifcopenshell.api.run( "root.create_entity", model, ifc_class="IfcBeamType", name='140x360' ) ifcopenshell.api.run( "material.assign_material", model, products=[beam_type], material=profile_set )
#79=IfcRelAssociatesMaterial('3O3q_dRqPFXgHtGYa7NTl7',$,$,$,(#78),#76)

Create a beam


beam = ifcopenshell.api.run( "root.create_entity", model, ifc_class="IfcBeam", name = 'A beam', ) ifcopenshell.api.run( "geometry.edit_object_placement", model, product=beam ) ifcopenshell.api.run( "type.assign_type", model, related_objects=[beam], relating_type=beam_type ) body = ifcopenshell.util.representation.get_context(model, "Model", "Body", "MODEL_VIEW") profile = beam_type.HasAssociations[0].RelatingMaterial.MaterialProfiles[0].Profile representation = ifcopenshell.api.run( "geometry.add_profile_representation", model, context=body, profile=profile, depth=2.5, #length ) ifcopenshell.api.run("geometry.assign_representation", model, product=beam, representation=representation)
model.write(f"{path}/beam_test.ifc")

However, if i open it with the latest version of BlenderBim, material and color seems to be missing:

In Solibri, I also can't find any material of color.
In OpenIfcViewer nothing is showing.

Andrej730

Comments

  • No idea why other viewers doesn't show it but it was a bug in IfcOpenShell occurred in the process transitioning to IfcOpenShell v0.8.0. It is fixed now but will take a bit until we update build in BlenderBIM, you can track it on github - https://github.com/IfcOpenShell/IfcOpenShell/issues/5093

    Thank you for reporting this issue!

  • Most viewers (incorrectly) only display styles that are assigned via representation items and completely ignore styles that are assigned via materials. I recall some Revit for example had an even stranger quirk where it only worked with an older presentation style assginment entity which has been deprecated.

    Thanks for the report!

Sign In or Register to comment.