From 57ffdac4ef1776fae1f5fd60b9ee927b17eb16ec Mon Sep 17 00:00:00 2001 From: "demeterdzadik@gmail.com" Date: Fri, 7 Jul 2023 11:53:31 +0200 Subject: [PATCH] GNSK: Improve visibility management There were cases where if the user tried to manage visibilities of objects or collections, they could encounter errors or poor UX: - If user excludes, disables, or nests the GNSK collection, they'll get an error from ops.object.mode_set(). - If they unhide all objects in the GNSK collection and then add a new sculpt, they would see all the sculpts until they switched back and forth once more. Both of those issues and possibly more are fixed in this patch. --- .../addons/geonode_shapekeys/operators.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts-blender/addons/geonode_shapekeys/operators.py b/scripts-blender/addons/geonode_shapekeys/operators.py index 65e37f73..12bc7a93 100644 --- a/scripts-blender/addons/geonode_shapekeys/operators.py +++ b/scripts-blender/addons/geonode_shapekeys/operators.py @@ -74,14 +74,24 @@ def link_shape_key_node_tree(context) -> bpy.types.NodeTree: return bpy.data.node_groups[NODETREE_NAME] -def ensure_shapekey_collection(scene: bpy.types.Scene) -> bpy.types.Collection: +def ensure_shapekey_collection(context: bpy.types.Context) -> bpy.types.Collection: """Ensure and return a collection used for the objects created by the add-on.""" + scene = context.scene coll = bpy.data.collections.get(COLLECTION_NAME) if not coll: coll = bpy.data.collections.new(COLLECTION_NAME) scene.collection.children.link(coll) coll.hide_render = True + coll.hide_viewport = False + if coll not in list(scene.collection.children): + scene.collection.children.link(coll) + + context.view_layer.layer_collection.children[coll.name].exclude = False + + for obj in coll.all_objects: + obj.hide_set(True) + return coll @@ -263,7 +273,8 @@ class GNSK_add_shape(bpy.types.Operator): sk_mesh = bpy.data.meshes.new_from_object(obj.evaluated_get(eval_dg)) sk_ob = bpy.data.objects.new(obj.name+"."+self.shape_name, sk_mesh) sk_ob.data.name = sk_ob.name - ensure_shapekey_collection(context.scene).objects.link(sk_ob) + sk_coll = ensure_shapekey_collection(context) + sk_coll.objects.link(sk_ob) # Add shape keys sk_ob.use_shape_key_edit_mode = True -- 2.30.2