How to find source name in pointlink
-
Newbie here:
I am trying to setup a pointlink between datapoints of two different datasources. The source point is a numeric value, which must return a string value. I need the source datapoint name to appear in the string as well - I.e. if my source datapoint name is point1, the return string will be point1_1 -
but I want to implement programmatically something like this:var x = source.value; if(x == 1.0) return [sourcename]+'_1'; else return [sourcename]+'_0';
Is there a way to achieve this? Our production setup will have around 400 of these pointlinks so it's really not practical to let the client manually input the datapoint name for each of these strings.
Thanks
-
Hi mariealtin,
Unfortunately there is not a way to currently reference information about the target or source points from within the script. It wouldn't be very much to add, so I'll bring it up to people.
One could programmatically fill those in, if you're interested in a workaround. Simply keep using "[sourcename]" where you'd like the name in the script, perhaps like this,
var x = source.value; if(x == 1.0) return '[sourcename]_1'; else return '[sourcename]_0';
Then export your pointLinks and dataPoints to JSON, and try out this python script:
import json configFile = open("/path/to/config.json") config = json.load( configFile ) configFile.close() dpXidMap = {} for dp in config["dataPoints"] : dpXidMap[dp["xid"]] = dp for pl in config["pointLinks"] : pl["script"] = pl["script"].replace("[sourcename]", dpXidMap[pl["sourcePointId"]]["name"]) outputFile = open("/path/to/output.json", "w+") outputFile.write(json.dumps(config, separators=(",",": "), indent=4, sort_keys=False)) outputFile.close()
Which should do all that text replacement for you, and write JSON you can import to the output.json file.
-
Hi phildunlap
Thank you for your reply - it would be great if this information could be readily available from within the source/target objects but this solution should do the trick - I'll try it out.
-
Certainly! Welcome to our forum!