Use passed context instead of bpy.context

This commit is contained in:
Gorgious
2021-08-17 14:55:19 +02:00
parent 4614bde8d7
commit fb1c340664
7 changed files with 144 additions and 132 deletions
+13 -13
View File
@@ -166,8 +166,8 @@ def undo_pre(scene):
@persistent
def undo_post(scene):
if IfcStore.last_transaction != bpy.context.scene.BIMProperties.last_transaction:
IfcStore.last_transaction = bpy.context.scene.BIMProperties.last_transaction
if IfcStore.last_transaction != scene.BIMProperties.last_transaction:
IfcStore.last_transaction = scene.BIMProperties.last_transaction
IfcStore.undo()
purge_module_data()
IfcStore.update_undo_redo_stack_objects()
@@ -181,8 +181,8 @@ def redo_pre(scene):
@persistent
def redo_post(scene):
if IfcStore.last_transaction != bpy.context.scene.BIMProperties.last_transaction:
IfcStore.last_transaction = bpy.context.scene.BIMProperties.last_transaction
if IfcStore.last_transaction != scene.BIMProperties.last_transaction:
IfcStore.last_transaction = scene.BIMProperties.last_transaction
IfcStore.redo()
purge_module_data()
IfcStore.update_undo_redo_stack_objects()
@@ -191,7 +191,7 @@ def redo_post(scene):
@persistent
def ensureIfcExported(scene):
if IfcStore.get_file() and not bpy.context.scene.BIMProperties.ifc_file:
if IfcStore.get_file() and not scene.BIMProperties.ifc_file:
bpy.ops.export_ifc.bim("INVOKE_DEFAULT")
@@ -230,18 +230,18 @@ def setDefaultProperties(scene):
key=active_object_key, owner=global_subscription_owner, args=(), notify=active_object_callback
)
ifcopenshell.api.owner.settings.get_person = (
lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_person))
if getPersons(None, bpy.context) and bpy.context.scene.BIMOwnerProperties.user_person
lambda ifc: ifc.by_id(int(scene.BIMOwnerProperties.user_person))
if getPersons(None, None) and scene.BIMOwnerProperties.user_person
else None
)
ifcopenshell.api.owner.settings.get_organisation = (
lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation))
if getOrganisations(None, bpy.context) and bpy.context.scene.BIMOwnerProperties.user_organisation
lambda ifc: ifc.by_id(int(scene.BIMOwnerProperties.user_organisation))
if getOrganisations(None, None) and scene.BIMOwnerProperties.user_organisation
else None
)
ifcopenshell.api.owner.settings.get_application = get_application
if len(bpy.context.scene.DocProperties.drawing_styles) == 0:
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
if len(scene.DocProperties.drawing_styles) == 0:
drawing_style = scene.DocProperties.drawing_styles.add()
drawing_style.name = "Technical"
drawing_style.render_type = "VIEWPORT"
drawing_style.raster_style = json.dumps(
@@ -272,7 +272,7 @@ def setDefaultProperties(scene):
"space.overlay.show_relationship_lines": False,
}
)
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
drawing_style = scene.DocProperties.drawing_styles.add()
drawing_style.name = "Shaded"
drawing_style.render_type = "VIEWPORT"
drawing_style.raster_style = json.dumps(
@@ -303,7 +303,7 @@ def setDefaultProperties(scene):
"space.overlay.show_relationship_lines": False,
}
)
drawing_style = bpy.context.scene.DocProperties.drawing_styles.add()
drawing_style = scene.DocProperties.drawing_styles.add()
drawing_style.name = "Blender Default"
drawing_style.render_type = "DEFAULT"
bpy.ops.bim.save_drawing_style(index="2")
@@ -766,7 +766,7 @@ class ActivateBcfViewpoint(bpy.types.Operator):
cam_width = context.scene.render.resolution_x
cam_height = context.scene.render.resolution_y
cam_aspect = cam_width / cam_height
if viewpoint.snapshot:
obj.data.show_background_images = True
obj.data.background_images.clear()
@@ -787,7 +787,7 @@ class ActivateBcfViewpoint(bpy.types.Operator):
area.spaces[0].region_3d.view_perspective = "CAMERA"
if self.file:
self.set_viewpoint_components(viewpoint)
self.set_viewpoint_components(viewpoint, context)
gp = bpy.data.grease_pencils.get("BCF")
if gp:
@@ -803,10 +803,10 @@ class ActivateBcfViewpoint(bpy.types.Operator):
if viewpoint.bitmaps:
self.create_bitmaps(bcfxml, viewpoint, topic)
self.setup_camera(viewpoint, obj, cam_aspect)
self.setup_camera(viewpoint, obj, cam_aspect, context)
return {"FINISHED"}
def setup_camera(self, viewpoint, obj, cam_aspect):
def setup_camera(self, viewpoint, obj, cam_aspect, context):
if viewpoint.orthogonal_camera:
camera = viewpoint.orthogonal_camera
obj.data.type = "ORTHO"
@@ -831,7 +831,7 @@ class ActivateBcfViewpoint(bpy.types.Operator):
[x_axis[2], y_axis[2], z_axis[2], camera.camera_view_point.z],
[0, 0, 0, 1],
))
props = bpy.context.scene.BIMGeoreferenceProperties
props = context.scene.BIMGeoreferenceProperties
if props.has_blender_offset:
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file)
matrix = ifcopenshell.util.geolocation.global2local(
@@ -844,7 +844,7 @@ class ActivateBcfViewpoint(bpy.types.Operator):
)
obj.matrix_world = Matrix(matrix.tolist())
def set_viewpoint_components(self, viewpoint):
def set_viewpoint_components(self, viewpoint, context):
if not viewpoint.components:
return
@@ -854,10 +854,10 @@ class ActivateBcfViewpoint(bpy.types.Operator):
exception_global_ids = [v.ifc_guid for v in viewpoint.components.visibility.exceptions]
if viewpoint.components.visibility.default_visibility:
old = bpy.context.area.type
bpy.context.area.type = "VIEW_3D"
old = context.area.type
context.area.type = "VIEW_3D"
bpy.ops.object.hide_view_clear()
bpy.context.area.type = old
context.area.type = old
for global_id in exception_global_ids:
obj = IfcStore.get_element(global_id)
if obj:
@@ -869,35 +869,35 @@ class ActivateBcfViewpoint(bpy.types.Operator):
if obj:
objs.append(obj)
if objs:
old = bpy.context.area.type
bpy.context.area.type = "VIEW_3D"
old = context.area.type
context.area.type = "VIEW_3D"
context_override = {}
context_override["object"] = context_override["active_object"] = objs[0]
context_override["selected_objects"] = context_override["selected_editable_objects"] = objs
bpy.ops.object.hide_view_set(context_override, unselected=True)
bpy.context.area.type = old
context.area.type = old
if viewpoint.components.view_setup_hints:
if not viewpoint.components.view_setup_hints.spaces_visible:
self.hide_spaces()
self.hide_spaces(context)
if viewpoint.components.view_setup_hints.openings_visible is not None:
self.set_openings_visibility(viewpoint.components.view_setup_hints.openings_visible)
self.set_openings_visibility(viewpoint.components.view_setup_hints.openings_visible, context)
else:
self.hide_spaces()
self.set_openings_visibility(False)
self.hide_spaces(context)
self.set_openings_visibility(False, context)
self.set_selection(viewpoint)
self.set_colours(viewpoint)
def hide_spaces(self):
old = bpy.context.area.type
bpy.context.area.type = "VIEW_3D"
def hide_spaces(self, context):
old = context.area.type
context.area.type = "VIEW_3D"
bpy.ops.object.select_pattern(pattern="IfcSpace/*")
bpy.ops.object.hide_view_set({})
bpy.context.area.type = old
context.area.type = old
def set_openings_visibility(self, is_visible):
for collection in self.get_opening_collections():
def set_openings_visibility(self, is_visible, context):
for collection in self.get_opening_collections(context):
collection.hide_viewport = not is_visible
def set_selection(self, viewpoint):
@@ -918,9 +918,9 @@ class ActivateBcfViewpoint(bpy.types.Operator):
if obj:
obj.color = self.hex_to_rgb(color)
def get_opening_collections(self):
def get_opening_collections(self, context):
collections = []
for collection in bpy.context.view_layer.layer_collection.children:
for collection in context.view_layer.layer_collection.children:
opening_collection = collection.children.get("IfcOpeningElements")
if opening_collection:
collections.append(opening_collection)
@@ -438,7 +438,7 @@ class UnassignCostItemQuantity(bpy.types.Operator):
else:
products = [
self.file.by_id(o.BIMObjectProperties.ifc_definition_id)
for o in bpy.context.selected_objects
for o in context.selected_objects
if o.BIMObjectProperties.ifc_definition_id
]
ifcopenshell.api.run(
@@ -637,11 +637,14 @@ class EnableEditingCostItemValue(bpy.types.Operator):
data = Data.cost_values[self.cost_value]
blenderbim.bim.helper.import_attributes(
data["type"], self.props.cost_value_attributes, data, self.import_attributes
data["type"],
self.props.cost_value_attributes,
data,
lambda name, prop, data: self.import_attributes(name, prop, data, context)
)
return {"FINISHED"}
def import_attributes(self, name, prop, data):
def import_attributes(self, name, prop, data, context):
if name == "AppliedValue":
# TODO: for now, only support simple values
prop.data_type = "float"
@@ -649,7 +652,7 @@ class EnableEditingCostItemValue(bpy.types.Operator):
return True
if (
name == "UnitBasis"
and Data.cost_schedules[bpy.context.scene.BIMCostProperties.active_cost_schedule_id]["PredefinedType"]
and Data.cost_schedules[context.scene.BIMCostProperties.active_cost_schedule_id]["PredefinedType"]
== "SCHEDULEOFRATES"
):
prop = self.props.cost_value_attributes.add()
@@ -711,7 +714,9 @@ class EditCostValue(bpy.types.Operator):
def _execute(self, context):
props = context.scene.BIMCostProperties
attributes = blenderbim.bim.helper.export_attributes(props.cost_value_attributes, self.export_attributes)
attributes = blenderbim.bim.helper.export_attributes(
props.cost_value_attributes,
lambda attributes, prop: self.export_attributes(attributes, prop, context))
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"cost.edit_cost_value",
@@ -722,7 +727,7 @@ class EditCostValue(bpy.types.Operator):
bpy.ops.bim.disable_editing_cost_item_value()
return {"FINISHED"}
def export_attributes(self, attributes, prop):
def export_attributes(self, attributes, prop, context):
if prop.name == "UnitBasisValue":
if prop.is_null:
attributes["UnitBasis"] = None
@@ -730,7 +735,7 @@ class EditCostValue(bpy.types.Operator):
attributes["UnitBasis"] = {
"ValueComponent": prop.float_value or 1,
"UnitComponent": IfcStore.get_file().by_id(
int(bpy.context.scene.BIMCostProperties.cost_value_attributes.get("UnitBasisUnit").enum_value)
int(context.scene.BIMCostProperties.cost_value_attributes.get("UnitBasisUnit").enum_value)
),
}
return True
@@ -127,7 +127,7 @@ class CreateDrawing(bpy.types.Operator):
self.profile_code("Generate annotation")
svg_path = self.combine_svgs(context, underlay_svg, linework_svg, annotation_svg)
self.profile_code("Combine SVG layers")
open_with_user_command(bpy.context.preferences.addons["blenderbim"].preferences.svg_command, svg_path)
open_with_user_command(context.preferences.addons["blenderbim"].preferences.svg_command, svg_path)
print("Total Time: {:.2f}".format(time.time() - start))
return {"FINISHED"}
@@ -185,8 +185,8 @@ class CreateDrawing(bpy.types.Operator):
if not self.props.has_underlay:
return
svg_path = os.path.join(context.scene.BIMProperties.data_dir, "cache", self.drawing_name + "-underlay.svg")
bpy.context.scene.render.filepath = svg_path[0:-4] + ".png"
drawing_style = bpy.context.scene.DocProperties.drawing_styles[
context.scene.render.filepath = svg_path[0:-4] + ".png"
drawing_style = context.scene.DocProperties.drawing_styles[
self.camera.data.BIMCameraProperties.active_drawing_style_index
]
@@ -197,7 +197,7 @@ class CreateDrawing(bpy.types.Operator):
for obj in self.camera.users_collection[0].objects:
previous_visibility[obj.name] = obj.hide_get()
obj.hide_set(True)
for obj in bpy.context.visible_objects:
for obj in context.visible_objects:
if (
(not obj.data and not obj.instance_collection)
or isinstance(obj.data, bpy.types.Camera)
@@ -208,14 +208,14 @@ class CreateDrawing(bpy.types.Operator):
previous_visibility[obj.name] = obj.hide_get()
obj.hide_set(True)
space = self.get_view_3d()
space = self.get_view_3d(context.screen.areas)
previous_shading = space.shading.type
previous_format = bpy.context.scene.render.image_settings.file_format
previous_format = context.scene.render.image_settings.file_format
space.shading.type = "RENDERED"
bpy.context.scene.render.image_settings.file_format = "PNG"
context.scene.render.image_settings.file_format = "PNG"
bpy.ops.render.opengl(write_still=True)
space.shading.type = previous_shading
bpy.context.scene.render.image_settings.file_format = previous_format
context.scene.render.image_settings.file_format = previous_format
for name, value in previous_visibility.items():
bpy.data.objects[name].hide_set(value)
@@ -229,7 +229,7 @@ class CreateDrawing(bpy.types.Operator):
svg_writer.human_scale = "NTS"
else:
svg_writer.human_scale = human_scale
render = bpy.context.scene.render
render = context.scene.render
if self.is_landscape():
width = self.camera.data.ortho_scale
height = width / render.resolution_x * render.resolution_y
@@ -237,13 +237,13 @@ class CreateDrawing(bpy.types.Operator):
height = self.camera.data.ortho_scale
width = height / render.resolution_y * render.resolution_x
svg_writer.output = svg_path
svg_writer.data_dir = bpy.context.scene.BIMProperties.data_dir
svg_writer.data_dir = context.scene.BIMProperties.data_dir
svg_writer.vector_style = drawing_style.vector_style
svg_writer.camera = self.camera
svg_writer.camera_width = width
svg_writer.camera_height = height
svg_writer.camera_projection = tuple(self.camera.matrix_world.to_quaternion() @ Vector((0, 0, -1)))
svg_writer.background_image = bpy.context.scene.render.filepath
svg_writer.background_image = context.scene.render.filepath
svg_writer.write("underlay")
return svg_path
@@ -332,12 +332,12 @@ class CreateDrawing(bpy.types.Operator):
else:
svg_writer.human_scale = human_scale
drawing_style = bpy.context.scene.DocProperties.drawing_styles[
drawing_style = context.scene.DocProperties.drawing_styles[
camera.data.BIMCameraProperties.active_drawing_style_index
]
render = bpy.context.scene.render
if self.is_landscape():
render = context.scene.render
if self.is_landscape(render):
width = camera.data.ortho_scale
height = width / render.resolution_x * render.resolution_y
else:
@@ -346,7 +346,7 @@ class CreateDrawing(bpy.types.Operator):
svg_writer.scale = float(numerator) / float(denominator)
svg_writer.output = svg_path
svg_writer.data_dir = bpy.context.scene.BIMProperties.data_dir
svg_writer.data_dir = context.scene.BIMProperties.data_dir
svg_writer.vector_style = drawing_style.vector_style
svg_writer.camera = camera
svg_writer.camera_width = width
@@ -391,11 +391,11 @@ class CreateDrawing(bpy.types.Operator):
svg_writer.write("annotation")
return svg_writer.output
def is_landscape(self):
return bpy.context.scene.render.resolution_x > bpy.context.scene.render.resolution_y
def is_landscape(self, render):
return render.resolution_x > render.resolution_y
def get_view_3d(self):
for area in bpy.context.screen.areas:
def get_view_3d(self, areas):
for area in areas:
if area.type != "VIEW_3D":
continue
for space in area.spaces:
@@ -512,7 +512,7 @@ class AddAnnotation(bpy.types.Operator):
bpy.ops.bim.update_representation(obj=obj.name)
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = obj
context.view_layer.objects.active = obj
obj.select_set(True)
bpy.ops.object.mode_set(mode="EDIT")
return {"FINISHED"}
@@ -525,11 +525,12 @@ class AddSheet(bpy.types.Operator):
# TODO: check undo redo
def execute(self, context):
new = bpy.context.scene.DocProperties.sheets.add()
new.name = "{} - SHEET".format(len(bpy.context.scene.DocProperties.sheets))
scene = context.scene
new = scene.DocProperties.sheets.add()
new.name = "{} - SHEET".format(len(scene.DocProperties.sheets))
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
sheet_builder.create(new.name, bpy.context.scene.DocProperties.titleblock)
sheet_builder.data_dir = scene.BIMProperties.data_dir
sheet_builder.create(new.name, scene.DocProperties.titleblock)
return {"FINISHED"}
@@ -538,11 +539,11 @@ class OpenSheet(bpy.types.Operator):
bl_label = "Open Sheet"
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
open_with_user_command(
bpy.context.preferences.addons["blenderbim"].preferences.svg_command,
context.preferences.addons["blenderbim"].preferences.svg_command,
os.path.join(
bpy.context.scene.BIMProperties.data_dir, "sheets", props.sheets[props.active_sheet_index].name + ".svg"
context.scene.BIMProperties.data_dir, "sheets", props.sheets[props.active_sheet_index].name + ".svg"
),
)
return {"FINISHED"}
@@ -555,9 +556,9 @@ class AddDrawingToSheet(bpy.types.Operator):
# TODO: check undo redo
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
sheet_builder.data_dir = context.scene.BIMProperties.data_dir
try:
sheet_builder.add_drawing(
props.drawings[props.active_drawing_index].name, props.sheets[props.active_sheet_index].name
@@ -573,17 +574,18 @@ class CreateSheets(bpy.types.Operator):
# TODO: check undo redo
def execute(self, context):
props = bpy.context.scene.DocProperties
scene = context.scene
props = scene.DocProperties
name = props.sheets[props.active_sheet_index].name
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
sheet_builder.data_dir = scene.BIMProperties.data_dir
sheet_builder.build(name)
svg2pdf_command = bpy.context.preferences.addons["blenderbim"].preferences.svg2pdf_command
svg2dxf_command = bpy.context.preferences.addons["blenderbim"].preferences.svg2dxf_command
svg2pdf_command = context.preferences.addons["blenderbim"].preferences.svg2pdf_command
svg2dxf_command = context.preferences.addons["blenderbim"].preferences.svg2dxf_command
if svg2pdf_command:
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "build", name)
path = os.path.join(scene.BIMProperties.data_dir, "build", name)
svg = os.path.join(path, name + ".svg")
pdf = os.path.join(path, name + ".pdf")
# With great power comes great responsibility. Example:
@@ -593,7 +595,7 @@ class CreateSheets(bpy.types.Operator):
subprocess.run(command)
if svg2dxf_command:
path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "build", name)
path = os.path.join(scene.BIMProperties.data_dir, "build", name)
svg = os.path.join(path, name + ".svg")
eps = os.path.join(path, name + ".eps")
dxf = os.path.join(path, name + ".dxf")
@@ -605,11 +607,11 @@ class CreateSheets(bpy.types.Operator):
subprocess.run(command)
if svg2pdf_command:
open_with_user_command(bpy.context.preferences.addons["blenderbim"].preferences.pdf_command, pdf)
open_with_user_command(context.preferences.addons["blenderbim"].preferences.pdf_command, pdf)
else:
open_with_user_command(
bpy.context.preferences.addons["blenderbim"].preferences.svg_command,
os.path.join(bpy.context.scene.BIMProperties.data_dir, "build", name, name + ".svg"),
context.preferences.addons["blenderbim"].preferences.svg_command,
os.path.join(scene.BIMProperties.data_dir, "build", name, name + ".svg"),
)
return {"FINISHED"}
@@ -621,8 +623,8 @@ class OpenView(bpy.types.Operator):
def execute(self, context):
open_with_user_command(
bpy.context.preferences.addons["blenderbim"].preferences.svg_command,
os.path.join(bpy.context.scene.BIMProperties.data_dir, "diagrams", self.view + ".svg"),
context.preferences.addons["blenderbim"].preferences.svg_command,
os.path.join(context.scene.BIMProperties.data_dir, "diagrams", self.view + ".svg"),
)
return {"FINISHED"}
@@ -634,13 +636,13 @@ class OpenViewCamera(bpy.types.Operator):
view_name: bpy.props.StringProperty()
def execute(self, context):
new_drawing_index = bpy.context.scene.DocProperties.drawings.find(self.view_name)
bpy.context.scene.DocProperties.active_drawing_index = new_drawing_index
drawing = bpy.context.scene.DocProperties.drawings[new_drawing_index]
bpy.context.view_layer.objects.active = drawing.camera
new_drawing_index = context.scene.DocProperties.drawings.find(self.view_name)
context.scene.DocProperties.active_drawing_index = new_drawing_index
drawing = context.scene.DocProperties.drawings[new_drawing_index]
context.view_layer.objects.active = drawing.camera
bpy.ops.object.select_all(action="DESELECT")
drawing.camera.select_set(True)
for area in bpy.context.screen.areas:
for area in context.screen.areas:
if area.ui_type == "PROPERTIES":
for space in area.spaces:
space.context = "DATA"
@@ -654,22 +656,22 @@ class ActivateView(bpy.types.Operator):
drawing_index: bpy.props.IntProperty()
def execute(self, context):
camera = bpy.context.scene.DocProperties.drawings[self.drawing_index].camera
camera = context.scene.DocProperties.drawings[self.drawing_index].camera
if not camera:
return {"FINISHED"}
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
area = next(area for area in context.screen.areas if area.type == "VIEW_3D")
is_local_view = area.spaces[0].local_view is not None
if is_local_view:
bpy.ops.view3d.localview()
bpy.context.scene.camera = camera
context.scene.camera = camera
bpy.ops.view3d.localview()
else:
bpy.context.scene.camera = camera
context.scene.camera = camera
area.spaces[0].region_3d.view_perspective = "CAMERA"
views_collection = bpy.data.collections.get("Views")
for collection in views_collection.children:
# We assume the project collection is at the top level
for project_collection in bpy.context.view_layer.layer_collection.children:
for project_collection in context.view_layer.layer_collection.children:
# We assume a convention that the 'Views' collection is directly
# in the project collection
if (
@@ -678,7 +680,7 @@ class ActivateView(bpy.types.Operator):
):
project_collection.children["Views"].children[collection.name].hide_viewport = True
bpy.data.collections.get(collection.name).hide_render = True
bpy.context.view_layer.layer_collection.children["Views"].children[
context.view_layer.layer_collection.children["Views"].children[
camera.users_collection[0].name
].hide_viewport = False
bpy.data.collections.get(camera.users_collection[0].name).hide_render = False
@@ -694,7 +696,7 @@ class SelectDocIfcFile(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.scene.DocProperties.ifc_files[self.index].name = self.filepath
context.scene.DocProperties.ifc_files[self.index].name = self.filepath
return {"FINISHED"}
def invoke(self, context, event):
@@ -708,7 +710,7 @@ class GenerateReferences(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
self.camera = bpy.context.scene.camera
self.camera = context.scene.camera
self.filter_potential_references()
if self.camera.data.BIMCameraProperties.target_view == "PLAN_VIEW":
self.generate_grids()
@@ -777,7 +779,7 @@ class ResizeText(bpy.types.Operator):
# TODO: check undo redo
def execute(self, context):
for obj in bpy.context.scene.camera.users_collection[0].objects:
for obj in context.scene.camera.users_collection[0].objects:
if isinstance(obj.data, bpy.types.TextCurve):
annotation.Annotator.resize_text(obj)
return {"FINISHED"}
@@ -789,7 +791,7 @@ class AddVariable(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
bpy.context.active_object.data.BIMTextProperties.variables.add()
context.active_object.data.BIMTextProperties.variables.add()
return {"FINISHED"}
@@ -800,7 +802,7 @@ class RemoveVariable(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.active_object.data.BIMTextProperties.variables.remove(self.index)
context.active_object.data.BIMTextProperties.variables.remove(self.index)
return {"FINISHED"}
@@ -810,8 +812,8 @@ class PropagateTextData(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
source = bpy.context.active_object
for obj in bpy.context.selected_objects:
source = context.active_object
for obj in context.selected_objects:
if obj == source:
continue
obj.data.body = source.data.body
@@ -834,7 +836,7 @@ class RemoveDrawing(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
camera = props.drawings[self.index].camera
collection = camera.users_collection[0]
for obj in collection.objects:
@@ -850,7 +852,7 @@ class AddDrawingStyle(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
new = bpy.context.scene.DocProperties.drawing_styles.add()
new = context.scene.DocProperties.drawing_styles.add()
new.name = "New Drawing Style"
return {"FINISHED"}
@@ -862,7 +864,7 @@ class RemoveDrawingStyle(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.scene.DocProperties.drawing_styles.remove(self.index)
context.scene.DocProperties.drawing_styles.remove(self.index)
return {"FINISHED"}
@@ -924,11 +926,12 @@ class ActivateDrawingStyle(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
if context.scene.camera.data.BIMCameraProperties.active_drawing_style_index < len(
bpy.context.scene.DocProperties.drawing_styles
scene = context.scene
if scene.camera.data.BIMCameraProperties.active_drawing_style_index < len(
scene.DocProperties.drawing_styles
):
self.drawing_style = bpy.context.scene.DocProperties.drawing_styles[
context.scene.camera.data.BIMCameraProperties.active_drawing_style_index
self.drawing_style = scene.DocProperties.drawing_styles[
scene.camera.data.BIMCameraProperties.active_drawing_style_index
]
self.set_raster_style()
self.set_query()
@@ -1039,7 +1042,7 @@ class RemoveSheet(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
props.sheets.remove(self.index)
return {"FINISHED"}
@@ -1050,8 +1053,8 @@ class AddSchedule(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
new = bpy.context.scene.DocProperties.schedules.add()
new.name = "SCHEDULE {}".format(len(bpy.context.scene.DocProperties.schedules))
new = context.scene.DocProperties.schedules.add()
new.name = "SCHEDULE {}".format(len(context.scene.DocProperties.schedules))
return {"FINISHED"}
@@ -1062,7 +1065,7 @@ class RemoveSchedule(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
props.schedules.remove(self.index)
return {"FINISHED"}
@@ -1076,7 +1079,7 @@ class SelectScheduleFile(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
props.schedules[props.active_schedule_index].file = self.filepath
return {"FINISHED"}
@@ -1090,12 +1093,12 @@ class BuildSchedule(bpy.types.Operator):
bl_label = "Build Schedule"
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
schedule = props.schedules[props.active_schedule_index]
schedule_creator = scheduler.Scheduler()
outfile = os.path.join(bpy.context.scene.BIMProperties.data_dir, "schedules", schedule.name + ".svg")
outfile = os.path.join(context.scene.BIMProperties.data_dir, "schedules", schedule.name + ".svg")
schedule_creator.schedule(schedule.file, outfile)
open_with_user_command(bpy.context.preferences.addons["blenderbim"].preferences.svg_command, outfile)
open_with_user_command(context.preferences.addons["blenderbim"].preferences.svg_command, outfile)
return {"FINISHED"}
@@ -1106,9 +1109,9 @@ class AddScheduleToSheet(bpy.types.Operator):
# TODO: check undo redo
def execute(self, context):
props = bpy.context.scene.DocProperties
props = context.scene.DocProperties
sheet_builder = sheeter.SheetBuilder()
sheet_builder.data_dir = bpy.context.scene.BIMProperties.data_dir
sheet_builder.data_dir = context.scene.BIMProperties.data_dir
sheet_builder.add_schedule(
props.schedules[props.active_schedule_index].name, props.sheets[props.active_sheet_index].name
)
@@ -1121,7 +1124,7 @@ class AddDrawingStyleAttribute(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
props = bpy.context.scene.camera.data.BIMCameraProperties
props = context.scene.camera.data.BIMCameraProperties
context.scene.DocProperties.drawing_styles[props.active_drawing_style_index].attributes.add()
return {"FINISHED"}
@@ -1133,7 +1136,7 @@ class RemoveDrawingStyleAttribute(bpy.types.Operator):
index: bpy.props.IntProperty()
def execute(self, context):
props = bpy.context.scene.camera.data.BIMCameraProperties
props = context.scene.camera.data.BIMCameraProperties
context.scene.DocProperties.drawing_styles[props.active_drawing_style_index].attributes.remove(self.index)
return {"FINISHED"}
@@ -1161,9 +1164,9 @@ class CleanWireframes(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
objects = bpy.data.objects
if bpy.context.selected_objects:
objects = bpy.context.selected_objects
objects = context.scene.objects
if context.selected_objects:
objects = context.selected_objects
for obj in objects:
if not isinstance(obj.data, bpy.types.Mesh):
continue
@@ -57,10 +57,10 @@ def getDiagramScales(self, context):
global diagram_scales_enum
if (
len(diagram_scales_enum) < 1
or (bpy.context.scene.unit_settings.system == "IMPERIAL" and len(diagram_scales_enum) == 13)
or (bpy.context.scene.unit_settings.system == "METRIC" and len(diagram_scales_enum) == 31)
or (context.scene.unit_settings.system == "IMPERIAL" and len(diagram_scales_enum) == 13)
or (context.scene.unit_settings.system == "METRIC" and len(diagram_scales_enum) == 31)
):
if bpy.context.scene.unit_settings.system == "IMPERIAL":
if context.scene.unit_settings.system == "IMPERIAL":
diagram_scales_enum = [
("CUSTOM", "Custom", ""),
("1'=1'-0\"|1/1", "1'=1'-0\"", ""),
@@ -234,13 +234,17 @@ class EnableEditingUnit(bpy.types.Operator):
props = context.scene.BIMUnitProperties
props.unit_attributes.clear()
data = Data.units[self.unit]
blenderbim.bim.helper.import_attributes(data["type"], props.unit_attributes, data, self.import_attributes)
blenderbim.bim.helper.import_attributes(
data["type"],
props.unit_attributes,
data,
lambda name, prop, data: self.import_attributes(name, prop, data, context))
props.active_unit_id = self.unit
return {"FINISHED"}
def import_attributes(self, name, prop, data):
def import_attributes(self, name, prop, data, context):
if name == "Dimensions":
new = bpy.context.scene.BIMUnitProperties.unit_attributes.add()
new = context.scene.BIMUnitProperties.unit_attributes.add()
new.name = name
new.is_null = data[name] is None
new.is_optional = False
+2 -2
View File
@@ -64,8 +64,8 @@ class ExportIFC(bpy.types.Operator):
def _execute(self, context):
start = time.time()
logger = logging.getLogger("ExportIFC")
path_log = os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log")
if not os.access(bpy.context.scene.BIMProperties.data_dir, os.W_OK):
path_log = os.path.join(context.scene.BIMProperties.data_dir, "process.log")
if not os.access(context.scene.BIMProperties.data_dir, os.W_OK):
path_log = os.path.join(tempfile.mkdtemp(), "process.log")
logging.basicConfig(
filename=path_log,