-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
75 lines (62 loc) · 2.12 KB
/
__init__.py
File metadata and controls
75 lines (62 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
bl_info = {
"name": "View Image Node",
"author": "Kenetics",
"version": (0, 1),
"blender": (3, 0, 0),
"location": "Node Editor > Context Menu",
"description": "View image node in image editor.",
"warning": "",
"wiki_url": "",
"category": "Node Editor"
}
import bpy
from bpy.props import EnumProperty, IntProperty, FloatVectorProperty, BoolProperty, FloatProperty, StringProperty, PointerProperty
from bpy.types import PropertyGroup, UIList, Operator, Panel, AddonPreferences
## Operators
class VIN_OT_view_image_node(Operator):
bl_idname = "vin.view_image_node"
bl_label = "View Image Node"
bl_options = {'REGISTER'}
@classmethod
def poll(cls, context):
return (
context.active_object and
context.active_object.active_material and
context.active_object.active_material.node_tree and
context.active_object.active_material.node_tree.nodes.active and
context.active_object.active_material.node_tree.nodes.active.image
)
def execute(self, context):
node = context.active_object.active_material.node_tree.nodes.active
if not (node.type == "TEX_IMAGE" and node.image):
return {'CANCELLED'}
for area in context.window.screen.areas:
if area.type == "IMAGE_EDITOR":
area.spaces[0].image = context.active_object.active_material.node_tree.nodes.active.image
break
else:
# if for loop finishes without breaking, this else will be called
bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
area = context.window_manager.windows[-1].screen.areas[0]
area.type = "IMAGE_EDITOR"
area.spaces[0].image = context.active_object.active_material.node_tree.nodes.active.image
return {'FINISHED'}
## Append to UI Helper Functions
def draw_func(self, context):
self.layout.operator(VIN_OT_view_image_node.bl_idname, icon="IMAGE_DATA")
## Register
classes = (
VIN_OT_view_image_node,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
## Append to UI
bpy.types.NODE_MT_context_menu.append(draw_func)
def unregister():
## Remove from UI
bpy.types.NODE_MT_context_menu.remove(draw_func)
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()