From 04729b0a5cdf619b1911b27496288288a06d9fdd Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Tue, 9 Apr 2024 11:28:42 -0700 Subject: [PATCH 1/6] FBX: Enable the Collection export feature --- io_scene_fbx/__init__.py | 6 ++++++ io_scene_fbx/export_fbx_bin.py | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 9a7527bc0..4602afe8c 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -315,6 +315,11 @@ class ExportFBX(bpy.types.Operator, ExportHelper): description="Export only objects from the active collection (and its children)", default=False, ) + collection: StringProperty( + name="Source Collection", + description="Export only objects from this collection (and its children)", + default="", + ) global_scale: FloatProperty( name="Scale", description="Scale all data (Some importers do not support scaled armatures!)", @@ -681,6 +686,7 @@ class IO_FH_fbx(bpy.types.FileHandler): bl_idname = "IO_FH_fbx" bl_label = "FBX" bl_import_operator = "import_scene.fbx" + bl_export_operator = "export_scene.fbx" bl_file_extensions = ".fbx" @classmethod diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 148d45f76..1ceb94c2a 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -3586,6 +3586,7 @@ def save(operator, context, use_selection=False, use_visible=False, use_active_collection=False, + collection="", batch_mode='OFF', use_batch_own_dir=False, **kwargs @@ -3606,13 +3607,22 @@ def save(operator, context, if batch_mode == 'OFF': kwargs_mod = kwargs.copy() + + source_collection = None if use_active_collection: - if use_selection: - ctx_objects = tuple(obj - for obj in context.view_layer.active_layer_collection.collection.all_objects - if obj.select_get()) + source_collection = context.view_layer.active_layer_collection.collection + elif collection: + if collection in bpy.data.collections: + source_collection = bpy.data.collections[collection] else: - ctx_objects = context.view_layer.active_layer_collection.collection.all_objects + operator.report({'ERROR'}, "Collection %s was not found" % collection) + return {'CANCELLED'} + + if source_collection: + if use_selection: + ctx_objects = tuple(obj for obj in source_collection.all_objects if obj.select_get()) + else: + ctx_objects = source_collection.all_objects else: if use_selection: ctx_objects = context.selected_objects -- 2.30.2 From eedc9f44add22844c8915e3c7e901072f86ec0a2 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Tue, 9 Apr 2024 11:53:11 -0700 Subject: [PATCH 2/6] FBX: Only draw use_active_collection in FILE_BROWSER space --- io_scene_fbx/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 4602afe8c..2b1520845 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -562,8 +562,11 @@ class ExportFBX(bpy.types.Operator, ExportHelper): layout.use_property_split = True layout.use_property_decorate = False # No animation. + # Are we inside the File browser + is_file_browser = context.space_data.type == 'FILE_BROWSER' + export_main(layout, self) - export_panel_include(layout, self) + export_panel_include(layout, self, is_file_browser) export_panel_transform(layout, self) export_panel_geometry(layout, self) export_panel_armature(layout, self) @@ -606,7 +609,7 @@ def export_main(layout, operator): sub.prop(operator, "use_batch_own_dir", text="", icon='NEWFOLDER') -def export_panel_include(layout, operator): +def export_panel_include(layout, operator, is_file_browser): header, body = layout.panel("FBX_export_include", default_closed=False) header.label(text="Include") if body: @@ -614,7 +617,8 @@ def export_panel_include(layout, operator): sublayout.enabled = (operator.batch_mode == 'OFF') sublayout.prop(operator, "use_selection") sublayout.prop(operator, "use_visible") - sublayout.prop(operator, "use_active_collection") + if is_file_browser: + sublayout.prop(operator, "use_active_collection") body.column().prop(operator, "object_types") body.prop(operator, "use_custom_props") -- 2.30.2 From c7e36ccaa240ed34cb1f39e8394972093cbe5fe9 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Tue, 9 Apr 2024 11:58:25 -0700 Subject: [PATCH 3/6] Make error message better --- io_scene_fbx/export_fbx_bin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 1ceb94c2a..78fb5c8e9 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -3615,7 +3615,7 @@ def save(operator, context, if collection in bpy.data.collections: source_collection = bpy.data.collections[collection] else: - operator.report({'ERROR'}, "Collection %s was not found" % collection) + operator.report({'ERROR'}, "Collection '%s' was not found" % collection) return {'CANCELLED'} if source_collection: -- 2.30.2 From b2a21b359aa7ccf9e1d9e9b31279c1f3ae7b3d24 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Wed, 10 Apr 2024 11:25:38 -0700 Subject: [PATCH 4/6] Only draw use selection/visible in FILE_BROWSER too --- io_scene_fbx/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 2b1520845..49dcf3bba 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -615,9 +615,9 @@ def export_panel_include(layout, operator, is_file_browser): if body: sublayout = body.column(heading="Limit to") sublayout.enabled = (operator.batch_mode == 'OFF') - sublayout.prop(operator, "use_selection") - sublayout.prop(operator, "use_visible") if is_file_browser: + sublayout.prop(operator, "use_selection") + sublayout.prop(operator, "use_visible") sublayout.prop(operator, "use_active_collection") body.column().prop(operator, "object_types") -- 2.30.2 From 7dc9a38448927258fa3c7004ef8ae4ffbe0eda2b Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Mon, 15 Apr 2024 13:41:48 -0700 Subject: [PATCH 5/6] Explicitly find local collections --- io_scene_fbx/export_fbx_bin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 78fb5c8e9..b1b30440f 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -3612,8 +3612,9 @@ def save(operator, context, if use_active_collection: source_collection = context.view_layer.active_layer_collection.collection elif collection: - if collection in bpy.data.collections: - source_collection = bpy.data.collections[collection] + local_collection = bpy.data.collections.get((collection, None)) + if local_collection: + source_collection = local_collection else: operator.report({'ERROR'}, "Collection '%s' was not found" % collection) return {'CANCELLED'} -- 2.30.2 From 0099da909e65f9419d2b9a978c656021adfbf1c7 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Mon, 15 Apr 2024 16:46:39 -0700 Subject: [PATCH 6/6] Feedback: Batch mode is only valid in file browser --- io_scene_fbx/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 49dcf3bba..9a657d85b 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -565,7 +565,7 @@ class ExportFBX(bpy.types.Operator, ExportHelper): # Are we inside the File browser is_file_browser = context.space_data.type == 'FILE_BROWSER' - export_main(layout, self) + export_main(layout, self, is_file_browser) export_panel_include(layout, self, is_file_browser) export_panel_transform(layout, self) export_panel_geometry(layout, self) @@ -597,16 +597,17 @@ class ExportFBX(bpy.types.Operator, ExportHelper): return export_fbx_bin.save(self, context, **keywords) -def export_main(layout, operator): +def export_main(layout, operator, is_file_browser): row = layout.row(align=True) row.prop(operator, "path_mode") sub = row.row(align=True) sub.enabled = (operator.path_mode == 'COPY') sub.prop(operator, "embed_textures", text="", icon='PACKAGE' if operator.embed_textures else 'UGLYPACKAGE') - row = layout.row(align=True) - row.prop(operator, "batch_mode") - sub = row.row(align=True) - sub.prop(operator, "use_batch_own_dir", text="", icon='NEWFOLDER') + if is_file_browser: + row = layout.row(align=True) + row.prop(operator, "batch_mode") + sub = row.row(align=True) + sub.prop(operator, "use_batch_own_dir", text="", icon='NEWFOLDER') def export_panel_include(layout, operator, is_file_browser): -- 2.30.2