-
Notifications
You must be signed in to change notification settings - Fork 20
Format Custom Messages
NodeOsc has from Version 2 onwards the ability to dynamically format the data-path string.
The expand on the previous example and working with an osc message whose arguments are looking the same:
/objects/Variable/location Cube 10.0 15.2 -5.3
We can see we receive the message on /objects/Variable/location
.
However, now we want to use one of the arguments to format the data-path. For this we have to enable 'Format' and a new text field appears.
Relying on Pythons string format() method, we can now take the arguments tuple to format the data-path.
You can see the Format-field says args
, which stands for the arguments tuple.
And looking at the data-path more closely: bpy.data.objects['{0}'].location
, there is a {0}
inside the brackets. Which means we take the first element of the arguments tuple ('Cube') and put it inside the brackets, making sure we don't forget the '' on both ends.
but since the message contains 4 arguments and the positional information are on the indices 1, 2 and 3, args[idx] is set to (1, 2, 3)
with the structure
address args
where in the above example the args is a tuple with 4 values
- address = /custom/osc/message
- arg0 = 4
- arg1 = 'myTextValue'
- arg2 = 5.63
- arg3 = 1
but we can do even better -> Format-Custom-Messages