OSArch Community

IfcOpenShell: Code example not working

  1. L
  2. T

    Without seeing the code, it's hard to troubleshoot.

    I've attached a similar working example. Perhaps that will help catch what was wrong.

  3. C

    How can I retrieve classification of an element?

    Maybe something like this?

    
    def get_classification_code(self, context, ifcproduct, ifc_version):
    
    
    
            #Classifications of an object may be referenced from an external source rather than being
    
            #contained within the IFC model. This is done through the IfcClassificationReference class.
    
            #ClassificationRefForObjects', 
    
    
    
            assembly_code_list = []
    
    
            if ifcproduct.HasAssociations:
    
    
    
                if ifcproduct.HasAssociations[0].is_a() == 'IfcRelAssociatesClassification':
    
    
    
                    if ifcproduct.HasAssociations[0].RelatingClassification:
    
    
    
                        #for IFC2x3
    
                        if ifc_version == 'IFC2X3':
    
                            if ifcproduct.HasAssociations[0].RelatingClassification.ItemReference:
    
                                assembly_code_list.append(ifcproduct.HasAssociations[0].RelatingClassification.ItemReference)
    
    
    
                        #for IFC4 
    
                        if ifc_version == 'IFC4':
    
                            if ifcproduct.HasAssociations[0].RelatingClassification.Identification:
    
                                assembly_code_list.append(ifcproduct.HasAssociations[0].RelatingClassification.Identification)
    
    
    
                if ifcproduct.HasAssociations[0].is_a() == 'IfcRelAssociatesMaterial':
    
    
    
                    for i in ifcproduct.HasAssociations:
    
                        if i.is_a() == 'IfcRelAssociatesClassification':
    
    
    
                            #for IFC2x3
    
                            if ifc_version == 'IFC2X3':
    
                                if i.RelatingClassification.ItemReference:
    
                                    assembly_code_list.append(i.RelatingClassification.ItemReference)
    
    
    
                            #for IFC4     
    
                            if ifc_version == 'IFC4':
    
                                if i.RelatingClassification:
    
                                    assembly_code_list.append(i.RelatingClassification.Identification)
    

    No module named 'ifcopenshell.util.attribute

    I don't know about that module, maybe @Moult has better ideas then my code.

  4. M
  5. L

    I'm wondering if ifcopenshell.util.classification should also work in regular Python (without Blender?)

    At the moment I can import ifcopenshell to Python but can not import ifcopenshell.util.classification

  6. M

    Yes, it should work without Blender. Almost everything in ifcopenshell can be used without Blender. How did you install ifcopenshell? It sounds like an installation issue.

  7. L

    I installed with cmd using "pip install ifcopenshell"

  8. L

    Uninstalling ifcopenshell and then installing from zip file worked. Thank you

  9. C

    @Coen said:

    How can I retrieve classification of an element?

    Maybe something like this?

    def get_classification_code(self, context, ifcproduct, ifc_version):

        #Classifications of an object may be referenced from an external source rather than being
        #contained within the IFC model. This is done through the IfcClassificationReference class.
        #ClassificationRefForObjects', 
        assembly_code_list = []
        if ifcproduct.HasAssociations:
            if ifcproduct.HasAssociations[0].is_a() == 'IfcRelAssociatesClassification':
                if ifcproduct.HasAssociations[0].RelatingClassification:
                    #for IFC2x3
                    if ifc_version == 'IFC2X3':
                        if ifcproduct.HasAssociations[0].RelatingClassification.ItemReference:
                            assembly_code_list.append(ifcproduct.HasAssociations[0].RelatingClassification.ItemReference)
                    #for IFC4 
                    if ifc_version == 'IFC4':
                        if ifcproduct.HasAssociations[0].RelatingClassification.Identification:
                            assembly_code_list.append(ifcproduct.HasAssociations[0].RelatingClassification.Identification)
            if ifcproduct.HasAssociations[0].is_a() == 'IfcRelAssociatesMaterial':
                for i in ifcproduct.HasAssociations:
                    if i.is_a() == 'IfcRelAssociatesClassification':
                        #for IFC2x3
                        if ifc_version == 'IFC2X3':
                            if i.RelatingClassification.ItemReference:
                                assembly_code_list.append(i.RelatingClassification.ItemReference)
                        #for IFC4     
                        if ifc_version == 'IFC4':
                            if i.RelatingClassification:
                                assembly_code_list.append(i.RelatingClassification.Identification)

    No module named 'ifcopenshell.util.attribute

    I don't know about that module, maybe @Moult has better ideas then my code.

    Or something like this. An object can contain multiple classifications. Only tested for IFC2X3TC1

     def get_classifications(element) -> list:
    
            """Get classification code (ItemReference)."""
    
            classifications = []
    
            for association in element.HasAssociations:
    
                if association.is_a("IfcRelAssociatesClassification"):
    
                    item_reference = association.RelatingClassification.ItemReference
    
                    classifications.append(str(item_reference))
    
            return classifications
  10. C

    Or something like this. An object can contain multiple classifications. Only tested for IFC2X3TC1

     def get_classifications(element) -> list:
    
            """Get classification code (ItemReference)."""
    
            classifications = []
    
            for association in element.HasAssociations:
    
                if association.is_a("IfcRelAssociatesClassification"):
    
                    item_reference = association.RelatingClassification.ItemReference
    
                    classifications.append(str(item_reference))
    
            return classifications
  11. D

Login or Register to reply.