Fix #4921. When upgrading to IFC4X3, preprocess the file to remove deprecated style assignments

This commit is contained in:
Dion Moult
2024-06-27 11:49:00 +10:00
parent 98afb72ba3
commit 48d058a32a
4 changed files with 18 additions and 3 deletions
@@ -48,6 +48,8 @@ class GeoreferenceData:
@classmethod
def coordinate_operation_class(cls):
if tool.Ifc.get_schema() == "IFC2X3":
return []
declaration = tool.Ifc.schema().declaration_by_name("IfcCoordinateOperation")
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
names = [d.name() for d in declarations]
-3
View File
@@ -16,11 +16,9 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import os
import bpy
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
try:
import ifcpatch
@@ -31,6 +29,5 @@ except:
class Patch(blenderbim.core.tool.Patch):
@classmethod
def run_migrate_patch(cls, infile, outfile, schema):
log = os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log")
output = ifcpatch.execute({"input": infile, "file": ifcopenshell.open(infile), "recipe": "Migrate", "arguments": [schema]})
ifcpatch.write(output, outfile)
@@ -223,6 +223,21 @@ class Migrator:
"User": None,
}
def preprocess(self, old_file, new_file):
if old_file.schema == "IFC4" and new_file.schema == "IFC4X3":
# In IFC4 -> IFC4X3, IfcPresentationStyleAssignment is deprecated
to_delete = set()
for assignment in old_file.by_type("IfcPresentationStyleAssignment"):
for styled_item in old_file.get_inverse(assignment):
if not styled_item.is_a("IfcStyledItem"):
continue
styled_item.Styles = [
s for s in styled_item.Styles if s.is_a("IfcPresentationStyle")
] + list(assignment.Styles)
to_delete.add(assignment)
for element in to_delete:
old_file.remove(element)
def migrate(
self, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file
) -> ifcopenshell.entity_instance:
+1
View File
@@ -46,6 +46,7 @@ class Patcher:
def patch(self):
self.file_patched = ifcopenshell.file(schema=self.schema)
migrator = ifcopenshell.util.schema.Migrator()
migrator.preprocess(self.file, self.file_patched)
for element in self.file:
new_element = migrator.migrate(element, self.file_patched)
print("Migrating", element)