Dynamic panels, is this a bad idea?

Hi all

Got a script I’m working one and in one of the UI panels, I want to have fields there to enter the file name of the baked cache (think smoke sim, fluid sim, etc), but I only want the field to appear if there is such a cache. So in the UI’s draw method, I call a function to check if there might be a cache, if there is then it displays the field for the user. Well, watching the way blender refreshes it’s UI panels, I notice the draw method is call quite frequently.

So my question is would be calling a function 6 times from a draw method a bad practice? The function is just one quick loop that looks for modifiers, (cloth modifier, smoke modifier, etc) but as I said I would be calling it six times on each redraw. My concern is it might slow blender down a bit.

Also, would there maybe an easier way to do this? A python or blender object that could always store a True/False flag for each modifier I’m looking for, avoiding the need to call my function 6 times every time the panel is re-drawn?


well if you define a domain

you could add an object property which would act as a flag i guess
and then use an operator to check it
and 6 times is one value
it can even be much higher then that also depends what you do in panel
but should not be a major burden on blender

why do you need to call that function 6 times?
You only need it to check whether to show a certain ui element or not, right ? Why don’t you call the function once, let the function return a boolean value and then just check against this bool value 6 times ?!

I’m calling the function 6 times to check for these - cloth, smoke, softbody, fluid, or collision modifiers, plus a different function that checks for the particle system, from an if/elif statement. If the result is true, a field for input appears in the panel for the user to add the name of the cache. I could call the function once, and set flags, then check the flags, but either way doesn’t seem very elegant. Almost like a loop that lasts forever.

I’m just look for a more efficient way to accomplish this.


edit: was just looking, I might need to call my function again if the explode modifier uses a cache.