IO: Option to import each 3DS file on a new collection #105232
@ -107,6 +107,12 @@ class Import3DS(bpy.types.Operator, ImportHelper):
|
||||
description="Read the 3D cursor location",
|
||||
default=False,
|
||||
)
|
||||
use_collection: BoolProperty(
|
||||
RobLop marked this conversation as resolved
Outdated
|
||||
name="Collection",
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
This looks better if we simply call it "Collection" This looks better if we simply call it "Collection"
|
||||
description="Create a new collection",
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
Would rename this to "Create a new collection" Would rename this to "Create a new collection"
|
||||
default=False,
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
Default should be False to make it optional by default Default should be False to make it optional by default
RobLop
commented
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.
Sebastian Sille
commented
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
|
||||
)
|
||||
|
||||
|
||||
def execute(self, context):
|
||||
from . import import_3ds
|
||||
@ -166,6 +172,9 @@ class MAX3DS_PT_import_include(bpy.types.Panel):
|
||||
layrow.prop(operator, "use_keyframes")
|
||||
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.use_collection else 'GROUP')
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
one last fix to make, replace this with: 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 ;)
|
||||
layrow = layout.row(align=True)
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
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)
|
||||
layrow.prop(operator, "use_cursor")
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
call it "use_collection" to match with style guide call it "use_collection" to match with style guide
|
||||
layrow.label(text="", icon='PIVOT_CURSOR' if operator.use_cursor else 'CURSOR')
|
||||
|
||||
|
@ -10,6 +10,7 @@ import struct
|
||||
import mathutils
|
||||
from bpy_extras.image_utils import load_image
|
||||
from bpy_extras.node_shader_utils import PrincipledBSDFWrapper
|
||||
from pathlib import Path
|
||||
|
||||
BOUNDS_3DS = []
|
||||
|
||||
@ -1772,11 +1773,23 @@ def load_3ds(filepath, context, CONSTRAIN=10.0, UNITS=False, IMAGE_SEARCH=True,
|
||||
|
||||
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,
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
Set default to False Set default to False
|
||||
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, use_collection=False):
|
||||
|
||||
for f in files:
|
||||
load_3ds(os.path.join(directory, f.name), context, CONSTRAIN=constrain_size, UNITS=use_scene_unit,
|
||||
# Get the active collection
|
||||
collection_init = bpy.context.view_layer.active_layer_collection.collection
|
||||
|
||||
# Load each selected file
|
||||
for file in files:
|
||||
# Create new collections if activated (collection name = 3ds file name)
|
||||
NRGSille marked this conversation as resolved
Sebastian Sille
commented
found a little error in line 1784 (below) must be replaced with found a little error in line 1784 (below) must be replaced with `if use_collection:`
RobLop
commented
Yes, I forgot this fix. Yes, I forgot this fix.
|
||||
if use_collection:
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
Looks better if we- use it without suffix. Can be achieved with Looks better if we- use it without suffix. Can be achieved with `file.name.split(".")[0]`
RobLop
commented
Ok, achieved with Path().stem (modern way). Ok, achieved with Path().stem (modern way).
|
||||
collection = bpy.data.collections.new(Path(file.name).stem)
|
||||
bpy.context.scene.collection.children.link(collection)
|
||||
bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection.children[collection.name]
|
||||
RobLop marked this conversation as resolved
Outdated
Sebastian Sille
commented
Here is a little error, it must be Here is a little error, it must be `os.path.join(directory, file.name)`
RobLop
commented
Ok, corrected with the Path(). Ok, corrected with the Path().
|
||||
load_3ds(Path(directory, file.name), context, CONSTRAIN=constrain_size, UNITS=use_scene_unit,
|
||||
IMAGE_SEARCH=use_image_search, FILTER=object_filter, WORLD_MATRIX=use_world_matrix, KEYFRAME=use_keyframes,
|
||||
APPLY_MATRIX=use_apply_transform, CONVERSE=global_matrix, CURSOR=use_cursor, PIVOT=use_center_pivot,)
|
||||
|
||||
# Retrive the initial collection as active
|
||||
bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection.children[collection_init.name]
|
||||
|
||||
return {'FINISHED'}
|
||||
|
In style guide we have all boolean options to begin with "use", therefore this boolean has to be "use_collection"