WIP port reassign and unassign class to partial editing. See #1222.

This commit is contained in:
Dion Moult
2021-01-04 13:07:29 +11:00
parent 0c0ffce908
commit 6387c03dbc
10 changed files with 184 additions and 50 deletions
+2 -19
View File
@@ -4,6 +4,7 @@
import ifcopenshell
import ifcopenshell.util.selector
import ifcopenshell.util.element
import ifcopenshell.util.schema
import csv
import lark
import argparse
@@ -13,7 +14,7 @@ class IfcAttributeExtractor:
@staticmethod
def set_element_key(ifc_file, element, key, value):
if key == "type" and element.is_a() != value:
return IfcAttributeExtractor.change_ifc_class(ifc_file, element, value)
return ifcopenshell.util.schema.reassign_class(ifc_file, element, value)
if hasattr(element, key):
setattr(element, key, value)
return element
@@ -32,24 +33,6 @@ class IfcAttributeExtractor:
return element
return element
@staticmethod
def change_ifc_class(ifc_file, element, new_class):
try:
new_element = ifc_file.create_entity(new_class)
except:
print(f"Class of {element} could not be changed to {new_class}")
return element
new_attributes = [new_element.attribute_name(i) for i, attribute in enumerate(new_element)]
for i, attribute in enumerate(element):
try:
new_element[new_attributes.index(element.attribute_name(i))] = attribute
except:
continue
for inverse in ifc_file.get_inverse(element):
ifcopenshell.util.element.replace_attribute(inverse, element, new_element)
ifc_file.remove(element)
return new_element
@staticmethod
def get_element_qto(element, name):
for relationship in element.IsDefinedBy: