writeBlocking from a popup using a parameter

Can anyone tell me why this script doesn't work for me?

indirect = self.view.params.MachineNumber
 
path = '[default]CL1/{}/To Auto Mode'.format(indirect)

system.tag.writeBlocking(path, 'true')

I don't see anything in the log when I press the button to run it. I can run the script just fine in the console if I change the path for indirect to a valid path inside of "".

You're writing a string "true" to the tag. I presume you should be writing a boolean, in which case it would be,
system.tag.writeBlocking([path], [True])

Both arguements of writeBlocking expect lists, [ ], although it tolerates single elements.

There may be other problems that I haven't spotted.

2 Likes

Aside from the use of a String as opposed to a Boolean value as @Transistor details.

I presume that the MachineNumber is an integer. In which case it is possible that the resultant path would be different from the expected path.

For instance for machine number 1 the path you would get from this script is:

'[default]CL1/1/To Auto Mode'

Which if you were expecting a leading zero in the path, would not work.

All of that said? for something this simple why not use a bi-directional indirect tag binding?

3 Likes

All of the above, plus get rid of spaces in tag paths. And any other whitespace.
Actually anything that's not a letter, digit or underscore.

3 Likes

param is a string.

Was just trying to get it working with a button instead of a toggle switch. Toggle switch works great.