Skip to content

Instantly share code, notes, and snippets.

@williamchange
Created March 27, 2024 08:56
Show Gist options
  • Save williamchange/10d51910f38aaa293a694c07469da6bb to your computer and use it in GitHub Desktop.
Save williamchange/10d51910f38aaa293a694c07469da6bb to your computer and use it in GitHub Desktop.
Bring back 'View Offset' toggle in node editors for Blender 4.0+
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
bl_info = {
"name" : "View Offset Toggle",
"author" : "None",
"description" : "Restore 'View Offset' toggle in view menu for node editors",
"blender" : (4, 0, 0),
"version" : (0, 1, 0),
"location" : "Node Editor > View",
"warning" : "",
"doc_url": "",
"tracker_url": "",
"category" : "Node"
}
import bpy
from bpy.app.handlers import persistent
def sna_update_sna_view_offset(self, context):
bpy.context.preferences.edit.node_use_insert_offset = self.sna_view_offset
bpy.ops.wm.save_userpref()
def sna_add_to_node_mt_view(self, context):
layout = self.layout
layout.prop(bpy.context.scene, 'sna_view_offset', text='View Offset')
@persistent
def load_post_handler(dummy):
bpy.context.scene.sna_view_offset = bpy.context.preferences.edit.node_use_insert_offset
def register():
bpy.types.Scene.sna_view_offset = bpy.props.BoolProperty(
name='View Offset',
description='Automatically offset the following or previous nodes in a chain when inserting a new node',
default=False,
update=sna_update_sna_view_offset)
bpy.types.NODE_MT_view.prepend(sna_add_to_node_mt_view)
bpy.app.handlers.load_post.append(load_post_handler)
def unregister():
del bpy.types.Scene.sna_view_offset
bpy.types.NODE_MT_view.remove(sna_add_to_node_mt_view)
bpy.app.handlers.load_post.remove(load_post_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment