Hello!
I’m working on a little plugin that imports some external data and also creates some Blender objects based on that data. I want to call up the import dialog (with ImportHelper in order to filter by file extension) and save the filepath returned by the import dialog as a property, to be used by other functions. Other functions would parse the filename, and look up some stuff in a little database I have, maybe move some things around that are already in the scene (or not), and also import that file. Alright.
The problem I’m having is that I can’t save the filepath anywhere, and I’m not sure where I should be saving it since I don’t want it attached to a mesh, etc. For example, here’s a snippet:
class SimSceneSettings(bpy.types.PropertyGroup) :
ps_filepath = bpy.props.StringProperty (
name = "File path for the ps mesh",
maxlen = 1024,
default = ""
)
# end SimSceneSettings
class PSDialog(Operator, ImportHelper):
bl_idname = "sim_tools.imp_ps"
bl_label = "PS"
filename_ext = ".x3d"
filter_glob = bpy.props.StringProperty (
default = "*.x3d",
options = {'HIDDEN'}
)
filepath = bpy.props.StringProperty (
name = "File Path",
maxlen = 1024,
default = ""
)
def execute(self, context) :
context.scene.sim_tools.ps_filepath = self.properties.filepath
print("inside execute: ", self.properties.filepath)
return {'FINISHED'}
This prints the stuff preceded by “inside execute”, but context.scene.sim_tools.ps_filepath is empty after the dialog box returns. I need this property to stay put.
To call up the dialog box, I do Shift+A to call up my toolkit (function add_to_menu referenced below) , which puts one object on the scene at the start. It also draws a panel in the Tool Shelf which has a button which calls up PSDialog. The PropertyGroup is registered under scene, but I’m not sure if that’s correct.
def register() :
bpy.utils.register_module(__name__)
bpy.types.Scene.sim_tools = bpy.props.PointerProperty(type = SimSceneSettings)
bpy.types.INFO_MT_add.prepend(add_to_menu)
# end register
def unregister() :
del bpy.types.Scene.sim_tools
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_add.remove(add_to_menu)
# end unregister
I hope this makes sense. I just want to save the filepath from the import dialog somewhere permanent, or at least, somewhere that lives as long as my Tool Shelf panel. Thank you!