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
	implemented.

	Arguments:
		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'
		else: 
			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'
				continue
		
		# 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