[IfcOpenShell] obj2ifc.py / file.create_entity() - Doesn't work with IfcElementType?

edited November 2022 in General

Hello,

I'm working on a project to generate IfcElementTypes from Obj files using IfcOpenShell.

Using the obj2ifc (meshlab) version works for me to create IfcElement instances (IfcFurniture for example) but when I try to create an IfcElementType (like IfcFurnitureType), I get the following error:

Traceback (most recent call last):
  File "C:\Users\vince\Desktop\test\obj2ifc-meshlab.py", line 157, in <module>
    obj2ifc.execute()
  File "C:\Users\vince\Desktop\test\obj2ifc-meshlab.py", line 80, in execute
    product = self.file.create_entity(
  File "C:\Users\vince\anaconda3\lib\site-packages\ifcopenshell\file.py", line 284, in create_entity
    e[idx] = arg
  File "C:\Users\vince\anaconda3\lib\site-packages\ifcopenshell\entity_instance.py", line 218, in __setitem__
    method = self.method_list[idx]
IndexError: list index out of range

I suspect it's because either the "create_entity" function doesn't work for IfcElementTypes only for "instances" or that I'm not providing the correct additional arguments to the function.

Any insight on this @Moult ?

Thanks!

Comments

  • If you just replaced "IfcBuildingElementProxy" on L81 with an IfcElementType, it won't work because it's assigning attributes that exist on IfcBuildingElementProxy but don't exist on types. For example, types don't have an ObjectPlacement and nor do they have a Representation.

    Here is a slightly more agnostic implementation:

    ifc_class = "IfcBuildingElementProxy" # Or a type will work too
    product = ifcopenshell.api.run("root.create_entity", self.file, ifc_class=ifc_class, name=mesh.label() or self.basename)
    if product.is_a("IfcProduct"):
        product.ObjectPlacement = self.placement
    ifcopenshell.api.run("geometry.assign_representation", self.file, product=product, representation=representation)
    
    vinnividivicci
  • Added [IfcOpenShell] to the post name so people can more easily see what posts they could be interested in reading

  • Thanks for the response guys, I'll give it a try.

Sign In or Register to comment.