IO: Option to import each 3DS file on a new collection #105232

Merged
Sebastian Sille merged 6 commits from :roblop-patch-new-collection into main 2024-03-13 13:34:08 +01:00
Contributor

Following my initial commit (#105227), I suggest a enhancement to have an option to include each 3DS file on a new collection (the name of the collection = name of 3DS file).

Importing a 3DS file can result in a lot of objects and it's a mess in the outliner and this commit solve this issue.

Following my initial commit (https://projects.blender.org/blender/blender-addons/pulls/105227), I suggest a enhancement to have an option to include each 3DS file on a new collection (the name of the collection = name of 3DS file). Importing a 3DS file can result in a lot of objects and it's a mess in the outliner and this commit solve this issue.
RobLop added 2 commits 2024-03-13 00:22:09 +01:00
RobLop requested review from Sebastian Sille 2024-03-13 00:22:38 +01:00
Sebastian Sille requested changes 2024-03-13 09:41:21 +01:00
Dismissed
@ -107,6 +107,12 @@ class Import3DS(bpy.types.Operator, ImportHelper):
description="Read the 3D cursor location",
default=False,
)
new_collection: BoolProperty(

In style guide we have all boolean options to begin with "use", therefore this boolean has to be "use_collection"

In style guide we have all boolean options to begin with "use", therefore this boolean has to be "use_collection"
RobLop marked this conversation as resolved
@ -108,2 +108,4 @@
default=False,
)
new_collection: BoolProperty(
name="New collection",

This looks better if we simply call it "Collection"

This looks better if we simply call it "Collection"
RobLop marked this conversation as resolved
@ -109,1 +109,4 @@
)
new_collection: BoolProperty(
name="New collection",
description="Include on a new collection",

Would rename this to "Create a new collection"

Would rename this to "Create a new collection"
RobLop marked this conversation as resolved
@ -110,0 +110,4 @@
new_collection: BoolProperty(
name="New collection",
description="Include on a new collection",
default=True,

Default should be False to make it optional by default

Default should be False to make it optional by default
Author
Contributor

I think it's better to make it True by default otherwise it create a mess on the active collection after the importation of multiple 3DS files.

I think it's better to make it True by default otherwise it create a mess on the active collection after the importation of multiple 3DS files.

I think it's better to make it True by default otherwise it create a mess on the active collection after the importation of multiple 3DS files.

It depends on what the user wants, it may be useful for multiple files but the common use of all importers is to add a model to the current collection, thats why I think it should be false by default to match with the other IO scripts

> I think it's better to make it True by default otherwise it create a mess on the active collection after the importation of multiple 3DS files. > It depends on what the user wants, it may be useful for multiple files but the common use of all importers is to add a model to the current collection, thats why I think it should be false by default to match with the other IO scripts
RobLop marked this conversation as resolved
@ -168,6 +174,9 @@ class MAX3DS_PT_import_include(bpy.types.Panel):
layrow = layout.row(align=True)
layrow.prop(operator, "use_cursor")
layrow.label(text="", icon='PIVOT_CURSOR' if operator.use_cursor else 'CURSOR')
layrow = layout.row(align=True)

This looks better if we move it up before "use_cursor" (so it looks more the same like the exporter)

This looks better if we move it up before "use_cursor" (so it looks more the same like the exporter)
RobLop marked this conversation as resolved
@ -169,2 +175,4 @@
layrow.prop(operator, "use_cursor")
layrow.label(text="", icon='PIVOT_CURSOR' if operator.use_cursor else 'CURSOR')
layrow = layout.row(align=True)
layrow.prop(operator, "new_collection")

call it "use_collection" to match with style guide

call it "use_collection" to match with style guide
RobLop marked this conversation as resolved
@ -1773,3 +1773,3 @@
def load(operator, context, files=None, directory="", filepath="", constrain_size=0.0, use_scene_unit=False,
use_image_search=True, object_filter=None, use_world_matrix=False, use_keyframes=True,
use_apply_transform=True, global_matrix=None, use_cursor=False, use_center_pivot=False):
use_apply_transform=True, global_matrix=None, use_cursor=False, use_center_pivot=False, new_collection=True):

Set default to False

Set default to False
RobLop marked this conversation as resolved
@ -1778,0 +1781,4 @@
for file in files:
# Create new collections if activated (collection name = 3ds file name)
if new_collection:
collection = bpy.data.collections.new(file.name)

Looks better if we- use it without suffix. Can be achieved with file.name.split(".")[0]

Looks better if we- use it without suffix. Can be achieved with `file.name.split(".")[0]`
Author
Contributor

Ok, achieved with Path().stem (modern way).

Ok, achieved with Path().stem (modern way).
RobLop marked this conversation as resolved
@ -1778,1 +1784,4 @@
collection = bpy.data.collections.new(file.name)
bpy.context.scene.collection.children.link(collection)
bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection.children[collection.name]
load_3ds(os.path.join(directory, f.name), context, CONSTRAIN=constrain_size, UNITS=use_scene_unit,

Here is a little error, it must be os.path.join(directory, file.name)

Here is a little error, it must be `os.path.join(directory, file.name)`
Author
Contributor

Ok, corrected with the Path().

Ok, corrected with the Path().
RobLop marked this conversation as resolved
Sebastian Sille added this to the Import/Export project 2024-03-13 09:47:14 +01:00
RobLop added 1 commit 2024-03-13 10:45:12 +01:00
RobLop added 1 commit 2024-03-13 10:47:02 +01:00
Sebastian Sille requested changes 2024-03-13 11:04:03 +01:00
Dismissed
@ -167,2 +173,4 @@
layrow.label(text="", icon='ANIM' if operator.use_keyframes else 'DECORATE_DRIVER')
layrow = layout.row(align=True)
layrow.prop(operator, "use_collection")
layrow.label(text="", icon='OUTLINER_COLLECTION' if operator.new_collection else 'COLLECTION_NEW')

one last fix to make, replace this with:
layrow.label(text="", icon='OUTLINER_COLLECTION' if operator.use_collection else 'GROUP')
the GROUP icon looks better because it is the inverse of the collection icon ;)

one last fix to make, replace this with: `layrow.label(text="", icon='OUTLINER_COLLECTION' if operator.use_collection else 'GROUP')` the GROUP icon looks better because it is the inverse of the collection icon ;)
RobLop marked this conversation as resolved
Sebastian Sille requested changes 2024-03-13 11:22:37 +01:00
Dismissed
@ -1779,0 +1780,4 @@
# Load each selected file
for file in files:
# Create new collections if activated (collection name = 3ds file name)

found a little error in line 1784 (below) must be replaced with if use_collection:

found a little error in line 1784 (below) must be replaced with `if use_collection:`
Author
Contributor

Yes, I forgot this fix.

Yes, I forgot this fix.
NRGSille marked this conversation as resolved
RobLop added 1 commit 2024-03-13 13:19:24 +01:00
RobLop added 1 commit 2024-03-13 13:23:16 +01:00

@RobLop Thanks for this contribution, we can merge this.

I will also add this to the manual and realease notes^^

@RobLop Thanks for this contribution, we can merge this. I will also add this to the manual and realease notes^^
Sebastian Sille merged commit 6eab88a9aa into main 2024-03-13 13:34:08 +01:00
Sebastian Sille approved these changes 2024-03-13 14:12:06 +01:00
RobLop deleted branch roblop-patch-new-collection 2024-04-22 22:08:51 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#105232
No description provided.