Tag writing from numeric field value using button

Hi guys,

wondering if anyone could point me in the correct direction for this script. I have a numeric field for a motor speed and an “Apply” button that takes the value of this field and drops it into a tag. Which worked perfectly fine when directing to a specific tag in my tag browser. However, this is in a pop up to which I’m passing certain tag parameters onto (i.e. motor 1, motor 2 etc). And I want to use the parameter’s cutomised property ID (for the name value) to be in place of the specific tag name.

Initially I had:

		value = event.source.parent.getComponent('Auto Speed').floatValue
		system.tag.writeBlocking(['[default]List/Motor_1/Auto_Spd'], [value])

Which I tried to have as…

		value = event.source.parent.getComponent('Auto Speed').floatValue
		system.tag.writeBlocking(['[default]List/{Root Container.Custom_Property::Motor_ID}/Auto_Spd'], [value])

But it wont have it with the error that the “{” of the {Root Container … is illegal.

Thank you guys! thank you for the patience.

Have you tried doing something like:

value = event.source.parent.getComponent('Auto Speed').floatValue
mID = {Root Container.Custom_Property::Motor_ID}
tag = '[default]List/%s/Auto_Spd' % (mID)
system.tag.writeBlocking([tag], [value])

When you put in “{Root Container.Custom_Property::Motor_ID}” like you did, it makes it part of the string instead of substituting in the parameter your looking for. If your combining values to create a string in a script, you have to substitute it in, in a python way.

oh yea! I see…sorrry, pretty new to coding and still trying to get the hang of it.

Thank you for the advice! could you point us in the right direction for the error I’m getting for that…

SynthaxError:("no viable alternative at input'Container'",(",9,13,"\tmID={Root Container.Custom_Property::Motor_ID}\n'))

Would it have to be a system.__.root container or an event.source, situation?

Again apologies if im butchering the synthax. Its definitely a learning curve & I appreciate all the time and advice you’re offering

It doesn’t like how you did the path to the custom property. Do you have an button to drill down to the property your looking for in the script editor? If you do, I would use that to make sure your path is right. It comes down to the custom property path. If you can get that path corrected then it should work. With out seeing exactly what your looking at though its hard to say what the correct path should be. But if I had to guess it should probably be something like:

mID = event.source.parent.Motor_ID

I’m basing that on you saying your doing this from a button and I would assume your component “Auto Speed” is directly on your root container so it should be at the same level as your custom property.

Yup, all components and costum property are on the same level.

Awesome, Thank you so much! the event source was spot on. just had to add the main reference so it ended up being

mID = event.source.parent.Motor_Reference.Motor_ID