mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
Introduce defaultdict instead of checks
This commit is contained in:
@@ -43,6 +43,7 @@ if "bpy" in locals():
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
import mathutils
|
||||||
|
from collections import defaultdict
|
||||||
from bpy.props import StringProperty, IntProperty, BoolProperty
|
from bpy.props import StringProperty, IntProperty, BoolProperty
|
||||||
from bpy_extras.io_utils import ImportHelper
|
from bpy_extras.io_utils import ImportHelper
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
if not valid_file:
|
if not valid_file:
|
||||||
return False
|
return False
|
||||||
print("Done reading file")
|
print("Done reading file")
|
||||||
id_to_object = {}
|
id_to_object = defaultdict(list)
|
||||||
id_to_parent = {}
|
id_to_parent = {}
|
||||||
id_to_matrix = {}
|
id_to_matrix = {}
|
||||||
openings = []
|
openings = []
|
||||||
@@ -82,6 +83,7 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
print("Creating geometry...")
|
print("Creating geometry...")
|
||||||
collection = bpy.data.collections.new(f"{bpy.path.basename(filename)}")
|
collection = bpy.data.collections.new(f"{bpy.path.basename(filename)}")
|
||||||
bpy.context.scene.collection.children.link(collection)
|
bpy.context.scene.collection.children.link(collection)
|
||||||
|
|
||||||
if process_relations:
|
if process_relations:
|
||||||
rel_collection = bpy.data.collections.new("Relations")
|
rel_collection = bpy.data.collections.new("Relations")
|
||||||
collection.children.link(rel_collection)
|
collection.children.link(rel_collection)
|
||||||
@@ -178,8 +180,6 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
bob.hide_viewport = bob.hide_render = True
|
bob.hide_viewport = bob.hide_render = True
|
||||||
bob.display_type = 'WIRE'
|
bob.display_type = 'WIRE'
|
||||||
|
|
||||||
if ob.id not in id_to_object:
|
|
||||||
id_to_object[ob.id] = []
|
|
||||||
id_to_object[ob.id].append(bob)
|
id_to_object[ob.id].append(bob)
|
||||||
|
|
||||||
if ob.parent_id > 0:
|
if ob.parent_id > 0:
|
||||||
@@ -201,8 +201,7 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
|
|
||||||
if process_relations:
|
if process_relations:
|
||||||
print("Processing relations...")
|
print("Processing relations...")
|
||||||
|
while len(id_to_parent_temp):
|
||||||
while len(id_to_parent_temp) and process_relations:
|
|
||||||
id, parent_id = id_to_parent_temp.popitem()
|
id, parent_id = id_to_parent_temp.popitem()
|
||||||
|
|
||||||
if parent_id in id_to_object:
|
if parent_id in id_to_object:
|
||||||
@@ -235,7 +234,6 @@ def import_ifc(filename, use_names, process_relations, blender_booleans):
|
|||||||
if parent_ob.parent_id > 0:
|
if parent_ob.parent_id > 0:
|
||||||
id_to_parent[parent_id] = parent_ob.parent_id
|
id_to_parent[parent_id] = parent_ob.parent_id
|
||||||
id_to_parent_temp[parent_id] = parent_ob.parent_id
|
id_to_parent_temp[parent_id] = parent_ob.parent_id
|
||||||
if parent_id not in id_to_object: id_to_object[parent_id] = []
|
|
||||||
id_to_object[parent_id].append(bob)
|
id_to_object[parent_id].append(bob)
|
||||||
if bob:
|
if bob:
|
||||||
for ob in id_to_object[id]:
|
for ob in id_to_object[id]:
|
||||||
|
|||||||
Reference in New Issue
Block a user