Dynamic Powerchart popup (Help!)

Hi there, I am having issues with a concept of mine, I would love some help, or someone to point out what I am doing wrong

The idea that I have and want to implement is a Powerchart popup, this popup is launched from a component view, whatever the component view is displaying will then show on the popup as line graphs.

The component used in this example is a load indicator for our plant’s UPS:

image

Now this component has four values namely, L1,L2,L3 and Avg

I want them to be displayed on the powerchart when I hit the button on the right top corner.

When this button is pressed parameters are passed to the popup window, these values are the path of the component and then the tag postfixes. The path is the path of the component, in this example it is “UPS/Load”. UPS is the page name, Load is the component name, this is assigned by scripting.

I do this because my tags follow the same structure, the tags here are “UPS/Load_L1”, “UPS/Load_L2”, “UPS/Load_L3” and “UPS/Load_Avg”

So I can build the tag paths if I have a list of tag postfixes on the component, so the other parameter is a list called tags, this is manually populated but will only be required to do once for every unique view, this current list has “Avg,L1,L2 and L3 in it”

In the popup window itself there is a pen that I use for a template, I have a feeling this is where I am going wrong, anyways:

So these values are passed, and the following code executes (onStartup Script)

def runAction(self):
	"""
	Method that will run whenever the selected event fires.

	Arguments:
		self: A reference to the component that is invoking this function.
	"""
	
	print "Chart Popup Started"

	Pen = self.getChild("root").getChild("PowerChart").props.pens[0]
	
	#get path
	Path = self.params.CalledFrom
	print "- Path: " + str(Path)
	
	Tagname = ""
	
	#create tag name, error catch
	if Path != "":
		Tagname = Path[self.params.CalledFrom.rindex("/")+1:]
	
	print "- Tagname: " + str(Tagname)
	
	#Get Pen Array
	PenArray = self.getChild("root").getChild("PowerChart").props.pens
	
	#get Tags Array
	TagArray = self.params.Tags
	
	#count list items
	
	TagCount = 0
	
	print "- Counting Tags"
	
	for x in TagArray:
		print "-- Tag["+ str(TagCount) + "]: " + str(TagArray[TagCount])
		TagCount = TagCount +1
	
	print "- Tags Counted: " + str(TagCount)
	
	print "- Creating " + str(TagCount) +" Pens"
	
	#Add a pen for every Tag in list
	#Tag is actually the string that is appended to the path
	for item in range(TagCount):
			
		PenArray.append(Pen)
		
	#If list was populated, (tags parameters more than one), remove template
	print "- " + str(len(PenArray)) + " Pens in total"
	
	if len(PenArray) > 1:
	
		print "- More than one pen found, discarding template pen"
	
		#remove initial pen that was copied if there are more than one
		#This keeps the list populated when opening in designer
		PenArray.pop(0)
		
		print "- " + str(len(PenArray)) + " Pens left"
		
		#Give a name for each pen, appends underscore and append name if append value in tag is not empty
		#assign source path for every component
		
		print "- Assigning names and source paths"
		for x in range(len(PenArray)):
		
			print "-- Pen " + str(x) + ":"
			
			print "-- TagArray[" + str(x) + "] = " + str(TagArray[x])
			
			try:
				if TagArray[x] != "" :
					print "-- name: " + str(Tagname) + str("_") + str(TagArray[x])
					PenArray[x].name = str(Tagname) + str("_") + str(TagArray[x])
					print "-- source: " + "histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:" + str(Path) + "_" + str(TagArray[x])
					PenArray[x].data.source = "histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:" + str(Path) + "_" + str(TagArray[x])
					
				else:
					PenArray[x].name = str(Tagname)
					PenArray[x].data.source = "histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:" + str(Path)		
				
			except:
				print "-- Could not assign pen " + str(x)
				print "--- exec info: " + sys.exc_info()
			
			print "-- Assigned name: " + PenArray[x].name
			print "-- Assigned source: " + PenArray[x].data.source
	

But this is the print out I get:

INFO   | jvm 1    | 2021/05/31 11:52:14 | Chart Popup Started
INFO   | jvm 1    | 2021/05/31 11:52:14 | - Path: UPS/Load
INFO   | jvm 1    | 2021/05/31 11:52:14 | - Tagname: Load
INFO   | jvm 1    | 2021/05/31 11:52:14 | - Counting Tags
INFO   | jvm 1    | 2021/05/31 11:52:14 | -- Tag[0]: Avg
INFO   | jvm 1    | 2021/05/31 11:52:14 | -- Tag[1]: L1
INFO   | jvm 1    | 2021/05/31 11:52:14 | -- Tag[2]: L2
INFO   | jvm 1    | 2021/05/31 11:52:14 | -- Tag[3]: L3
INFO   | jvm 1    | 2021/05/31 11:52:14 | - Tags Counted: 4
INFO   | jvm 1    | 2021/05/31 11:52:14 | - Creating 4 Pens
INFO   | jvm 1    | 2021/05/31 11:52:14 | - 5 Pens in total
INFO   | jvm 1    | 2021/05/31 11:52:14 | - More than one pen found, discarding template pen
INFO   | jvm 1    | 2021/05/31 11:52:15 | - 4 Pens left
INFO   | jvm 1    | 2021/05/31 11:52:15 | - Assigning names and source paths
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Pen 0:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- TagArray[0] = Avg
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- name: Load_Avg
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:UPS/Load_Avg
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned name: 
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Pen 1:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- TagArray[1] = L1
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- name: Load_L1
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:UPS/Load_L1
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned name: 
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Pen 2:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- TagArray[2] = L2
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- name: Load_L2
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:UPS/Load_L2
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned name: 
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Pen 3:
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- TagArray[3] = L3
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- name: Load_L3
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:UPS/Load_L3
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned name: 
INFO   | jvm 1    | 2021/05/31 11:52:15 | -- Assigned source: histprov:IgnitionDB:/drv:ignition-gbctprsrv:default:/tag:

As you can see, it all runs okay, but the value itself is never assigned, what could be the cause of this (persistence?) and how do I get around it?

I’m stumped

I tried testing your code and it ran fine for me, but I tested it on a button action event instead of an onStartup event. For the test, I set the TagArray variable to a static list of strings, replaced all the print functions with system.perspective.print(), and I had to change to getSibling() on the parameter calls (due to using a button event). So maybe something to do with the timing of the view initializing and when the onStartup script runs? Maybe a rogue Property Change Script or component level onStartup event somewhere that is overwriting this script (could rule these out by testing with an entirely new view and components)?

1 Like

Thank you for the effort

So your pens array gets appended and the name and source values change? That is strange, I will have a look, I rarely use startup scripts and the view itself has no other scripts

Yep, go from 1 pen to 4 pens, and all the name/source values are set as expected.

So I tried it on a button, but that had the same effect, so it couldn’t be timing. Then after fiddling around quite a bit I discovered that if I add an axes to it it works.

No idea why the print statement isn’t display what it assigned, but I am going to leave it at that. Thanks for the help, I figured it was coding seeing that I am not 100% comfortable with python yet