利用者:Levon/open in window
2014年1月8日 (水) 02:25時点におけるwiki>Plasmasolutionsによる版
This script adds a "open in finder/windows explorer/nautilus" link to the file menu, image editor image menu and text editor Text menu.
So far only tested in OSX10.8, 10.9 and Ubuntu 13.10 64bit
please let me know if it works in windows.
bl_info = {
"name": "open in window",
"author": "Levon Hudson",
"version": (0, 9, 0, 0),
"blender": (2, 6, 0),
"location": "File-reveal in window, Image editor-Image-reveal in window, Text editor-Text-reveal in window",
"description": "Opens the current file location in a system window (osx-finder,windows-explorer,linux-xdg-open. works on blend file, text files and image files",
"wiki_url": "",
"tracker_url": "",
"category": "System"}
import bpy
import sys
#windows
if sys.platform == 'win32' or sys.platform=='cygwin':
sys_prog = "Explorer"
def open_window(path):
import subprocess
if path == '':
return False
else:
subprocess.Popen("explorer", "/select",path)
return True
#OSX
elif sys.platform =='darwin':
sys_prog = "Finder"
def open_window(path):
import subprocess
if path == '':
return False
else:
subprocess.Popen(["open", "-R", path])
return True
#Linux
elif sys.platform.startswith('linux'):
sys_prog = "Nautilus"
def open_window(path):
import subprocess
import os
path, filename = os.path.split(path)
if path == '':
return False
else:
subprocess.Popen(['xdg-open', path])
class Image_Finder(bpy.types.Operator):
"""opens current blend file in window"""
bl_idname = "file.image_window"
bl_label = "Open in %s" %sys_prog
def execute(self, context):
try:
file_to_show = bpy.path.abspath(bpy.context.edit_image.filepath)
except:
self.report({'INFO'}, "no file open")
complete= open_window(file_to_show)
if complete==0:
self.report({'INFO'}, "file is not saved")
return {'FINISHED'}
else:
return {'FINISHED'}
class Blend_Finder(bpy.types.Operator):
"""opens current blend file in window"""
bl_idname = "file.blend_window"
bl_label = "Open in %s" %sys_prog
def execute(self, context):
try:
file_to_show = bpy.path.abspath(bpy.context.blend_data.filepath)
except:
self.report({'INFO'}, "no file open")
return {'FINISHED'}
complete= open_window(file_to_show)
if complete==0:
self.report({'INFO'}, "file is not saved")
return {'FINISHED'}
else:
return {'FINISHED'}
class Text_Finder(bpy.types.Operator):
"""opens current blend file in window"""
bl_idname = "file.text_window"
bl_label = "Open in %s" %sys_prog
def execute(self, context):
try:
file_to_show = bpy.path.abspath(bpy.context.edit_text.filepath)
except:
self.report({'INFO'}, "no file open")
return {'FINISHED'}
complete= open_window(file_to_show)
if complete==0:
self.report({'INFO'}, "file is not saved")
return {'FINISHED'}
else:
return {'FINISHED'}
def blend_file(self, context):
self.layout.operator("file.blend_window", icon='FILE_FOLDER')
def text_file(self, context):
self.layout.operator("file.text_window", icon='FILE_FOLDER')
def image_file(self, context):
self.layout.operator("file.image_window", icon='FILE_FOLDER')
def register():
bpy.utils.register_class(Blend_Finder)
bpy.utils.register_class(Text_Finder)
bpy.utils.register_class(Image_Finder)
bpy.types.INFO_MT_file.append(blend_file)
bpy.types.TEXT_MT_text.append(text_file)
bpy.types.IMAGE_MT_image.append(image_file)
def unregister():
bpy.utils.unregister_class(Blend_Finder)
bpy.utils.unregister_class(Text_Finder)
bpy.utils.unregister_class(Image_Finder)
bpy.types.INFO_MT_file.remove(blend_file)
bpy.types.TEXT_MT_text.remove(text_file)
bpy.types.IMAGE_MT_image.remove(image_file)
if __name__ == "__main__":
register()