Hello everyone,
I am working on parking components in REVIT which are exported as instances of the IfcBuildingElementProxy class. We computed some new attributes and functions for these component with help of IfcOpenShell and wondered if we could add these new attributes to the object's built-in attributes (like Name, GuId, Type, etc.).
If we try to build a new class that can assign these new attributes to our objects, the built-in attributes of the ifc class wont be available except in case that the new class inherits from the object's very first ifc class.
Is there a way to introduce the ifc classes to our .py code and define some child classes for them which is able to produce instances that are more enhanced?
thanks
Last edit: Faez Amiri 2021-08-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Currently there isn't a mechanism for that. Suppose you subclass from ifcopenshell.entity_instance. Add such an instance to the file and later retrieve that instance from the file or through a relationship from another instance. The object you get returned would be a regular ifcopenshell.entity_instance and not your embellished class.
I don't fully understand what you're aiming to do. Is this just for readability of the code or is there some more intricate functionality you're envisioning.
One thing you could do is not use subclassing but composition:
Hi,
thanks for your help, I tried and it helped.
the reason I wanted to do such a thing was for code readability as you said. I am implementing this in a code checking module and makes it more structured; also the properties computed in one module could be easily accessible in another module just by calling the instances of the custom class.
Last edit: Faez Amiri 2021-08-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
I am working on parking components in REVIT which are exported as instances of the IfcBuildingElementProxy class. We computed some new attributes and functions for these component with help of IfcOpenShell and wondered if we could add these new attributes to the object's built-in attributes (like Name, GuId, Type, etc.).
If we try to build a new class that can assign these new attributes to our objects, the built-in attributes of the ifc class wont be available except in case that the new class inherits from the object's very first ifc class.
Is there a way to introduce the ifc classes to our .py code and define some child classes for them which is able to produce instances that are more enhanced?
thanks
Last edit: Faez Amiri 2021-08-18
Currently there isn't a mechanism for that. Suppose you subclass from ifcopenshell.entity_instance. Add such an instance to the file and later retrieve that instance from the file or through a relationship from another instance. The object you get returned would be a regular ifcopenshell.entity_instance and not your embellished class.
I don't fully understand what you're aiming to do. Is this just for readability of the code or is there some more intricate functionality you're envisioning.
One thing you could do is not use subclassing but composition:
By means of the dynamic attribute lookup getattr you'd be able to use the new
area
property as well as the IFC attributes on instances of this class.Hi,
thanks for your help, I tried and it helped.
the reason I wanted to do such a thing was for code readability as you said. I am implementing this in a code checking module and makes it more structured; also the properties computed in one module could be easily accessible in another module just by calling the instances of the custom class.
Last edit: Faez Amiri 2021-08-25