I am trying to make an addon that will randomize path variables. The system I have works by adding and subtracting boxes that contain an input for a data path.
It works fine except for one issue. Because I have to create properties for each of the variables (input box, min, max, randomize on render), all of the values are linked, and every input field, max, min, etc. is all the same:
So how would I fix this issue so that I am able to have independent variables that can be easily created or destroyed? Here is my code:
import bpy
from bpy.types import Panel, Operator
from bpy.props import *
import random as r
paths = 0
class add_data_path(Operator):
bl_idname = "path.add"
bl_label = "Add a data path to change"
def execute(self, context):
global paths
paths += 1
self.report({'INFO'}, 'Added path variable')
return{'FINISHED'}
class subtract_data_path(Operator):
bl_idname = "path.subtract"
bl_label = "Get rid of a data path to change"
def execute(self, context):
global paths
if paths > 0:
paths -= 1
self.report({'INFO'}, 'Removed path variable')
return{'FINISHED'}
# Panel
class RANDOMIZER_UI(Panel):
# Create a Panel in the Tool Shelf
bl_label = "Randomizer"
bl_idname = "RANDOMIZER_Manager"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Tool"
bl_options = {"DEFAULT_CLOSED"}
# Custom Properties
text = bpy.props.StringProperty(name="Text:")
# Draw
def draw(self, context):
Mybool = True
layout = self.layout
obj = context.object
row = layout.row()
row.label(text="Path Randomizations:")
row = layout.row()
row.operator("path.subtract", text="-")
i = 0
while i < paths:
# Visible UI
box = layout.box()
row = box.row()
row.use_property_split = True
row.label(text="Path Variable:")
row.prop(context.object, "varpath", text="")
if context.object.varpath != "":
row = box.row(align=True)
row.prop(context.object, "minvar")
row.prop(context.object, "maxvar")
row = box.row(align=True)
row.prop(context.object, "randonrender", text="Randomize On Render?")
# Special Number
i += 1
row = layout.row()
row.operator("path.add", text="+")
RANDOMIZER_UI(self)
def register():
bpy.utils.register_class(RANDOMIZER_UI)
bpy.utils.register_class(add_data_path)
bpy.utils.register_class(subtract_data_path)
# Registering Variables
bpy.types.Object.varpath = StringProperty(name="Variable Path",
description="Input field for the randomized value")
bpy.types.Object.maxvar = FloatProperty(name="Max Value",
description="The maximum value for the variable path", default=1)
bpy.types.Object.minvar = FloatProperty(name="Min Value",
description="The minimum value for the variable path", default=1)
bpy.types.Object.randonrender = BoolProperty(name="Randomize On Render",
description="Determines whether or not the value is randomized upon rendering an image")
def unregister():
bpy.utils.unregister_class(RANDOMIZER_UI)
bpy.utils.unregister_class(add_data_path)
bpy.utils.unregister_class(subtract_data_path)
del(bpy.types.Object.varpath)
del(bpy.types.Object.maxvar)
del(bpy.types.Object.minvar)
del(bpy.types.Object.randonrender)
if __name__ == "__main__":
register()
```


