Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAras Pranckevicius <aras@nesnausk.org>2022-08-11 17:05:54 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-08-11 17:05:54 +0300
commit4cbd799373d07498813ad84f8cee5f3a8c269631 (patch)
tree86c65832d55244d1dabe336919af87e7a86e540b /source/blender/editors/io
parentc4a0438522b7eadccb5c2d723521d5b3933fc5e9 (diff)
obj: support importing multiple files at once
Implemented the same way as STL or GPencil SVG importers: loop over the input files, import one by one. Has been requested by the community for quite a long time (e.g. https://blender.community/c/rightclickselect/Jhbbbc/), as well as 3rd party addons to implement just this (https://github.com/p2or/blender-batch-import-wavefront-obj).
Diffstat (limited to 'source/blender/editors/io')
-rw-r--r--source/blender/editors/io/io_obj.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 662ff601e29..c151baf13ef 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -382,11 +382,6 @@ static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
static int wm_obj_import_exec(bContext *C, wmOperator *op)
{
- if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
- BKE_report(op->reports, RPT_ERROR, "No filename given");
- return OPERATOR_CANCELLED;
- }
-
struct OBJImportParams import_params;
RNA_string_get(op->ptr, "filepath", import_params.filepath);
import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size");
@@ -395,8 +390,35 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op)
import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups");
import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
import_params.relative_paths = ((U.flag & USER_RELPATHS) != 0);
-
- OBJ_import(C, &import_params);
+ import_params.clear_selection = true;
+
+ int files_len = RNA_collection_length(op->ptr, "files");
+ if (files_len) {
+ /* Importing multiple files: loop over them and import one by one. */
+ PointerRNA fileptr;
+ PropertyRNA *prop;
+ char dir_only[FILE_MAX], file_only[FILE_MAX];
+
+ RNA_string_get(op->ptr, "directory", dir_only);
+ prop = RNA_struct_find_property(op->ptr, "files");
+ for (int i = 0; i < files_len; i++) {
+ RNA_property_collection_lookup_int(op->ptr, prop, i, &fileptr);
+ RNA_string_get(&fileptr, "name", file_only);
+ BLI_join_dirfile(
+ import_params.filepath, sizeof(import_params.filepath), dir_only, file_only);
+ import_params.clear_selection = (i == 0);
+ OBJ_import(C, &import_params);
+ }
+ }
+ else if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ /* Importing one file. */
+ RNA_string_get(op->ptr, "filepath", import_params.filepath);
+ OBJ_import(C, &import_params);
+ }
+ else {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
Scene *scene = CTX_data_scene(C);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
@@ -454,7 +476,8 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
FILE_TYPE_FOLDER,
FILE_BLENDER,
FILE_OPENFILE,
- WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
+ WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS |
+ WM_FILESEL_DIRECTORY | WM_FILESEL_FILES,
FILE_DEFAULTDISPLAY,
FILE_SORT_ALPHA);
RNA_def_float(