I am trying to find a way to have only my selected object go into xray mode so that I can edit it while the other objects in the scene are still fully opaque. Xray mode functionality currently seems to turn everything transparent, and when adjusting the transparency setting, it applies it to all objects in the scene globally. Is there a way to do this without having to create materials and such? This is something I would just like to be able to toggle on and off via shortcut for editing purposes without having to go through a convoluted process. Thanks!
2 Answers
Thanks, I was aware of that but I wanted a simple toggle for ease of use. I have attached a script that works to that effect. If you install this via an addon, it will create a toggle button that will appear in the 3dviewport as a tab labelled Toggle Wireframe, which you can then assign as a keyboard shortcut.
Save the following code as toggle_wireframe.py
using notepad. Save it under your Blender user directory: C:\Users\"your username"\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons
In blender, install it as an addon and enable it. Once enabled, the button will pop up in your viewport. Right click and create shortcut. I hope this is helpful to others. Ignore the weird formatting here on the post and just copy all of the text into that notepad file.
import bpy
class OBJECT_OT_toggle_wireframe(bpy.types.Operator):
"""Toggle Wireframe Display"""
bl_idname = "object.toggle_wireframe"
bl_label = "Toggle Wireframe"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
mode = context.mode
if mode == 'OBJECT':
for obj in context.selected_objects:
obj.display_type = 'WIRE' if obj.display_type != 'WIRE' else 'SOLID'
elif mode == 'EDIT_MESH':
for obj in context.selected_objects:
obj.display_type = 'WIRE' if obj.display_type != 'WIRE' else 'SOLID'
return {'FINISHED'}
class VIEW3D_PT_custom_panel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Toggle Wireframe"
bl_idname = "VIEW3D_PT_custom_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Toggle Wireframe'
def draw(self, context):
layout = self.layout
layout.operator(OBJECT_OT_toggle_wireframe.bl_idname)
def register():
bpy.utils.register_class(OBJECT_OT_toggle_wireframe)
bpy.utils.register_class(VIEW3D_PT_custom_panel)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_toggle_wireframe)
bpy.utils.unregister_class(VIEW3D_PT_custom_panel)
if __name__ == "__main__":
register()
-
$\begingroup$ So Im having a different issue. Blender crashed on me while I was working and now the addon doesnt load. I tried uninstalling it and reinstalling it and still no luck. Blender says it added it but it does not show up under addons in preferences like it did before the crash. $\endgroup$– VsionsCommented Mar 27 at 17:50