BlenderKit: hide extra objects when appending collection
All extra objects that are appended thanks to their link through geometry nodes, bone shapes and others are now hidden to a new subcollection.
This commit is contained in:
parent
e2e7fac7af
commit
fb9dc77cd0
|
@ -302,17 +302,26 @@ def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwar
|
|||
bpy.ops.object.select_all(action='DESELECT')
|
||||
|
||||
path = file_name + "\\Collection\\"
|
||||
object_name = kwargs.get('name')
|
||||
collection_name = kwargs.get('name')
|
||||
fc = utils.get_fake_context(bpy.context, area_type='VIEW_3D')
|
||||
bpy.ops.wm.append(fc, filename=object_name, directory=path)
|
||||
bpy.ops.wm.append(fc, filename=collection_name, directory=path)
|
||||
|
||||
return_obs = []
|
||||
to_hidden_collection = []
|
||||
collection = None
|
||||
for ob in bpy.context.scene.objects:
|
||||
if ob.select_get():
|
||||
return_obs.append(ob)
|
||||
if not ob.parent:
|
||||
main_object = ob
|
||||
ob.location = location
|
||||
# check for object that should be hidden
|
||||
if ob.users_collection[0].name == collection_name:
|
||||
collection = ob.users_collection[0]
|
||||
else:
|
||||
to_hidden_collection.append(ob)
|
||||
|
||||
|
||||
|
||||
if kwargs.get('rotation'):
|
||||
main_object.rotation_euler = kwargs['rotation']
|
||||
|
@ -321,6 +330,16 @@ def append_objects(file_name, obnames=[], location=(0, 0, 0), link=False, **kwar
|
|||
main_object.parent = bpy.data.objects[kwargs['parent']]
|
||||
main_object.matrix_world.translation = location
|
||||
|
||||
#move objects that should be hidden to a sub collection
|
||||
if len(to_hidden_collection)>0 and collection is not None:
|
||||
hidden_collection_name = collection_name+'_hidden'
|
||||
h_col = bpy.data.collections.new(name = hidden_collection_name)
|
||||
collection.children.link(h_col)
|
||||
for ob in to_hidden_collection:
|
||||
ob.users_collection[0].objects.unlink(ob)
|
||||
h_col.objects.link(ob)
|
||||
utils.exclude_collection(hidden_collection_name)
|
||||
|
||||
bpy.ops.object.select_all(action='DESELECT')
|
||||
utils.selection_set(sel)
|
||||
|
||||
|
|
|
@ -152,6 +152,28 @@ def get_selected_replace_adepts():
|
|||
return parents
|
||||
|
||||
|
||||
def exclude_collection(name, state=True):
|
||||
'''
|
||||
Set the exclude state of collection
|
||||
Parameters
|
||||
----------
|
||||
name - name of collection
|
||||
state - default True.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None
|
||||
'''
|
||||
vl = bpy.context.view_layer.layer_collection
|
||||
cc = [vl]
|
||||
found = False
|
||||
while len(cc) > 0 and not found:
|
||||
c = cc.pop()
|
||||
if c.name == name:
|
||||
c.exclude = state
|
||||
found = True
|
||||
cc.extend(c.children)
|
||||
|
||||
def get_search_props():
|
||||
scene = bpy.context.scene
|
||||
wm = bpy.context.window_manager
|
||||
|
|
Loading…
Reference in New Issue