1
$\begingroup$

How to show a panel, only when a particular collection exist (or appended)?

Here a bit more explanation of what I am aiming for in case the question is not clear:

enter image description here

In the screenshot above you see there is a panel called 3point light Ctrl. What I want is that the panel "3Point Light Ctrl" only shows up after the user clicked on "Add 3 Point Light" in the "Add to scene" panel.

Often I see a poll function in other addons like:

@classmethod
    def poll(cls, context):
        return context.active_object is not None

And so I thought I could do it as follows:

@classmethod
    def poll(cls, context):
        return return bpy.data.collections[“ThreePointLight”] 

But that doesn't work, and I realize it is expecting context, not bpy.data. Any idea how I can do this? (It's for Blender 2.80).

$\endgroup$

1 Answer 1

1
$\begingroup$

You are going to want to use python's membership operator: in

@classmethod
def poll(cls, context):
    return "ThreePointLight" in bpy.data.collections

Using bpy.data.collections[*name string*] would result in an KeyError in the event the name does not exist.

$\endgroup$
3
  • 1
    $\begingroup$ Would be a KeyError if the name doesn't exist. Could also use collection.get(key) is not None $\endgroup$
    – batFINGER
    Commented Apr 23, 2019 at 9:25
  • $\begingroup$ @proxeIO That was the trick. That makes it quite easy to make a dynamic menu. Thanks! See answer: return "ThreePointLight" in bpy.data.collections $\endgroup$ Commented Apr 23, 2019 at 19:07
  • $\begingroup$ @batFINGER Corrected $\endgroup$
    – proxe
    Commented Apr 24, 2019 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .