Skip to content

Instantly share code, notes, and snippets.

@Fweeb
Last active November 20, 2025 11:52
Show Gist options
  • Select an option

  • Save Fweeb/bb61c15139bff338cb17 to your computer and use it in GitHub Desktop.

Select an option

Save Fweeb/bb61c15139bff338cb17 to your computer and use it in GitHub Desktop.
Blender add-on for exposing the 3D View's rotation locking feature
# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# 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 2
# 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
# MERCHANTABILITY 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****
bl_info = {
"name": "Lock View",
"description": "Exposes rotation locking in the 3D View to a specific viewing angle",
"author": "Jason van Gumster (Fweeb)",
"version": (1, 0, 1),
"blender": (3, 0, 0),
"location": "3D View > Properties Region > View",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"}
import bpy
def lock_ui(self, context):
layout = self.layout
layout.prop(context.space_data.region_3d, 'lock_rotation', text='Lock View Rotation')
def register():
bpy.types.VIEW3D_PT_view3d_properties.append(lock_ui)
def unregister():
bpy.types.VIEW3D_PT_view3d_properties.remove(lock_ui)
if __name__ == "__main__":
register()
@Tibuq

Tibuq commented Jul 25, 2016

Copy link
Copy Markdown

Features I'd love to see:

  1. Don't prevent the ability to switch between views like top/right/front (numpad 1,3,7 by default), flip the view (numpad 9 by default) or switch between ortho and persp (numpad 5 by default) while view rotation is locked.
    -> ONLY prevent view rotation through mouse input. ('view3d.rotate')
  2. Add option to reuse 'Rotate View' ('view3d.rotate') hotkey for a different action while view rotation is locked.
    e.g. 'Rotate View' is bound to 'Right Mouse'. 'Right Mouse' does nothing while view rotation is locked. -> Let me bind 'Right Mouse' to 'Move View' while view rotation is locked but remain its original use while view rotation is not locked.

@danpolanco

Copy link
Copy Markdown

I just wanted to say good work.

@swordfighter79

Copy link
Copy Markdown

thanks that is exactly what I needed thanks alot it a great help

@iamtitere

Copy link
Copy Markdown

Thanks you so much!

Important if people wants to import it to Blender 2.8x, the code line

"blender": (2, 76, 0),

must be updated after importing to the blender version, so

"blender": (2, 80, 0),

and the menu is on the 3D View>right panel>View>Lock View Rotation

@Qhuenta

Qhuenta commented Jul 5, 2021

Copy link
Copy Markdown

Is there a way for this to work with Blender 2.81a?

@ithil

ithil commented Jan 23, 2022

Copy link
Copy Markdown

Is there a way for this to work with Blender 2.81a?

Yes, you simply need to update the line with the blender version as @iamtitere showed above to the version you're using.

For version 3.0.0 I've already done that so you could also just grab my fork: https://gist.github.com/ithil/ffc48aba19771d6850d1c2fc6a84d6c0

@Fweeb

Fweeb commented Jan 25, 2022

Copy link
Copy Markdown
Author

@ithil I've incorporated your update to this. Because the code is so short, I never thought to make a full-on repo for it. :) Thanks for pointing this out.

@shadkp

shadkp commented Apr 27, 2022

Copy link
Copy Markdown

Excellent to make the viewport a reference viewer in Blender !

@df-0

df-0 commented May 19, 2023

Copy link
Copy Markdown

Thanks for this! I'm using this for drawing with grease pencil, for which obviously you don't want to accidentally orbit the camera. However - this does also prevent you from being able to 2D roll the view (which is useful for drawing because often you want to roll the view to draw a particular curve more easily. Any way it could lock orbit but not roll? Thanks!

@Fweeb

Fweeb commented May 21, 2023

Copy link
Copy Markdown
Author

Hi there @df-0!

I think what you're looking for is technically possible, but would certainly require quite a bit more work. Right now, this add-on is just exposing functionality that's already built into Blender.

However, there is a workaround. I'm assuming that you're using Grease Pencil from the 2D Animation template. If you do that, you have a camera object and you're drawing from that camera's view. So if you want to rotate the view, you can just select the camera object and rotate that. It's a bit clunky because you have to hop out of Draw mode to do that, so maybe an add-on could be written that allows limited camera movement from within Edit mode. Maybe I'll play with that in the next week or so.

@df-0

df-0 commented May 23, 2023

Copy link
Copy Markdown

Cool - thanks. Yes, there's definitely some workarounds! I tend to use view roll a lot when drawing in blender - there's a reason it was built into old animation light tables, and it's easily accessible in stuff like photoshop (hold R) and toon boom (hold ctrl+alt) - and you currently don't need to have a camera for it to work, but of course it gets disabled by view lock. There's a request to add this as core functionality but these things can take a while! https://blender.community/c/rightclickselect/q2cbbc/?sorting=hot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment