Skip to content

Commit fb1c340

Browse files
committed
Use passed context instead of bpy.context
1 parent 4614bde commit fb1c340

7 files changed

Lines changed: 144 additions & 132 deletions

File tree

src/blenderbim/blenderbim/bim/handler.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def undo_pre(scene):
166166

167167
@persistent
168168
def undo_post(scene):
169-
if IfcStore.last_transaction != bpy.context.scene.BIMProperties.last_transaction:
170-
IfcStore.last_transaction = bpy.context.scene.BIMProperties.last_transaction
169+
if IfcStore.last_transaction != scene.BIMProperties.last_transaction:
170+
IfcStore.last_transaction = scene.BIMProperties.last_transaction
171171
IfcStore.undo()
172172
purge_module_data()
173173
IfcStore.update_undo_redo_stack_objects()
@@ -181,8 +181,8 @@ def redo_pre(scene):
181181

182182
@persistent
183183
def redo_post(scene):
184-
if IfcStore.last_transaction != bpy.context.scene.BIMProperties.last_transaction:
185-
IfcStore.last_transaction = bpy.context.scene.BIMProperties.last_transaction
184+
if IfcStore.last_transaction != scene.BIMProperties.last_transaction:
185+
IfcStore.last_transaction = scene.BIMProperties.last_transaction
186186
IfcStore.redo()
187187
purge_module_data()
188188
IfcStore.update_undo_redo_stack_objects()
@@ -191,7 +191,7 @@ def redo_post(scene):
191191

192192
@persistent
193193
def ensureIfcExported(scene):
194-
if IfcStore.get_file() and not bpy.context.scene.BIMProperties.ifc_file:
194+
if IfcStore.get_file() and not scene.BIMProperties.ifc_file:
195195
bpy.ops.export_ifc.bim("INVOKE_DEFAULT")
196196

197197

@@ -230,18 +230,18 @@ def setDefaultProperties(scene):
230230
key=active_object_key, owner=global_subscription_owner, args=(), notify=active_object_callback
231231
)
232232
ifcopenshell.api.owner.settings.get_person = (
233-
lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_person))
234-
if getPersons(None, bpy.context) and bpy.context.scene.BIMOwnerProperties.user_person
233+
lambda ifc: ifc.by_id(int(scene.BIMOwnerProperties.user_person))
234+
if getPersons(None, None) and scene.BIMOwnerProperties.user_person
235235
else None
236236
)
237237
ifcopenshell.api.owner.settings.get_organisation = (
238-
lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation))
239-
if getOrganisations(None, bpy.context) and bpy.context.scene.BIMOwnerProperties.user_organisation
238+
lambda ifc: ifc.by_id(int(scene.BIMOwnerProperties.user_organisation))
239+
if getOrganisations(None, None) and scene.BIMOwnerProperties.user_organisation
240240
else None
241241
)
242242
ifcopenshell.api.owner.settings.get_application = get_application
243-
if len(bpy.context.scene.DocProperties.drawing_styles) == 0:
244-
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
243+
if len(scene.DocProperties.drawing_styles) == 0:
244+
drawing_style = scene.DocProperties.drawing_styles.add()
245245
drawing_style.name = "Technical"
246246
drawing_style.render_type = "VIEWPORT"
247247
drawing_style.raster_style = json.dumps(
@@ -272,7 +272,7 @@ def setDefaultProperties(scene):
272272
"space.overlay.show_relationship_lines": False,
273273
}
274274
)
275-
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
275+
drawing_style = scene.DocProperties.drawing_styles.add()
276276
drawing_style.name = "Shaded"
277277
drawing_style.render_type = "VIEWPORT"
278278
drawing_style.raster_style = json.dumps(
@@ -303,7 +303,7 @@ def setDefaultProperties(scene):
303303
"space.overlay.show_relationship_lines": False,
304304
}
305305
)
306-
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
306+
drawing_style = scene.DocProperties.drawing_styles.add()
307307
drawing_style.name = "Blender Default"
308308
drawing_style.render_type = "DEFAULT"
309309
bpy.ops.bim.save_drawing_style(index="2")

