# Untitled

a guest
Sep 30th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import bpy
2. from bpy.types import Operator, Macro
3. from bpy_extras import view3d_utils
4. from mathutils import Vector
5. import rna_keymap_ui
6. from bpy.props import (
7. EnumProperty,
8. )
9.
10. bl_info = {
11. "name": "view snap",
12. "location": "View3D > view snap",
13. "description": "Snap View",
15. "version": (0, 3),
16. "blender": (2, 80, 0),
17. "category": "View3D",
18. }
19. PREFS = None
20.
21.
22. def getView(self, context, event):
23. region = context.region
24. rv3d = context.region_data
25. coord = event.mouse_region_x, event.mouse_region_y
26. return rv3d.view_rotation * Vector((0.0, 0.0, -1.0))
27.
28.
29. def findView(self, context, event):
30. vector = getView(self, context, event)
31. if vector == Vector((0.0, -1.0, 0.0)):
33. elif vector == Vector((0.0, 1.0, 0.0)):
35. elif vector == Vector((1.0, 0.0, 0.0)):
37. elif vector == Vector((-1.0, 0.0, 0.0)):
39. elif vector == Vector((0.0, 0.0, 1.0)):
41. elif vector == Vector((0.0, 0.0, -1.0)):
43.
44.
45. def ExcludeAxis(self, context, vector):
46. x = vector[0]
47. y = vector[1]
48. z = vector[2]
49.
50. if abs(x) > abs(y) and abs(x) > abs(z):
51. return 'x', x
52. elif abs(y) > abs(x) and abs(y) > abs(z):
53. return 'y', y
54. elif abs(z) > abs(x) and abs(z) > abs(y):
55. return 'z', z
56.
57.
58. def findView2(self, context, axis, ax):
59. if axis == 'x':
60. if ax < 0:
62. else:
64. elif axis == 'y':
65. if ax < 0:
67. else:
69. elif axis == 'z':
70. if ax < 0:
72. else:
74.
75.
76. class SnapView_OT_darcvizer(bpy.types.Operator):
77. """Border Occlusion selection """
78. bl_idname = "view3d.snap_view_ot_darcvizer"
79. bl_label = "SnapView"
80.
81. def invoke(self, context, event):
82.
83. if PREFS.Mode == 'blender':
84. if event.ctrl:
85. vector = getView(self, context, event)
86. name, value = ExcludeAxis(self, context, vector)
87. findView2(self, context, name, value)
88. elif PREFS.Mode == 'maya':
89. if event.shift:
90. vector = getView(self, context, event)
91. name, value = ExcludeAxis(self, context, vector)
92. findView2(self, context, name, value)
93. elif PREFS.Mode == '3ds max':
94. if event.shift:
95. vector = getView(self, context, event)
96. name, value = ExcludeAxis(self, context, vector)
97. findView2(self, context, name, value)
98.
99. return {'FINISHED'}
100.
101.
102. class ViewMacro_ot_darcvizer(Macro):
103. bl_idname = 'view3d.view_snap_ot_darcvizer'
104. bl_label = 'view_snap'
105. #bl_options = {'REGISTER', 'UNDO'}
106.
107. def execute(self, context):
108. ViewMacro.define('VIEW3D_OT_rotate')
109. return {'FINISHED'}
110.
111.
112. def use_cashes(self, context):
113. self.caches_valid = True
114.
115.
117. bl_idname = __name__
118. bl_options = {'REGISTER'}
119. Mode = EnumProperty(
120. items=[('blender', "Blender", "Press ctrl after middle mouse button "),
121. ('maya', "Maya", "Press shift after left mouse button "),
122. ('3ds max', "3DS Max", "Press shift after middle mouse button")],
123. name="Rotate mode",
124. default='maya',
125. # update=use_cashes
126. )
127. caches_valid = True
128.
129. def draw(self, context):
130. layout = self.layout
131. layout.prop(self, "Mode")
132.
133.
134.
135.
136.
137. ViewMacro_ot_darcvizer.define('view3d.snap_view_ot_darcvizer')
138. ViewMacro_ot_darcvizer.define('view3d.view_snap_ot_darcvizer')
139.
140.