0
$\begingroup$

I'm currently making an addon to randomize path variables, and need lots of groups of variables that I can independently edit. I've been trying to get Property Groups working with this but can't figure out how to make instances of the Property Groups and still be able to edit the variables inside them.

Here's what I have:

the main PropertyGroup

class PathNode(PropertyGroup):
    path: StringProperty()
    minvar: FloatProperty()
    maxvar: FloatProperty()
    randomize: BoolProperty()

this is how I've been trying to make multiple instances of it, with "pathsam" as an IntProperty

bpy.types.Object.pathsam = CollectionProperty(type=PathNode)

Does anyone know how to either fix this, or know how to create multiple instances of the main path variable where the variables can still be independently accessed and edited?

$\endgroup$
3
  • $\begingroup$ For scripting / python / addon questions using those tags can alert people to your specific needs more readily. $\endgroup$
    – Ratt
    Jan 7, 2020 at 3:30
  • $\begingroup$ Doesn't answer here blender.stackexchange.com/a/160738/15543 cover this? $\endgroup$
    – batFINGER
    Jan 7, 2020 at 7:22
  • $\begingroup$ ... puts in context this question re the suggestion of adding to collection a per object basis rather than having the "global" scene property. (See new edit.). IMO Could have been addressed via a comment under that answer. $\endgroup$
    – batFINGER
    Jan 7, 2020 at 7:49

1 Answer 1

1
$\begingroup$

In general adding property groups to object types can be done with

import bpy


class PathNode(bpy.types.PropertyGroup):
    path: bpy.props.StringProperty()
    minvar: bpy.props.FloatProperty()
    maxvar: bpy.props.FloatProperty()
    randomize: bpy.props.BoolProperty()

classes = [PathNode, ]


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.Object.pathsam = bpy.props.PointerProperty(
            type=PathNode)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
    del bpy.types.Object.pathsam

if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ The problem is that when I do that, I am no longer able to edit the variable that controls the amount of path nodes there are (pathsam), and get an unsupported operand type(s) for +=: 'PathNode' and 'int' error. Is there any way to fix this? $\endgroup$ Jan 8, 2020 at 0:49

You must log in to answer this question.

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