OnTagsDropped - Auto Axis to display Eng Unit Label

I am trying to auto set the axis on the tag dropped. So if I have 3 plots already (“A”,“kW”,“V”).
If I add in a new voltage tag it adds into the “A” plot instead of the “V” plot.
Is there a way to change the “Defualt Axis” to whatever the ENG unit of the tag is.

	#Set up the chart defaults. 
	default = ['DefaultName', # name
	'[~]DefaultPath', # tag_path
	'MinMax', # aggregation_mode
	'Default Axis', # axis
	1, # subplot
	True, # enabled
	"color(255,0,0,255)", # color
	'', # dash_pattern
	1, # render_style
	1.0, # line_weight
	0, # shape
	True, # fill_shape
	False, # labels
	'', # group_name
	False, # digital
	False, # override_autocolor
	False, # hidden
	True, # user_selectable
	None, # sort_order
	False] # user_removable
	tagpens = self.tagPens
	for path in paths:
		newrow = default
		newrow[0] = path.split('/')[-1]
		newrow[3] = system.tag.read("%s.EngUnit" % path).value
		newrow[6] = self.autoColorList[tagpens.rowCount % len(self.autoColorList)]
		tagpens = system.dataset.addRow(tagpens, tagpens.rowCount, newrow)
	self.tagPens = tagpens

Absolutely possible; here’s a rudimentary implementation of onTagsDropped that will do it. The “important” line is: newrow[3] = system.tag.read("%s.EngUnit" % path).value

I implemented the script and now the pen being dragged on won’t display data and can’t be deleted. It also plots along side the top chart. See Pic below.

The pen dragged on is Current_Phase_A

Here is a working script I recently wrote on Version 8.0.16: This is placed within the onTagsDropped scripting of the EasyChart:

def onTagsDropped(self, paths):
	Called when the user has dropped tags from the tag tree onto the chart.
	Normally, the chart will add pens automatically when tags are dropped, but
	this default behavior will be suppressed if this extension function is

		self: A reference to the component that is invoking this function.
		paths: A list of the tag paths that were dropped on the chart.
	# Alter chart configuration here

	#Set up the chart defaults.
	'''default = 
	[Name,TagPath,aggregation mode, axis, subplot, enabled, color, dash pattern, render style, 
	line weight, shape, fill shape, labels, group_name,digital, override autocolor, hidden, user_selectable, sort_order,user_removable]
	defaultTagPens = ['DefaultName', '[~]DefaultPath','MinMax','Default Axis', 1,True, "color(255,0,0,255)",'', 1,1.0,0, True, False, '', False, False, False, True, None, True] 

	defaultAxes = ['Default Axis','Value','Numeric',"color(255,0,0,255)","color(255,0,0,255)","color(255,0,0,255)",0,False,True,False,0.05,0.0,100.0,True,5.0,5.0,'','normal','',False,"color(232,234,232,255)","color(255,0,0,255)"]

	for path in paths:
		# create new tagPath row 
		newRow = defaultTagPens  # default list as defined above 
		# set tag name 
		tagName =  path.split('/')[-1] # tag name as a string
		newRow[0] = tagName 
		# set tag path 
		tagPath = path
		newRow[1] = tagPath
		# set color 
		color = self.autoColorList[self.tagPens.rowCount % len(self.autoColorList)]
		newRow[6] = color
		# set axis option
		engUnits = system.tag.read("%s.EngUnit" % path).value
		axisName = ''
		axisLabel = ''
		if engUnits == '':
			axisName = 'Default Axis'
			axisLabel = 'Value'
			axisName = engUnits
			axisLabel = engUnits
		print axisName
		print axisLabel
		# set axis 
		newRow[3] = axisName
		# create the tag pen row 
		tagpens = system.dataset.addRow(self.tagPens, self.tagPens.rowCount, newRow)
		# check to see if axis already exists
		currentAxes = self.axes
		pds = system.dataset.toPyDataSet(currentAxes)
		headers = system.dataset.getColumnHeaders(currentAxes)
		length = len(headers)
		# Check to see if axisLabel exists 
		createNewAxis = True
		for row in pds:		
			if row['LABEL'] == axisLabel:
				createNewAxis = False
				print 'already exists \n'
		# if it doesn't exist then create a new axis
		if createNewAxis:
			print 'creating new one' 
			#create new axis 
			newAxis = defaultAxes
			# set axis name
			print axisName
			newAxis[0] = axisName
			# set axis label
			newAxis[1] = axisLabel
			# set label color
			newAxis[3] = color
			axes = system.dataset.addRow(self.axes, self.axes.rowCount,newAxis)
			self.axes = axes
		self.tagPens = tagpens

Another working example in version 8.1. This one is a bit more simple and is geared towards UDTs.

It takes the full UDT path instead of the default ‘parameter’ for the pen name. My UDT has a “.Val” historical data tag and a “.Cfg_Desc” for the string desciption.

Window Export:
Ad Hoc Trend.zip (16.9 KB)

onTagsDropped script:

	# Alter chart configuration here
	# This will take a tag that gets dropped from a Tag Browse Tree and instead of 
	# using just the 'param' will instead use 'device/tag/param' and attempt to read description
	tagPens = self.tagPens
    	for tag in paths:
        	# incoming tag format is [database]device/tag/param
	        splitTag = tag.split("]")
	        name = splitTag[1]
	        # attempt to ready Cfg_Desc from parent UDT and set to pen's GROUP_NAME
	        # path to description is device/tag/Cfg_Desc
	        descSplit = name.split("/")
	        descPath = descSplit[0] + "/" + descSplit[1] + "/Cfg_Desc"
	        description = system.tag.readBlocking([descPath])[0].value + " " # add a trailing space for easier reading on plot
			# set color based on next auto color
	        color = self.autoColorList[self.tagPens.rowCount % len(self.autoColorList)]
	        newRow = [name, tag, "MinMax", "Default Axis", 1, 1, color, "", 1, 1, 0, 1, 0, description, 0, 0, 0, 1, "", 1]
	        self.tagPens = system.dataset.addRow(tagPens, newRow)


How do I create different axis upon dropping new tag? so Each tag can have it's own separate axis.

You have to alter the script to decide which row of the .axes property should apply, and use its name in the pen definition you add to .pens or .tagPens.