forked from franMarz/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_texture_open.py
42 lines (29 loc) · 978 Bytes
/
op_texture_open.py
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
import bpy
import os, sys, subprocess
class op(bpy.types.Operator):
bl_idname = "uv.textools_texture_open"
bl_label = "Open Texture"
bl_description = "Open the texture on the system"
name : bpy.props.StringProperty(
name="image name",
default = ""
)
@classmethod
def poll(cls, context):
return True
def execute(self, context):
open_texture(self, context)
return {'FINISHED'}
def open_texture(self, context):
if self.name in bpy.data.images:
image = bpy.data.images[self.name]
if image.filepath != "":
path = bpy.path.abspath(image.filepath)
# https://meshlogic.github.io/posts/blender/addons/extra-image-list/
# https://docs.blender.org/api/blender_python_api_2_78_release/bpy.ops.image.html
print("Open: {}".format(path))
if sys.platform == "win32":
os.startfile(path)
else:
opener ="open" if sys.platform == "darwin" else "xdg-open"
subprocess.call([opener, path])