1
0
mirror of https://github.com/drewcassidy/TexTools-Blender synced 2024-06-11 00:26:53 +00:00
Blender-TexTools/op_texture_open.py

52 lines
1.3 KiB
Python
Raw Normal View History

2019-06-08 23:42:50 +00:00
import bpy
import bmesh
import operator
import math
2019-12-24 19:59:46 +00:00
import os
import sys
import subprocess
2019-06-08 23:42:50 +00:00
from . import settings
from . import utilities_bake
class op(bpy.types.Operator):
2019-12-18 20:53:16 +00:00
bl_idname = "uv.textools_texture_open"
bl_label = "Open Texture"
bl_description = "Open the texture on the system"
2019-06-08 23:42:50 +00:00
2019-12-24 19:59:46 +00:00
name: bpy.props.StringProperty(
2019-12-18 20:53:16 +00:00
name="image name",
2019-12-24 19:59:46 +00:00
default=""
2019-12-18 20:53:16 +00:00
)
2019-06-08 23:42:50 +00:00
2019-12-18 20:53:16 +00:00
@classmethod
def poll(cls, context):
return True
2019-12-24 19:59:46 +00:00
2019-12-18 20:53:16 +00:00
def execute(self, context):
open_texture(self, context)
return {'FINISHED'}
2019-06-08 23:42:50 +00:00
def open_texture(self, context):
2019-12-18 20:53:16 +00:00
print("Info")
if self.name in bpy.data.images:
image = bpy.data.images[self.name]
2019-12-24 19:59:46 +00:00
2019-12-18 20:53:16 +00:00
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:
2019-12-24 19:59:46 +00:00
opener = "open" if sys.platform == "darwin" else "xdg-open"
2019-12-18 20:53:16 +00:00
subprocess.call([opener, path])
2019-06-08 23:42:50 +00:00
2019-12-24 19:59:46 +00:00
bpy.utils.register_class(op)