Great example pink vertex. I already wondered if it is possible to go the reverse way to the “set camera to view” command
There wasn’t only a problem with ortho view, but also persp. The view_distance needs to be reset to ~15, or you’ll end up in vast space after reset if you rotate view. The view_distance needs to be reset to ~15, or you’ll end up in vast space after reset if you rotate view.
Yup, that was what happened to me. The rv3d.view_distance = 10 line did the trick. And yes, it’s around 15 as i just found out ^^
Here’s the script to check the current matrix and distance:
import bpy
view_matrix = ((0.41, -0.4017, 0.8188, 0.0),
(0.912, 0.1936, -0.3617, 0.0),
(-0.0133, 0.8959, 0.4458, 0.0),
(0.0, 0.0, -14.9892, 1.0))
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
rv3d = area.spaces[0].region_3d
if rv3d is not None:
for vector in rv3d.view_matrix :
print(view_matrix)
distance = area.spaces[0].region_3d.view_distance
print(distance)
Post your final script when it’s ready, I’ll wait with mine, so you really learn something
Will do. And i have learnt lots in the last three days since i touched Blender Python. My head already explodes, heh. But i still have a very long way to go as i just noticed.
I just stumbled across the next problem. The ortho views. We need other view_matrices here. One for every ortho view it seems. Work for tomorrow ^^
This is the current state of the whole script at the moment. Any tips at the menu stuff and all the things around? Did i miss something?
I have one problem at the keymap code. This line here gives me an error:
kmi.properties.total = 4
What does this line do? And why does it give an error? What did i overlook? It works fine in the example code from the addon tutorial that can be found here: http://www.blender.org/documentation/blender_python_api_2_65_5/info_tutorial_addon.html
The error message in the console is: AttributeError: 'View_OT_reset_view has no attribute ‘total’
#Big Thanks for the help with the code goes to pink vertex and CoDEmanX at the Blenderartists forum
#I have basically just copied their code. And made a plugin out of it.
bl_info = {
"name": "Reset View",
"description": "Resets the views of all 3D windows to standard view",
"author": "Reiner 'Tiles' Prokein",
"version": (0, 5),
"blender": (2, 69, 0),
"location": "View3D > View",
"warning": "", # used for warning icon and text in addons panel
## not yet ...
# "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"
# "Scripts/My_Script",
"category": "View"}
import bpy
class ResetView(bpy.types.Operator):
"""Reset View"""
bl_idname = "view.reset_view"
bl_label = "Reset View"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
view_matrix = ((0.41, -0.4017, 0.8188, 0.0), # This is the view matrix from Factory settings
(0.912, 0.1936, -0.3617, 0.0),
(-0.0133, 0.8959, 0.4458, 0.0),
(0.0, 0.0, -14.9892, 1.0))
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
rv3d = area.spaces[0].region_3d
if rv3d is not None:
# Here happens the magic. Distance and Location and Rotation gets reset
rv3d.view_distance = 15 # This is the original distance to the zero point from Factory settings.
rv3d.view_matrix = view_matrix # This resets the location and rotation back to the initial view matrix values
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(ResetView.bl_idname)
# store keymaps here to access after registration
addon_keymaps = []
def register():
bpy.utils.register_class(ResetView)
bpy.types.VIEW3D_MT_view.append(menu_func)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='View Mode', space_type='EMPTY')
kmi = km.keymap_items.new(ResetView.bl_idname, 'ONE', 'PRESS', ctrl=False, shift=True)
# kmi.properties.total = 4 # spits an error, and i have no idea why ...
addon_keymaps.append(km)
def unregister():
bpy.utils.unregister_class(ResetView)
bpy.types.VIEW3D_MT_view.remove(menu_func)
# handle the keymap
wm = bpy.context.window_manager
for km in addon_keymaps:
wm.keyconfigs.addon.keymaps.remove(km)
# clear the list
del addon_keymaps[:]
if __name__ == "__main__":
register()