I asked Chat to make me addon that would save selected objects as separate fbx files using last used fbx saving dialog options into a target folder i could set. Asked sometime earlier in other script to make the path in Windows format (other slashes) but seems Chat continued to use it as a rule .
It works when I paste the path in the input field but doesn’t work when I use folder button in the addon. Can somebody point where is the mistake or fix it please?
Here it is:
bl_info = {
“name”: “Export Selected as FBX”,
“blender”: (3, 0, 0),
“category”: “Object”,
“description”: “Export selected objects as separate FBX files using the last used settings”,
“author”: “Your Name”,
“version”: (1, 0, 0),
“location”: “View3D > N-panel > Export FBX”,
}
import bpy
import os
class ExportFBXSettings(bpy.types.PropertyGroup):
path: bpy.props.StringProperty(
name=“Export Path”,
subtype=‘DIR_PATH’
)
class ExportSelectedAsFBX(bpy.types.Operator):
“”“Export Selected Objects as FBX”“”
bl_idname = “export.selected_as_fbx”
bl_label = “Export Selected as FBX”
def execute(self, context):
export_path = context.scene.export_fbx_settings.path
if not os.path.exists(export_path):
self.report({'ERROR'}, "Invalid path")
return {'CANCELLED'}
original_selection = context.selected_objects
bpy.ops.object.select_all(action='DESELECT')
for obj in original_selection:
context.view_layer.objects.active = obj
obj.select_set(True)
export_path_full = os.path.join(export_path, f"{obj.name}.fbx")
bpy.ops.export_scene.fbx(filepath=export_path_full, use_selection=True)
obj.select_set(False)
for obj in original_selection:
obj.select_set(True)
self.report({'INFO'}, "Export Completed")
return {'FINISHED'}
class EXPORTFBX_PT_Panel(bpy.types.Panel):
bl_label = “Export Selected as FBX”
bl_idname = “EXPORTFBX_PT_panel”
bl_space_type = ‘VIEW_3D’
bl_region_type = ‘UI’
bl_category = ‘Export FBX’
def draw(self, context):
layout = self.layout
scene = context.scene
layout.prop(scene.export_fbx_settings, "path")
layout.operator(ExportSelectedAsFBX.bl_idname)
def register():
bpy.utils.register_class(ExportSelectedAsFBX)
bpy.utils.register_class(EXPORTFBX_PT_Panel)
bpy.utils.register_class(ExportFBXSettings)
bpy.types.Scene.export_fbx_settings = bpy.props.PointerProperty(type=ExportFBXSettings)
def unregister():
bpy.utils.unregister_class(ExportSelectedAsFBX)
bpy.utils.unregister_class(EXPORTFBX_PT_Panel)
bpy.utils.unregister_class(ExportFBXSettings)
del bpy.types.Scene.export_fbx_settings
if name == “main”:
register()