OSArch Community

Why doesn't things like `obj.hide = False` and `obj.hide_set(False)` work in BB?

  1. T

    I think there's a reason, but not sure...

    Why doesn't things like obj.hide = False and obj.hide_set(False) work in BB?

    Maybe i'm missing something.

  2. M

    Works for me. What exactly are you trying?

    Step 1. Fresh Blender. Step 2 in Python console: C.active_object.hide_set(True) then C.active_object.hide_set(False)

  3. T
  4. M

    In theory we can just turn it on there, but there could be all sorts of reasons for a hidden object - one of which is hide_set. Another could be the parent collection being hidden. Or the parent collection being unloaded. Or being isolated (\ or / hotkey). Perhaps there are more reasons I'm not aware of right now?

  5. T
  6. M

    Collections typically store their visibility per "view layer", so try C.view_layer.layer_collection.children['IfcProject/My Project'].hide_viewport = True.

  7. T
  8. G

    FWIW another solution that doesn't involve recursion - python has an arbitrary recursion limit, you will hardly ever encounter it in a regular project but if for some reason you do it will fail :

    
    def recursive_search(collection, target_name):
    
        children = list(collection.children)
    
        while children:
    
            collection_test = children.pop(0)
    
            if collection_test.name == target_name:
    
                return collection_test
    
            children.extend(collection_test.children)
    

    I don't know if there is an explicit rule about it in the python guidelines so you can keep it that way if it makes it more readable for you, but FWIW all functions implicitly return None by default if there is no return statement before the last line. As a rule of thumb (from my own, limited experience) the less return statements your function has, the easier it is to debug. But the python zen states "Explicit is better than implicit", so, yeah, a bit contradictory. :p

    Also my 2 cents about getting collections the other way around, look for the project empty and select its collection. Might offer more leeway in letting the user reorder the collections since it doesn't rely on a hardcoded hierarchy structure. Could do with a cache system to save some computing power on huge scenes.

    
    def get_entity_collection(entity_type, entity_name=None):
    
        for obj in bpy.context.scene.objects:
    
            if obj.type != "EMPTY":
    
                continue
    
            if not (entity:= tool.Ifc.get_entity(obj)) or not entity.is_a(entity_type):
    
                continue
    
            if entity.Name == entity_name or not entity_name:
    
                return obj.users_collection[0]
    
    
    print(get_entity_collection("IfcProject", "My Project"))
    
    print(get_entity_collection("IfcProject"))
    
    print(get_entity_collection("IfcBuilding", "My Building"))
    

Login or Register to reply.