Indirect Address Script

I have a script attached for a button that resets a PM counter. Im making a template for each line. The Template has a custom property called "PMno"
I would like the PMno to point at the "20" in "WeekADDVAR20" and DateCalc20. What is the correct was the point at the PMno?

today = system.date.now()
weeks = system.tag.read("PM/PM Week Add/WeekADDVAR20").value
WeeksFromToday = system.date.addWeeks(today, weeks)
system.tag.write("PM/Date Calculation/DateCalc20", WeeksFromToday)

There are many ways to format strings in python, I used this one:

some_variable = 42
some_string = "some words {}".format(some_variable)

This will result in some_string == "some word 42"

Search "string format python 2" on google, you'll find other methods.

I would use an expression on the date tags instead of using a script. The script would write to an "offset" integer tag that would hold the weeks value, 20 for instance. That way you could use the tag value to know the date range without any kind of parsing if you needed it for other scripts.

The 20 is the PM number so i have a screen with a list of 20 PMs. The 20 I want to try to pull is from the custom property(PMno) of the template.
Example:

weeks = system.tag.read("PM/PM Week Add/WeekADDVAR{PMno}").value

I think im addressing the PMno incorrectly.

You are expecting a python string constant with braces in it to magically perform a substitution. Braces are an expression language tool to look up tags and properties, not python.

You need to construct that string with python operations. (It's v7.9, which uses python 2.5 syntax, so modern python's .format() isn't available. Use classic python's % string interpolation operator.)

PMno = 20
tagPath = "PM/PM Week Add/WeekADDVAR%s" % PMno
weeks = system.tag.read(tagPath).value
2 Likes

Just to clarify a bit on what @dkhayes117 shows, if you have multiple values you want to substitute then you provide a tuple of those following the %, order in the tuple needs to match the order the parameters are provided in the string. The %s denotes that you are providing a string value. If you need to substitute formatted numbers then there is a different notation for that.

machineNumber = 10
PMno = 20
tagPath = "%s/PM/PM Week Add/WeekADDVAR%s" % (machineNumber,PMno)
print tagPath

Output:

>>>
10/PM/PM Week ADD/WeekADDVAR20
>>>
2 Likes