First of all sorry, I don't have coding background and maybe this question is not formulated in a proper way.
Basically I want to have control over the number of variables (properties) of an add-on. Normally, if I want to have an input in an add-on I would have a property (for example my_float) and then:
row= layout.row()
row.prop(mytool, "my_float_4")
Then this value can be easily changed:
Now, if I want to link the number of this inputs to a parameter of the scene (let's say, one per object of the scene or one per Geometry Nodes input of an object), because I have to declare the properties in a class a priori, I can't have this flexibility.
Is there a way to avoid this problem?
I made this code, in this case for having a property per GN input, but this DOESN´T mean that I want to control the GN tree with with the add-on, I just want to match the number of inputs with the number of properties.
import bpy
from bpy.props import (BoolProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
PropertyGroup,
)
import bmesh
from math import fabs,sin,cos,sqrt,atan2,pi
import numpy as np
import mathutils
class MyPropertiesTool(bpy.types.PropertyGroup):
my_float :bpy.props.FloatProperty (name = "Float" )
class ADDONNAME_PT_main_panel(bpy.types.Panel):
bl_label= "Test"
bl_idname = "TEst"
bl_space_type = 'VIEW_3D'
bl_region_type= 'UI'
bl_category= 'Test'
def draw(self,context):
layout = self.layout
scene= context.scene
mytool= scene.my_tool
row= layout.row()
row.prop_search(scene, "Source", scene, "objects")
obj = scene.Source
modifiers = []
for modifier in obj.modifiers:
if modifier.type == 'NODES':
modifiers.append(modifier)
modifier = modifiers[0]
for input in modifier.node_group.inputs:
row= layout.row()
row.label (text=input.name )
row.label()
# HERE IS WHERE I WANT TO ADD THE VALUES, SO I WOULD NEED SOMETHING LIKE THIS LINKED TO
#THE INPUTS OF THE GEOMETRY NODES SET UP
#row.prop(mytool, "my_float", slider= True)
classes = [ADDONNAME_PT_main_panel,MyPropertiesTool]
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
bpy.types.Scene.my_tool = PointerProperty(type=MyPropertiesTool)
bpy.types.Scene.prop = PointerProperty(type=bpy.types.Object)
bpy.types.Scene.Source = PointerProperty(type=bpy.types.Object)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
del bpy.types.Scene.my_tool
del bpy.types.Object.Source
if __name__ == "__main__":
register()