diff --git a/scripts/startup/bl_operators/anim.py b/scripts/startup/bl_operators/anim.py index 3e8db3647c4..054fdcc2e2a 100644 --- a/scripts/startup/bl_operators/anim.py +++ b/scripts/startup/bl_operators/anim.py @@ -533,8 +533,9 @@ def _armature_from_context(context): pin_armature = getattr(context, "armature", None) if pin_armature: return pin_armature - if context.object and context.object.type == 'ARMATURE': - return context.object.data + ob = context.object + if ob and ob.type == 'ARMATURE': + return ob.data return None diff --git a/scripts/startup/bl_operators/geometry_nodes.py b/scripts/startup/bl_operators/geometry_nodes.py index 438ffe0785c..0ac3d141733 100644 --- a/scripts/startup/bl_operators/geometry_nodes.py +++ b/scripts/startup/bl_operators/geometry_nodes.py @@ -48,7 +48,8 @@ def geometry_node_group_empty_tool_new(context): group.use_fake_user = True group.is_tool = True - ob_type = context.object.type if context.object else 'MESH' + ob = context.object + ob_type = ob.type if ob else 'MESH' if ob_type == 'CURVES': group.is_type_curve = True elif ob_type == 'POINTCLOUD': @@ -56,7 +57,7 @@ def geometry_node_group_empty_tool_new(context): else: group.is_type_mesh = True - mode = context.object.mode if context.object else 'OBJECT' + mode = ob.mode if ob else 'OBJECT' if mode in {'SCULPT', 'SCULPT_CURVES'}: group.is_mode_sculpt = True elif mode == 'EDIT': diff --git a/scripts/startup/bl_operators/view3d.py b/scripts/startup/bl_operators/view3d.py index e71fe4aad99..7d1caa7bf3d 100644 --- a/scripts/startup/bl_operators/view3d.py +++ b/scripts/startup/bl_operators/view3d.py @@ -31,10 +31,11 @@ class VIEW3D_OT_edit_mesh_extrude_individual_move(Operator): def execute(self, context): from bpy_extras.object_utils import object_report_if_active_shape_key_is_locked - if object_report_if_active_shape_key_is_locked(context.object, self): + ob = context.object + if object_report_if_active_shape_key_is_locked(ob, self): return {'CANCELLED'} - mesh = context.object.data + mesh = ob.data select_mode = context.tool_settings.mesh_select_mode totface = mesh.total_face_sel @@ -99,10 +100,11 @@ class VIEW3D_OT_edit_mesh_extrude_move(Operator): def extrude_region(operator, context, use_vert_normals, dissolve_and_intersect): from bpy_extras.object_utils import object_report_if_active_shape_key_is_locked - if object_report_if_active_shape_key_is_locked(context.object, operator): + ob = context.object + if object_report_if_active_shape_key_is_locked(ob, operator): return {'CANCELLED'} - mesh = context.object.data + mesh = ob.data totface = mesh.total_face_sel totedge = mesh.total_edge_sel diff --git a/scripts/startup/bl_ui/properties_data_grease_pencil.py b/scripts/startup/bl_ui/properties_data_grease_pencil.py index 39e3ec6fe06..bafabca9ea4 100644 --- a/scripts/startup/bl_ui/properties_data_grease_pencil.py +++ b/scripts/startup/bl_ui/properties_data_grease_pencil.py @@ -82,7 +82,8 @@ class GREASE_PENCIL_MT_grease_pencil_add_layer_extra(Menu): def draw(self, context): layout = self.layout - grease_pencil = context.object.data + ob = context.object + grease_pencil = ob.data space = context.space_data if space.type == 'PROPERTIES': diff --git a/scripts/startup/bl_ui/properties_grease_pencil_common.py b/scripts/startup/bl_ui/properties_grease_pencil_common.py index 57cc460e403..a1d5a63194c 100644 --- a/scripts/startup/bl_ui/properties_grease_pencil_common.py +++ b/scripts/startup/bl_ui/properties_grease_pencil_common.py @@ -431,8 +431,9 @@ class AnnotationDataPanel: def draw(self, context): layout = self.layout layout.use_property_decorate = False + space = context.space_data - is_clip_editor = context.space_data.type == 'CLIP_EDITOR' + is_clip_editor = space.type == 'CLIP_EDITOR' # Grease Pencil owner. gpd_owner = context.annotation_data_owner @@ -443,7 +444,7 @@ class AnnotationDataPanel: col = layout.column() col.label(text="Data Source:") row = col.row() - row.prop(context.space_data, "annotation_source", expand=True) + row.prop(space, "annotation_source", expand=True) # Only allow adding annotation ID if its owner exist if context.annotation_data_owner is None: diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index bd8a03fb8e5..8a128d9f3d0 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -139,17 +139,20 @@ class VIEW3D_HT_tool_header(Header): return row, sub if mode_string == 'EDIT_ARMATURE': + ob = context.object _row, sub = row_for_mirror() - sub.prop(context.object.data, "use_mirror_x", text="X", toggle=True) + sub.prop(ob.data, "use_mirror_x", text="X", toggle=True) elif mode_string == 'POSE': + ob = context.object _row, sub = row_for_mirror() - sub.prop(context.object.pose, "use_mirror_x", text="X", toggle=True) + sub.prop(ob.pose, "use_mirror_x", text="X", toggle=True) elif mode_string in {'EDIT_MESH', 'PAINT_WEIGHT', 'SCULPT', 'PAINT_VERTEX', 'PAINT_TEXTURE'}: # Mesh Modes, Use Mesh Symmetry + ob = context.object row, sub = row_for_mirror() - sub.prop(context.object, "use_mesh_mirror_x", text="X", toggle=True) - sub.prop(context.object, "use_mesh_mirror_y", text="Y", toggle=True) - sub.prop(context.object, "use_mesh_mirror_z", text="Z", toggle=True) + sub.prop(ob, "use_mesh_mirror_x", text="X", toggle=True) + sub.prop(ob, "use_mesh_mirror_y", text="Y", toggle=True) + sub.prop(ob, "use_mesh_mirror_z", text="Z", toggle=True) if mode_string == 'EDIT_MESH': tool_settings = context.tool_settings layout.prop(tool_settings, "use_mesh_automerge", text="") @@ -160,12 +163,13 @@ class VIEW3D_HT_tool_header(Header): elif mode_string == 'PAINT_VERTEX': row.popover(panel="VIEW3D_PT_tools_vertexpaint_symmetry_for_topbar", text="") elif mode_string == 'SCULPT_CURVES': + ob = context.object _row, sub = row_for_mirror() - sub.prop(context.object.data, "use_mirror_x", text="X", toggle=True) - sub.prop(context.object.data, "use_mirror_y", text="Y", toggle=True) - sub.prop(context.object.data, "use_mirror_z", text="Z", toggle=True) + sub.prop(ob.data, "use_mirror_x", text="X", toggle=True) + sub.prop(ob.data, "use_mirror_y", text="Y", toggle=True) + sub.prop(ob.data, "use_mirror_z", text="Z", toggle=True) - layout.prop(context.object.data, "use_sculpt_collision", icon='MOD_PHYSICS', icon_only=True, toggle=True) + layout.prop(ob.data, "use_sculpt_collision", icon='MOD_PHYSICS', icon_only=True, toggle=True) # Expand panels from the side-bar as popovers. popover_kw = {"space_type": 'VIEW_3D', "region_type": 'UI', "category": "Tool"} @@ -373,19 +377,20 @@ class _draw_tool_settings_context_mode: if brush is None: return False + ob = context.object gp_settings = brush.gpencil_settings row = layout.row(align=True) settings = tool_settings.gpencil_paint row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True) - if context.object and brush.gpencil_tool in {'FILL', 'DRAW'}: + if ob and brush.gpencil_tool in {'FILL', 'DRAW'}: from bl_ui.properties_paint_common import ( brush_basic__draw_color_selector, ) brush_basic__draw_color_selector(context, layout, brush, gp_settings, None) - if context.object and brush.gpencil_tool == 'TINT': + if ob and brush.gpencil_tool == 'TINT': row.separator(factor=0.4) row.prop_with_popover(brush, "color", text="", panel="TOPBAR_PT_gpencil_vertexcolor") @@ -2717,6 +2722,8 @@ class VIEW3D_MT_object(Menu): def draw(self, context): layout = self.layout + ob = context.object + layout.menu("VIEW3D_MT_transform_object") layout.operator_menu_enum("object.origin_set", text="Set Origin", property="type") layout.menu("VIEW3D_MT_mirror") @@ -2752,7 +2759,7 @@ class VIEW3D_MT_object(Menu): layout.separator() layout.operator("object.shade_smooth") - if context.object and context.object.type == 'MESH': + if ob and ob.type == 'MESH': layout.operator("object.shade_smooth_by_angle") layout.operator("object.shade_flat") @@ -4101,9 +4108,10 @@ class VIEW3D_MT_bone_collections(Menu): @classmethod def poll(cls, context): - if not context.object or context.object.type != 'ARMATURE': + ob = context.object + if not (ob and ob.type == 'ARMATURE'): return False - if context.object.data.library: + if ob.data.library: return False return True @@ -4557,7 +4565,8 @@ class VIEW3D_MT_edit_mesh_extrude(Menu): tool_settings = context.tool_settings select_mode = tool_settings.mesh_select_mode - mesh = context.object.data + ob = context.object + mesh = ob.data if mesh.total_face_sel: layout.operator("view3d.edit_mesh_extrude_move_normal", text="Extrude Faces") @@ -7751,13 +7760,16 @@ class VIEW3D_PT_overlay_gpencil_options(Panel): @classmethod def poll(cls, context): - return context.object and context.object.type == 'GPENCIL' + ob = context.object + return ob and ob.type == 'GPENCIL' def draw(self, context): layout = self.layout view = context.space_data overlay = view.overlay + ob = context.object + layout.label(text={ 'PAINT_GPENCIL': iface_("Draw Grease Pencil"), 'EDIT_GPENCIL': iface_("Edit Grease Pencil"), @@ -7790,15 +7802,15 @@ class VIEW3D_PT_overlay_gpencil_options(Panel): sub.prop(overlay, "gpencil_fade_objects", text="Fade Inactive Objects", slider=True) sub.prop(overlay, "use_gpencil_fade_gp_objects", text="", icon='OUTLINER_OB_GREASEPENCIL') - if context.object.mode in {'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL', 'VERTEX_GPENCIL'}: + if ob.mode in {'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL', 'VERTEX_GPENCIL'}: split = layout.split() col = split.column() col.prop(overlay, "use_gpencil_edit_lines", text="Edit Lines") col = split.column() col.prop(overlay, "use_gpencil_multiedit_line_only", text="Only in Multiframe") - if context.object.mode == 'EDIT_GPENCIL': - gpd = context.object.data + if ob.mode == 'EDIT_GPENCIL': + gpd = ob.data split = layout.split() col = split.column() col.prop(overlay, "use_gpencil_show_directions") @@ -7811,10 +7823,10 @@ class VIEW3D_PT_overlay_gpencil_options(Panel): # Handles for Curve Edit layout.prop(overlay, "display_handle", text="Handles") - if context.object.mode == 'SCULPT_GPENCIL': + if ob.mode == 'SCULPT_GPENCIL': layout.prop(overlay, "vertex_opacity", text="Vertex Opacity", slider=True) - if context.object.mode in {'PAINT_GPENCIL', 'VERTEX_GPENCIL'}: + if ob.mode in {'PAINT_GPENCIL', 'VERTEX_GPENCIL'}: layout.label(text="Vertex Paint") row = layout.row() shading = VIEW3D_PT_shading.get_shading(context) @@ -7830,20 +7842,23 @@ class VIEW3D_PT_overlay_grease_pencil_options(Panel): @classmethod def poll(cls, context): - return context.object and context.object.type == 'GREASEPENCIL' + ob = context.object + return ob and ob.type == 'GREASEPENCIL' def draw(self, context): layout = self.layout view = context.space_data overlay = view.overlay + ob = context.object + layout.label(text={ 'PAINT_GREASE_PENCIL': iface_("Draw Grease Pencil"), 'EDIT_GREASE_PENCIL': iface_("Edit Grease Pencil"), 'OBJECT': iface_("Grease Pencil"), }[context.mode], translate=False) - if context.object.mode in {'EDIT'}: + if ob.mode in {'EDIT'}: split = layout.split() col = split.column() col.prop(overlay, "use_gpencil_edit_lines", text="Edit Lines") @@ -8729,7 +8744,7 @@ class TOPBAR_PT_gpencil_materials(GreasePencilMaterialsPanel, Panel): @classmethod def poll(cls, context): ob = context.object - return ob and (ob.type == 'GPENCIL' or ob.type == 'GREASEPENCIL') + return ob and ob.type in {'GPENCIL', 'GREASEPENCIL'} class TOPBAR_PT_gpencil_vertexcolor(GreasePencilVertexcolorPanel, Panel): diff --git a/scripts/startup/bl_ui/space_view3d_toolbar.py b/scripts/startup/bl_ui/space_view3d_toolbar.py index 96ae5403709..110a35b5cdf 100644 --- a/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -615,7 +615,7 @@ class VIEW3D_PT_slots_paint_canvas(SelectPaintSlotHelper, View3DPanel, Panel): def draw_header(self, context): paint = context.tool_settings.paint_mode ob = context.object - me = context.object.data + me = ob.data mat = ob.active_material label = iface_("Canvas") @@ -646,7 +646,8 @@ class VIEW3D_PT_slots_color_attributes(Panel): ) def draw(self, context): - mesh = context.object.data + ob = context.object + mesh = ob.data layout = self.layout row = layout.row() @@ -1124,7 +1125,9 @@ class VIEW3D_PT_sculpt_symmetry(Panel, View3DPaintPanel): sculpt = context.tool_settings.sculpt row = layout.row(align=True, heading="Mirror") - mesh = context.object.data + + ob = context.object + mesh = ob.data row.prop(mesh, "use_mirror_x", text="X", toggle=True) row.prop(mesh, "use_mirror_y", text="Y", toggle=True) row.prop(mesh, "use_mirror_z", text="Z", toggle=True) @@ -1167,14 +1170,16 @@ class VIEW3D_PT_curves_sculpt_symmetry(Panel, View3DPaintPanel): @classmethod def poll(cls, context): - return context.object and context.object.type == 'CURVES' + ob = context.object + return ob and ob.type == 'CURVES' def draw(self, context): layout = self.layout layout.use_property_split = True layout.use_property_decorate = False - curves = context.object.data + ob = context.object + curves = ob.data row = layout.row(align=True, heading="Mirror") row.prop(curves, "use_mirror_x", text="X", toggle=True) @@ -1211,11 +1216,13 @@ class VIEW3D_PT_tools_weightpaint_symmetry(Panel, View3DPaintPanel): tool_settings = context.tool_settings wpaint = tool_settings.weight_paint - mesh = context.object.data + + ob = context.object + mesh = ob.data layout.prop(mesh, "use_mirror_vertex_groups") - draw_vpaint_symmetry(layout, wpaint, context.object) + draw_vpaint_symmetry(layout, wpaint, ob) row = layout.row() row.active = mesh.use_mirror_vertex_groups @@ -1293,7 +1300,9 @@ class VIEW3D_PT_tools_vertexpaint_symmetry(Panel, View3DPaintPanel): tool_settings = context.tool_settings vpaint = tool_settings.vertex_paint - draw_vpaint_symmetry(layout, vpaint, context.object) + ob = context.object + + draw_vpaint_symmetry(layout, vpaint, ob) class VIEW3D_PT_tools_vertexpaint_symmetry_for_topbar(Panel): @@ -1358,7 +1367,8 @@ class VIEW3D_PT_tools_imagepaint_symmetry(Panel, View3DPaintPanel): col = split.column() row = col.row(align=True) - mesh = context.object.data + ob = context.object + mesh = ob.data row.prop(mesh, "use_mirror_x", text="X", toggle=True) row.prop(mesh, "use_mirror_y", text="Y", toggle=True) row.prop(mesh, "use_mirror_z", text="Z", toggle=True)