11import ifcopenshell
22import ifcopenshell .util .schema
33
4+
45class Usecase :
56 def __init__ (self , file , settings = None ):
67 self .file = file
@@ -14,13 +15,19 @@ def __init__(self, file, settings=None):
1415
1516 def execute (self ):
1617 relating_classification = None
18+
19+ if hasattr (self .settings ["reference" ], "ItemReference" ):
20+ identification = self .settings ["reference" ].ItemReference # IFC2X3
21+ else :
22+ identification = self .settings ["reference" ].Identification
23+
1724 for reference in self .file .by_type ("IfcClassificationReference" ):
1825 if self .file .schema == "IFC2X3" :
19- if reference .ItemReference == self . settings [ "reference" ]. ItemReference :
26+ if reference .ItemReference == identification :
2027 relating_classification = reference
2128 break
2229 else :
23- if reference .Identification == self . settings [ "reference" ]. Identification :
30+ if reference .Identification == identification :
2431 relating_classification = reference
2532 break
2633
@@ -38,16 +45,19 @@ def execute(self):
3845 relating_classification = migrator .migrate (self .settings ["reference" ], self .file )
3946 relating_classification .ReferencedSource = self .settings ["classification" ]
4047 self .settings ["reference" ].ReferencedSource = old_referenced_source
41- self .file .create_entity ("IfcRelAssociatesClassification" , ** {
42- "GlobalId" : ifcopenshell .guid .new (),
43- "RelatedObjects" : [self .settings ["product" ]],
44- "RelatingClassification" : relating_classification
45- })
48+ self .file .create_entity (
49+ "IfcRelAssociatesClassification" ,
50+ ** {
51+ "GlobalId" : ifcopenshell .guid .new (),
52+ "RelatedObjects" : [self .settings ["product" ]],
53+ "RelatingClassification" : relating_classification ,
54+ }
55+ )
4656
4757 def get_association (self , reference ):
4858 if self .file .schema == "IFC2X3" :
4959 for association in self .file .by_type ("IfcRelAssociatesClassification" ):
50- if relating_classification == reference :
60+ if association . RelatingClassification == reference :
5161 return association
5262 elif reference .ClassificationRefForObjects :
5363 return reference .ClassificationRefForObjects [0 ]
0 commit comments