mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
Linking projects now shares context prioritisation logic with regular project loading
This means it can link in more interesting shapes.
This commit is contained in:
@@ -988,7 +988,9 @@ class LoadLink(bpy.types.Operator):
|
|||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
bpy.ops.bim.load_linked_project(filepath="{self.filepath}", false_origin="{self.false_origin}")
|
props = bpy.context.scene.BIMProjectProperties
|
||||||
|
props.false_origin = "{self.false_origin}"
|
||||||
|
bpy.ops.bim.load_linked_project(filepath="{self.filepath}")
|
||||||
bpy.ops.wm.save_as_mainfile(filepath="{blend_filepath}")
|
bpy.ops.wm.save_as_mainfile(filepath="{blend_filepath}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -1245,7 +1247,6 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
bl_label = "Load a project for viewing only."
|
bl_label = "Load a project for viewing only."
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
filepath: bpy.props.StringProperty()
|
filepath: bpy.props.StringProperty()
|
||||||
false_origin: bpy.props.StringProperty(name="False Origin", default="0,0,0")
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
import ifcpatch
|
import ifcpatch
|
||||||
@@ -1269,10 +1270,9 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
print("Finished writing property database")
|
print("Finished writing property database")
|
||||||
|
|
||||||
logger = logging.getLogger("ImportIFC")
|
logger = logging.getLogger("ImportIFC")
|
||||||
ifc_import_settings = import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger)
|
tool.Loader.set_settings(import_ifc.IfcImportSettings.factory(context, IfcStore.path, logger))
|
||||||
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
tool.Loader.settings.contexts = ifcopenshell.util.representation.get_prioritised_contexts(self.file)
|
||||||
ifc_importer.file = self.file
|
tool.Loader.settings.context_settings = tool.Loader.create_settings()
|
||||||
ifc_importer.process_context_filter()
|
|
||||||
|
|
||||||
self.elements = set(self.file.by_type("IfcElement"))
|
self.elements = set(self.file.by_type("IfcElement"))
|
||||||
if self.file.schema in ("IFC2X3", "IFC4"):
|
if self.file.schema in ("IFC2X3", "IFC4"):
|
||||||
@@ -1282,18 +1282,21 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
else:
|
else:
|
||||||
self.elements |= set(self.file.by_type("IfcSpatialElement"))
|
self.elements |= set(self.file.by_type("IfcSpatialElement"))
|
||||||
self.elements -= set(self.file.by_type("IfcFeatureElement"))
|
self.elements -= set(self.file.by_type("IfcFeatureElement"))
|
||||||
self.elements = list(self.elements)
|
|
||||||
|
|
||||||
model_origin = np.array(ifcopenshell.util.geolocation.auto_xyz2enh(self.file, 0, 0, 0))
|
if tool.Loader.settings.false_origin:
|
||||||
false_origin = np.array([float(o.strip()) for o in self.false_origin.split(",")])
|
model_origin = np.array(ifcopenshell.util.geolocation.auto_xyz2enh(self.file, 0, 0, 0))
|
||||||
model_offset = model_origin - false_origin
|
false_origin = np.array(tool.Loader.settings.false_origin)
|
||||||
zero_origin = np.array((0, 0, 0))
|
model_offset = model_origin - false_origin
|
||||||
has_model_offset = not np.allclose(model_offset, zero_origin)
|
zero_origin = np.array((0, 0, 0))
|
||||||
|
has_model_offset = not np.allclose(model_offset, zero_origin)
|
||||||
|
else:
|
||||||
|
has_model_offset = False
|
||||||
|
|
||||||
for settings in ifc_importer.context_settings:
|
for settings in tool.Loader.settings.context_settings:
|
||||||
settings = ifcopenshell.geom.settings()
|
if not self.elements:
|
||||||
settings.set("apply-default-materials", False)
|
break
|
||||||
|
|
||||||
|
results = set()
|
||||||
if has_model_offset:
|
if has_model_offset:
|
||||||
offset = ifcopenshell.ifcopenshell_wrapper.float_array_3()
|
offset = ifcopenshell.ifcopenshell_wrapper.float_array_3()
|
||||||
offset[0], offset[1], offset[2] = model_offset
|
offset[0], offset[1], offset[2] = model_offset
|
||||||
@@ -1314,7 +1317,6 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
chunked_materials = []
|
chunked_materials = []
|
||||||
chunked_material_ids = []
|
chunked_material_ids = []
|
||||||
material_offset = 0
|
material_offset = 0
|
||||||
max_slot_index = 0
|
|
||||||
chunk_size = 10000
|
chunk_size = 10000
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
@@ -1322,6 +1324,8 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
if iterator.initialize():
|
if iterator.initialize():
|
||||||
while True:
|
while True:
|
||||||
shape = iterator.get()
|
shape = iterator.get()
|
||||||
|
results.add(self.file.by_id(shape.id))
|
||||||
|
|
||||||
if len(shape.geometry.faces) > 1000 and self.is_local(shape): # 333 tris
|
if len(shape.geometry.faces) > 1000 and self.is_local(shape): # 333 tris
|
||||||
self.process_occurrence(shape)
|
self.process_occurrence(shape)
|
||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
@@ -1418,7 +1422,6 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
chunked_materials = []
|
chunked_materials = []
|
||||||
chunked_material_ids = []
|
chunked_material_ids = []
|
||||||
material_offset = 0
|
material_offset = 0
|
||||||
max_slot_index = 0
|
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
if not iterator.next():
|
if not iterator.next():
|
||||||
@@ -1448,10 +1451,10 @@ class LoadLinkedProject(bpy.types.Operator):
|
|||||||
chunked_guid_ids,
|
chunked_guid_ids,
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
|
self.elements -= results
|
||||||
|
|
||||||
bpy.context.scene.collection.children.link(self.collection)
|
bpy.context.scene.collection.children.link(self.collection)
|
||||||
print("Finished", time.time() - start)
|
print("Finished", time.time() - start)
|
||||||
break
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def is_local(self, shape: ShapeElementType) -> bool:
|
def is_local(self, shape: ShapeElementType) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user