[Bf-blender-cvs] [bf48750] master: Fix T49111: Automatically add file path suffix for Alembic and Collada export.

Kévin Dietrich noreply at git.blender.org
Fri Aug 19 04:42:49 CEST 2016


Commit: bf4875001de10d0053fc9377fa98349bd6e1e8a9
Author: Kévin Dietrich
Date:   Fri Aug 19 04:42:12 2016 +0200
Branches: master
https://developer.blender.org/rBbf4875001de10d0053fc9377fa98349bd6e1e8a9

Fix T49111: Automatically add file path suffix for Alembic and Collada
export.

This aligns the behaviour of the file selection with the other
exporters. The Alembic case would fail if the filepath did not have an
extension set.

Also set a default file name for the Alembic export operator in case the
Blender file was not saved before exporting.

===================================================================

M	source/blender/editors/io/io_alembic.c
M	source/blender/editors/io/io_collada.c

===================================================================

diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index 63c6f3d..96a3ef1 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -68,8 +68,16 @@
 static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+		Main *bmain = CTX_data_main(C);
 		char filepath[FILE_MAX];
-		BLI_strncpy(filepath, G.main->name, sizeof(filepath));
+
+		if (bmain->name[0] == '\0') {
+			BLI_strncpy(filepath, "untitled", sizeof(filepath));
+		}
+		else {
+			BLI_strncpy(filepath, bmain->name, sizeof(filepath));
+		}
+
 		BLI_replace_extension(filepath, sizeof(filepath), ".abc");
 		RNA_string_set(op->ptr, "filepath", filepath);
 	}
@@ -213,6 +221,20 @@ static void wm_alembic_export_draw(bContext *UNUSED(C), wmOperator *op)
 	ui_alembic_export_settings(op->layout, &ptr);
 }
 
+static bool wm_alembic_export_check(bContext *UNUSED(C), wmOperator *op)
+{
+	char filepath[FILE_MAX];
+	RNA_string_get(op->ptr, "filepath", filepath);
+
+	if (!BLI_testextensie(filepath, ".abc")) {
+		BLI_ensure_extension(filepath, FILE_MAX, ".abc");
+		RNA_string_set(op->ptr, "filepath", filepath);
+		return true;
+	}
+
+	return false;
+}
+
 void WM_OT_alembic_export(wmOperatorType *ot)
 {
 	ot->name = "Export Alembic";
@@ -223,6 +245,7 @@ void WM_OT_alembic_export(wmOperatorType *ot)
 	ot->exec = wm_alembic_export_exec;
 	ot->poll = WM_operator_winactive;
 	ot->ui = wm_alembic_export_draw;
+	ot->check = wm_alembic_export_check;
 
 	WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_ALEMBIC,
 	                               FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH,
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c
index d62651c..8659100 100644
--- a/source/blender/editors/io/io_collada.c
+++ b/source/blender/editors/io/io_collada.c
@@ -280,6 +280,20 @@ static void wm_collada_export_draw(bContext *UNUSED(C), wmOperator *op)
 	uiCollada_exportSettings(op->layout, &ptr);
 }
 
+static bool wm_collada_export_check(bContext *UNUSED(C), wmOperator *op)
+{
+	char filepath[FILE_MAX];
+	RNA_string_get(op->ptr, "filepath", filepath);
+
+	if (!BLI_testextensie(filepath, ".dae")) {
+		BLI_ensure_extension(filepath, FILE_MAX, ".dae");
+		RNA_string_set(op->ptr, "filepath", filepath);
+		return true;
+	}
+
+	return false;
+}
+
 void WM_OT_collada_export(wmOperatorType *ot)
 {
 	static EnumPropertyItem prop_bc_export_mesh_type[] = {
@@ -302,6 +316,7 @@ void WM_OT_collada_export(wmOperatorType *ot)
 	ot->invoke = wm_collada_export_invoke;
 	ot->exec = wm_collada_export_exec;
 	ot->poll = WM_operator_winactive;
+	ot->check = wm_collada_export_check;
 
 	ot->flag |= OPTYPE_PRESET;




More information about the Bf-blender-cvs mailing list