mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Fix bug where product and type representations wouldn't be linked in Blender when importing
This commit is contained in:
@@ -636,7 +636,7 @@ class IfcImporter:
|
|||||||
if self.ifc_import_settings.should_import_type_representations and representation_map:
|
if self.ifc_import_settings.should_import_type_representations and representation_map:
|
||||||
try:
|
try:
|
||||||
shape = ifcopenshell.geom.create_shape(self.settings, representation_map.MappedRepresentation)
|
shape = ifcopenshell.geom.create_shape(self.settings, representation_map.MappedRepresentation)
|
||||||
mesh_name = f"mesh-{shape.id}"
|
mesh_name = self.get_mesh_name(shape)
|
||||||
mesh = self.meshes.get(mesh_name)
|
mesh = self.meshes.get(mesh_name)
|
||||||
if mesh is None:
|
if mesh is None:
|
||||||
mesh = self.create_mesh(element, shape)
|
mesh = self.create_mesh(element, shape)
|
||||||
@@ -761,8 +761,7 @@ class IfcImporter:
|
|||||||
self.ifc_import_settings.logger.info("Creating object %s", element)
|
self.ifc_import_settings.logger.info("Creating object %s", element)
|
||||||
|
|
||||||
if shape:
|
if shape:
|
||||||
# TODO: make names more meaningful
|
mesh_name = self.get_mesh_name(shape.geometry)
|
||||||
mesh_name = f"mesh-{shape.geometry.id}"
|
|
||||||
mesh = self.meshes.get(mesh_name)
|
mesh = self.meshes.get(mesh_name)
|
||||||
if mesh is None:
|
if mesh is None:
|
||||||
if element.GlobalId in self.native_elements:
|
if element.GlobalId in self.native_elements:
|
||||||
@@ -1388,6 +1387,16 @@ class IfcImporter:
|
|||||||
):
|
):
|
||||||
return representation.Items[0].MappingTarget
|
return representation.Items[0].MappingTarget
|
||||||
|
|
||||||
|
def get_mesh_name(self, geometry):
|
||||||
|
representation_id = geometry.id
|
||||||
|
if "-" in representation_id:
|
||||||
|
representation_id = int(re.sub(r"\D", "", representation_id.split("-")[0]))
|
||||||
|
else:
|
||||||
|
representation_id = int(re.sub(r"\D", "", representation_id))
|
||||||
|
representation = self.file.by_id(representation_id)
|
||||||
|
context_id = representation.ContextOfItems.id() if hasattr(representation, "ContextOfItems") else 0
|
||||||
|
return "{}/{}".format(context_id, representation_id)
|
||||||
|
|
||||||
def create_mesh(self, element, shape, is_curve=False):
|
def create_mesh(self, element, shape, is_curve=False):
|
||||||
try:
|
try:
|
||||||
if hasattr(shape, "geometry"):
|
if hasattr(shape, "geometry"):
|
||||||
@@ -1398,14 +1407,7 @@ class IfcImporter:
|
|||||||
if is_curve:
|
if is_curve:
|
||||||
return self.create_curve(geometry)
|
return self.create_curve(geometry)
|
||||||
|
|
||||||
representation_id = geometry.id
|
mesh = bpy.data.meshes.new(self.get_mesh_name(geometry))
|
||||||
if "-" in representation_id:
|
|
||||||
representation_id = int(re.sub(r"\D", "", representation_id.split("-")[0]))
|
|
||||||
else:
|
|
||||||
representation_id = int(re.sub(r"\D", "", representation_id))
|
|
||||||
representation = self.file.by_id(representation_id)
|
|
||||||
context_id = representation.ContextOfItems.id() if hasattr(representation, "ContextOfItems") else 0
|
|
||||||
mesh = bpy.data.meshes.new("{}/{}".format(context_id, representation_id))
|
|
||||||
|
|
||||||
props = bpy.context.scene.BIMGeoreferenceProperties
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
||||||
if props.has_blender_offset and props.blender_offset_type == "CARTESIAN_POINT":
|
if props.has_blender_offset and props.blender_offset_type == "CARTESIAN_POINT":
|
||||||
|
|||||||
Reference in New Issue
Block a user