src/blenderbim/blenderbim/bim/module/bcf/operator.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def execute(self, context):
766766
cam_width = context.scene.render.resolution_x
767767
cam_height = context.scene.render.resolution_y
768768
cam_aspect = cam_width / cam_height
769-
769+
770770
if viewpoint.snapshot:
771771
obj.data.show_background_images = True
772772
obj.data.background_images.clear()
@@ -787,7 +787,7 @@ def execute(self, context):
787787
area.spaces[0].region_3d.view_perspective = "CAMERA"
788788

789789
if self.file:
790-
self.set_viewpoint_components(viewpoint)
790+
self.set_viewpoint_components(viewpoint, context)
791791

792792
gp = bpy.data.grease_pencils.get("BCF")
793793
if gp:
@@ -803,10 +803,10 @@ def execute(self, context):
803803
if viewpoint.bitmaps:
804804
self.create_bitmaps(bcfxml, viewpoint, topic)
805805

806-
self.setup_camera(viewpoint, obj, cam_aspect)
806+
self.setup_camera(viewpoint, obj, cam_aspect, context)
807807
return {"FINISHED"}
808808

809-
def setup_camera(self, viewpoint, obj, cam_aspect):
809+
def setup_camera(self, viewpoint, obj, cam_aspect, context):
810810
if viewpoint.orthogonal_camera:
811811
camera = viewpoint.orthogonal_camera
812812
obj.data.type = "ORTHO"
@@ -831,7 +831,7 @@ def setup_camera(self, viewpoint, obj, cam_aspect):
831831
[x_axis[2], y_axis[2], z_axis[2], camera.camera_view_point.z],
832832
[0, 0, 0, 1],
833833
))
834-
props = bpy.context.scene.BIMGeoreferenceProperties
834+
props = context.scene.BIMGeoreferenceProperties
835835
if props.has_blender_offset:
836836
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
837837
matrix = ifcopenshell.util.geolocation.global2local(
@@ -844,7 +844,7 @@ def setup_camera(self, viewpoint, obj, cam_aspect):
844844
)
845845
obj.matrix_world = Matrix(matrix.tolist())
846846

847-
def set_viewpoint_components(self, viewpoint):
847+
def set_viewpoint_components(self, viewpoint, context):
848848
if not viewpoint.components:
849849
return
850850

@@ -854,10 +854,10 @@ def set_viewpoint_components(self, viewpoint):
854854
exception_global_ids = [v.ifc_guid for v in viewpoint.components.visibility.exceptions]
855855

856856
if viewpoint.components.visibility.default_visibility:
857-
old = bpy.context.area.type
858-
bpy.context.area.type = "VIEW_3D"
857+
old = context.area.type
858+
context.area.type = "VIEW_3D"
859859
bpy.ops.object.hide_view_clear()
860-
bpy.context.area.type = old
860+
context.area.type = old
861861
for global_id in exception_global_ids:
862862
obj = IfcStore.get_element(global_id)
863863
if obj:
@@ -869,35 +869,35 @@ def set_viewpoint_components(self, viewpoint):
869869
if obj:
870870
objs.append(obj)
871871
if objs:
872-
old = bpy.context.area.type
873-
bpy.context.area.type = "VIEW_3D"
872+
old = context.area.type
873+
context.area.type = "VIEW_3D"
874874
context_override = {}
875875
context_override["object"] = context_override["active_object"] = objs[0]
876876
context_override["selected_objects"] = context_override["selected_editable_objects"] = objs
877877
bpy.ops.object.hide_view_set(context_override, unselected=True)
878-
bpy.context.area.type = old
878+
context.area.type = old
879879

880880
if viewpoint.components.view_setup_hints:
881881
if not viewpoint.components.view_setup_hints.spaces_visible:
882-
self.hide_spaces()
882+
self.hide_spaces(context)
883883
if viewpoint.components.view_setup_hints.openings_visible is not None:
884-
self.set_openings_visibility(viewpoint.components.view_setup_hints.openings_visible)
884+
self.set_openings_visibility(viewpoint.components.view_setup_hints.openings_visible, context)
885885
else:
886-
self.hide_spaces()
887-
self.set_openings_visibility(False)
886+
self.hide_spaces(context)
887+
self.set_openings_visibility(False, context)
888888

889889
self.set_selection(viewpoint)
890890
self.set_colours(viewpoint)
891891

