99
1010
1111def mode_callback (obj , data ):
12- if (
13- obj .mode != "OBJECT"
14- or not obj .data
15- or not isinstance (obj .data , bpy .types .Mesh )
16- or not obj .data .BIMMeshProperties .ifc_definition_id
17- or not bpy .context .scene .BIMProjectProperties .is_authoring
18- ):
19- return
20- representation = IfcStore .get_file ().by_id (obj .data .BIMMeshProperties .ifc_definition_id )
21- if representation .RepresentationType == "Tessellation" or representation .RepresentationType == "Brep" :
22- IfcStore .edited_objs .add (obj .name )
12+ for obj in bpy .context .selected_objects :
13+ if (
14+ obj .mode != "EDIT"
15+ or not obj .data
16+ or not isinstance (obj .data , bpy .types .Mesh )
17+ or not obj .data .BIMMeshProperties .ifc_definition_id
18+ or not bpy .context .scene .BIMProjectProperties .is_authoring
19+ ):
20+ return
21+ representation = IfcStore .get_file ().by_id (obj .data .BIMMeshProperties .ifc_definition_id )
22+ if representation .RepresentationType == "Tessellation" or representation .RepresentationType == "Brep" :
23+ IfcStore .edited_objs .add (obj .name )
2324
2425
2526def name_callback (obj , data ):
@@ -29,6 +30,9 @@ def name_callback(obj, data):
2930 element = IfcStore .get_file ().by_id (obj .BIMObjectProperties .ifc_definition_id )
3031 if not element .is_a ("IfcRoot" ):
3132 return
33+ if element .is_a ("IfcSpatialStructureElement" ) or (hasattr (element , "IsDecomposedBy" ) and element .IsDecomposedBy ):
34+ collection = obj .users_collection [0 ]
35+ collection .name = obj .name
3236 element .Name = "/" .join (obj .name .split ("/" )[1 :])
3337 AttributeData .load (IfcStore .get_file (), obj .BIMObjectProperties .ifc_definition_id )
3438
@@ -52,52 +56,35 @@ def subscribe_to(object, data_path, callback):
5256def purge_module_data ():
5357 from blenderbim .bim import modules
5458
55- for name in modules .keys ():
59+ for name , value in modules .items ():
5660 try :
5761 getattr (getattr (getattr (ifcopenshell .api , name ), "data" ), "Data" ).purge ()
5862 except AttributeError :
5963 pass
6064
65+ try :
66+ getattr (value , "prop" ).purge ()
67+ except AttributeError :
68+ pass
69+
6170
6271@persistent
6372def loadIfcStore (scene ):
64- IfcStore .file = None
65- IfcStore .schema = None
66- props = bpy .context .scene .BIMProperties
67- IfcStore .id_map = (
68- {int (k ): bpy .data .objects .get (v ) for k , v in json .loads (props .id_map ).items ()} if props .id_map else {}
69- )
70- IfcStore .guid_map = (
71- {k : bpy .data .objects .get (v ) for k , v in json .loads (props .guid_map ).items ()} if props .id_map else {}
72- )
73+ IfcStore .purge ()
74+ ifc_file = IfcStore .get_file ()
75+ IfcStore .get_schema ()
76+ [
77+ IfcStore .link_element (ifc_file .by_id (o .BIMObjectProperties .ifc_definition_id ), o )
78+ for o in bpy .data .objects
79+ if o .BIMObjectProperties .ifc_definition_id
80+ ]
7381 purge_module_data ()
7482
7583
7684@persistent
7785def ensureIfcExported (scene ):
7886 if IfcStore .get_file () and not bpy .context .scene .BIMProperties .ifc_file :
79- # The invocation pops up a file select window.
80- # This is non-blocking, therefore the Blend file is saved before we export.
81- bpy .ops .export_ifc .bim ("INVOKE_DEFAULT" , should_force_resave = True )
82-
83-
84- @persistent
85- def storeIdMap (scene ):
86- try :
87- bpy .context .scene .BIMProperties .id_map = json .dumps ({k : v .name for k , v in IfcStore .id_map .items ()})
88- bpy .context .scene .BIMProperties .guid_map = json .dumps ({k : v .name for k , v in IfcStore .guid_map .items ()})
89- except :
90- # Regenerate maps. Is there a better solution for this? It seems fragile.
91- file = IfcStore .get_file ()
92- IfcStore .id_map = {
93- o .ifc_definition_id : o .name for o in bpy .data .objects if o .BIMObjectProperties .ifc_definition_id
94- }
95- IfcStore .guid_map = {
96- file .by_id (i ).GlobalId : n for i , n in IfcStore .id_map .items () if file .by_id (i ).is_a ("IfcRoot" )
97- }
98- # Then attempt to store it again
99- bpy .context .scene .BIMProperties .id_map = json .dumps ({k : v .name for k , v in IfcStore .id_map .items ()})
100- bpy .context .scene .BIMProperties .guid_map = json .dumps ({k : v .name for k , v in IfcStore .guid_map .items ()})
87+ bpy .ops .export_ifc .bim ("INVOKE_DEFAULT" )
10188
10289
10390def get_application (ifc ):
@@ -172,12 +159,12 @@ def create_application_organisation(ifc):
172159@persistent
173160def setDefaultProperties (scene ):
174161 ifcopenshell .api .owner .settings .get_person = (
175- lambda ifc : ifc .by_id (int (bpy .context .scene .BIMOwnerProperties .user_person ))
162+ lambda ifc : ifc .by_id (int (bpy .context .scene .BIMOwnerProperties .user_person ))
176163 if bpy .context .scene .BIMOwnerProperties .user_person
177164 else None
178165 )
179166 ifcopenshell .api .owner .settings .get_organisation = (
180- lambda ifc : ifc .by_id (int (bpy .context .scene .BIMOwnerProperties .user_organisation ))
167+ lambda ifc : ifc .by_id (int (bpy .context .scene .BIMOwnerProperties .user_organisation ))
181168 if bpy .context .scene .BIMOwnerProperties .user_organisation
182169 else None
183170 )
0 commit comments