0
$\begingroup$

I'm currently working on a Blender addon, and I'm facing an issue regarding the creation of dynamic properties for UI panels. Specifically, I'm trying to read parameters from a JSON file and display them as sliders or input fields within several panels.

The problem is that I can't find a suitable method to dynamically create these properties based on the data from the JSON file. I've attempted to create them within a callback function or directly in the draw() method of the panel that contains the button responsible for reading the JSON. This answer seems to be similar to what I'm looking for but I haven't been able to get my head around it.

Could someone please guide me on how to dynamically generate these properties and have them displayed as sliders or input fields within the panel? Any help or code examples would be greatly appreciated.

Thank you in advance!

$\endgroup$

1 Answer 1

0
$\begingroup$

You can try something like this. It's a bit verbose but unfortunately that's how blender can be when working with properties.

First, I create a JsonObject property group, which will contain collections for any data types you want to parse. I've just included a collection property for booleans and one for strings. We can think of CollectionProperties as arrays or lists for a data type.

enter image description here

To fill these lists, I created two more property groups, representing json strings and json booleans. Now, when you load your json data, you'll be able to populate these collections with your chosen data types.

I'll see if i can add some more examples of this approach later. Hopefully this is a good start!

$\endgroup$
2
  • $\begingroup$ Thanks it worked fine! though its a shame that collections dont allow dictionary-like structures :/ $\endgroup$ Jun 6, 2023 at 6:20
  • $\begingroup$ @AdriánDelgadoDelSol I agree, but this design stems from C / C++ where creating custom data structures like this is a frequent necessity. $\endgroup$ Jun 12, 2023 at 21:20

You must log in to answer this question.

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