892-
def hide_spaces(self):
893-
old = bpy.context.area.type
894-
bpy.context.area.type = "VIEW_3D"
892+
def hide_spaces(self, context):
893+
old = context.area.type
894+
context.area.type = "VIEW_3D"
895895
bpy.ops.object.select_pattern(pattern="IfcSpace/*")
896896
bpy.ops.object.hide_view_set({})
897-
bpy.context.area.type = old
897+
context.area.type = old
898898

899-
def set_openings_visibility(self, is_visible):
900-
for collection in self.get_opening_collections():
899+
def set_openings_visibility(self, is_visible, context):
900+
for collection in self.get_opening_collections(context):
901901
collection.hide_viewport = not is_visible
902902

903903
def set_selection(self, viewpoint):
@@ -918,9 +918,9 @@ def set_colours(self, viewpoint):
918918
if obj:
919919
obj.color = self.hex_to_rgb(color)
920920

921-
def get_opening_collections(self):
921+
def get_opening_collections(self, context):
922922
collections = []
923-
for collection in bpy.context.view_layer.layer_collection.children:
923+
for collection in context.view_layer.layer_collection.children:
924924
opening_collection = collection.children.get("IfcOpeningElements")
925925
if opening_collection:
926926
collections.append(opening_collection)

src/blenderbim/blenderbim/bim/module/cost/operator.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def _execute(self, context):
438438
else:
439439
products = [
440440
self.file.by_id(o.BIMObjectProperties.ifc_definition_id)
441-
for o in bpy.context.selected_objects
441+
for o in context.selected_objects
442442
if o.BIMObjectProperties.ifc_definition_id
443443
]
444444
ifcopenshell.api.run(
@@ -637,19 +637,22 @@ def execute(self, context):
637637
data = Data.cost_values[self.cost_value]
638638

639639
blenderbim.bim.helper.import_attributes(
640-
data["type"], self.props.cost_value_attributes, data, self.import_attributes
640+
data["type"],
641+
self.props.cost_value_attributes,
642+
data,
643+
lambda name, prop, data: self.import_attributes(name, prop, data, context)
641644
)
642645
return {"FINISHED"}
643646

644-
def import_attributes(self, name, prop, data):
647+
def import_attributes(self, name, prop, data, context):
645648
if name == "AppliedValue":
646649
# TODO: for now, only support simple values
647650
prop.data_type = "float"
648651
prop.float_value = 0.0 if prop.is_null else data[name]
649652
return True
650653
if (
651654
name == "UnitBasis"
652-
and Data.cost_schedules[bpy.context.scene.BIMCostProperties.active_cost_schedule_id]["PredefinedType"]
655+
and Data.cost_schedules[context.scene.BIMCostProperties.active_cost_schedule_id]["PredefinedType"]
653656
== "SCHEDULEOFRATES"
654657
):
655658
prop = self.props.cost_value_attributes.add()
@@ -711,7 +714,9 @@ def execute(self, context):
711714

712715
def _execute(self, context):
713716
props = context.scene.BIMCostProperties
714-
attributes = blenderbim.bim.helper.export_attributes(props.cost_value_attributes, self.export_attributes)
717+
attributes = blenderbim.bim.helper.export_attributes(
718+
props.cost_value_attributes,
719+
lambda attributes, prop: self.export_attributes(attributes, prop, context))
715720
self.file = IfcStore.get_file()
716721
ifcopenshell.api.run(
717722
"cost.edit_cost_value",
@@ -722,15 +727,15 @@ def _execute(self, context):
722727
bpy.ops.bim.disable_editing_cost_item_value()
723728
return {"FINISHED"}
724729

725-
def export_attributes(self, attributes, prop):
730+
def export_attributes(self, attributes, prop, context):
726731
if prop.name == "UnitBasisValue":
727732
if prop.is_null:
728733
attributes["UnitBasis"] = None
729734
return True
730735
attributes["UnitBasis"] = {
731736
"ValueComponent": prop.float_value or 1,
732737
"UnitComponent": IfcStore.get_file().by_id(
733-
int(bpy.context.scene.BIMCostProperties.cost_value_attributes.get("UnitBasisUnit").enum_value)
738+
int(context.scene.BIMCostProperties.cost_value_attributes.get("UnitBasisUnit").enum_value)
734739
),
735740
}
736741
return True

0 commit comments

Comments
 (0)