Thanks again. That self.report works like a charm. The script is doing a perfect job, or at least it did.
Now that I’m testing it on another machine, I’m suddenly getting this error:
‘Scene’ object has no attribute ‘file_path’
I have no clue why it would suddenly not be able to get the file_path.
The file browser layout element is also not showing up anymore.
So here’s the entire thing, because after a whole morning of trying to fix this, I’m all out of ideas:
import bpy
import os
class ToolsPanel(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Tools"
bl_label = "FBX Exporter"
file_path = bpy.props.StringProperty(subtype='DIR_PATH')
# draw the gui
def draw(self, context):
lay = self.layout
col = lay.column(align=True)
row = col.row(align=True)
col.prop(context.scene, "file_path", text="")
col.operator('tool.exportfbx', icon='EXPORT')
def get_filename():
filename = bpy.path.basename(bpy.context.blend_data.filepath)
basename = os.path.splitext(filename)[0]
return basename
class ExportFBX(bpy.types.Operator):
bl_idname = 'tool.exportfbx'
bl_description = 'Export entire scene as .fbx file'
bl_label = 'Export scene as FBX'
def execute(self, context):
directory = bpy.context.scene.file_path
if not os.path.exists(directory):
self.report({'ERROR'}, 'Invalid path') # let's the the user there was an error
return {'CANCELLED'}
target_file = os.path.join(directory, get_filename() + '.fbx')
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='DESELECT')
#fbx export properties go here
bpy.ops.object.select_all(action='DESELECT')
return {'FINISHED'}
# Registration
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()