How to create custom properties via Python

I’m having trouble creating custom properties with fx.Property()

The docs don’t seem to offer much insight. What I’m finding is the first arg is the id or name. 2nd is the label, 3rd is the default value which in turn can set the type, and fourth is a dictionary housing more info? If you pass in a string for the 3rd arg it’s a string prop, an int, it’s a list, a float, its a number.

What I’m really looking for is how I can create the Button prop and when clicked run another specific script.

Does anyone have any examples or know the proper arguments?

The arguments are:
id - internal property name, must be unique for that object
label - visible label
value - default value, the type of parameter is derived from the value type
info - a dictionary with more information depending on type
tooltip - a tooltip

If value is None, then info must have a ‘type’ key with value of ‘button’ or ‘group’.
If value is type Bool, then no arguments are necessary.
If value is type Double/Float, then ‘info’ dictionary must contain ‘min’ and ‘max’ keys, and optional ‘display_min’ and ‘display_max’ keys
If value is type Integer, then the property type is a list and ‘info’ must contain a ‘items’ key with a list of item strings.
If value is type String, the optional ‘info’ dictionary can contain a ‘type’ key with possible values of ‘dir’, ‘path’, ‘in_path’, ‘label’.

It’s not yet possible to create other property types.

Thank you!,

I was able to set the type as a button and add it to the node, but how do I set the script it runs when triggered?

Well I’m sorry to say there isn’t yet a way to do that. One of the reasons the “button” type was undocumented I guess.
Currently there are no hooks regarding property changes. I’ll see if I can get something in place for our upcoming 2022.5 release.

1 Like

Thank you!

I take it back - there is an existing hook!

“property_changed” - the argument is the property that changed.

Currently it is only triggered when the user fiddles directly with a property. It does not currently trigger when the change is undone/redone. However, that should suffice to handle a button click.

1 Like

The upcoming 2022.5 release has a fix where the hook will trigger with undo/redo.