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

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.

Comments

  • 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)

  • Conceptually i'm try to understand the logic behind, this..
    https://github.com/IfcOpenShell/IfcOpenShell/blame/86cc2bf39abd0417bb33a6e4942a007616cb1247/src/blenderbim/blenderbim/bim/module/type/operator.py#L155
    That is, wondering why we can't find some methods to turn on the type, and the collection that it's in. I'm sure there's a reason. :)

  • 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?

  • Oh sorry, i meant why doesn't it work on a collection.
    Doesn't seem to.
    https://g.co/gemini/share/e905be8cda34

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

    theoryshaw
  • edited May 2024

    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"))
    
    theoryshaw
Sign In or Register to comment.