Forked from anonymous/file_unfile_with_prefs.py
Last active
September 23, 2020 03:44
-
-
Save zeffii/de5f7112bf08bd794b04 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "FILL ME MO", | |
"author": "", | |
"version": (0, 1), | |
"blender": (2, 7, 6), | |
"category": "3D View" | |
} | |
import os | |
import bpy | |
from bpy_extras.io_utils import ExportHelper | |
# adding a PropertyGroup helps keep the Scene namespace clean. | |
# instead of adding 10 properties directly to Scene, you only | |
# add 1 group, which itself has a dot(.) lookup to get individual | |
# properties | |
class MyAddonProperties(bpy.types.PropertyGroup): | |
some_identifier = bpy.props.StringProperty() | |
some_integer_prop = bpy.props.IntProperty() | |
# ...etc .. | |
class WMFileRemover(bpy.types.Operator): | |
bl_idname = "wm.remove_file" | |
bl_label = "Remove File" | |
def execute(self, context): | |
fp = context.scene.my_addon.some_identifier | |
if fp: | |
print('os.remove(', fp, ')') | |
os.remove(fp) | |
else: | |
self.report({'ERROR'}, 'filepath is an empty string') | |
return {'FINISHED'} | |
class WMFileSelector(bpy.types.Operator, ExportHelper): | |
bl_idname = "something.identifier_selector" | |
bl_label = "some folder" | |
filename_ext = "" | |
def execute(self, context): | |
fdir = self.properties.filepath | |
context.scene.my_addon.some_identifier = fdir | |
return{'FINISHED'} | |
class WMFilePanel(bpy.types.Panel): | |
"""Creates a Panel in the Object properties window""" | |
bl_label = "Hello World Panel" | |
bl_idname = "OBJECT_PT_hello" | |
bl_space_type = 'PROPERTIES' | |
bl_region_type = 'WINDOW' | |
def draw(self, context): | |
layout = self.layout | |
scn = context.scene | |
# ui | |
col = layout.column() | |
row = col.row(align=True) | |
row.prop(scn.my_addon, 'some_identifier', text='directory:') | |
row.operator("something.identifier_selector", icon="FILE_FOLDER", text="") | |
col = layout.column() | |
col.label(scn.my_addon.some_identifier) | |
col.operator("wm.remove_file") | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.Scene.my_addon = bpy.props.PointerProperty(type=MyAddonProperties) | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
del bpy.types.Scene.my_addon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment