How to fix AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'toDataset'

Hi ,I have rewrite the excel file to create a memory dataset type tag in ignition, but I could not create a new dataset , could you please help to check which is wrong and how to fix it, Thanks

import math
from org.apache.commons.math3.analysis.function import Log, Log10
def finaloutput():
	#print("Starting Calculation")
	input= system.tag.read("[default]input").value
	pipeline_inputs = system.tag.read("[default]pipeline_inputs").value
	output1 = system.tag.read("[default]output1").value
	pyds1 =system.dataset.toPyDataSet(output1)
	pyds2 =system.dataset.toPyDataSet(input)
	pyds3 =system.dataset.toPyDataSet(pipeline_inputs)
	OD = pyds3[0][1]
	WT = pyds3[1][1]
	C= pyds3[3][1]
	m= pyds3[4][1]
	Load_Array=[]
	for column in pyds2:
		value=column[1]
		Load_Array.append(value)      
	#34685
	number_of_loads = output1.getRowCount()
	#U column
	urange=[]
	for column in pyds1:
		Range=column[1]
		urange.append(Range)
	#print urange
	#W column
	wcycles=[]
	for column in pyds1:
		Cycles=column[3]
		wcycles.append(Cycles) 
	#print wcycles
	pressure_range=[]
	for i in range(0,1210,10):
		pressure_range.append(i)
	#sum of cycles 
	Sum_w=[0]*120
	for i in range(0,120):
		for j in range(0,number_of_loads):
			if 10*i<urange[j]<=10*(i+1):
				Sum_w[i]=Sum_w[i]+wcycles[j]
	Sum_w.insert(0,0)
	stressrange=[]
	j=0
	for j in range(len(pressure_range)):
		stressvalue=(pressure_range[j])*OD/(2*WT)
		j+=1
		stressrange.append(int(round(stressvalue)))
#	x=1
#	N=[]
#	x10=Log10()
#	for x in range(1,len(stressrange)):
#		logval=stressrange[x]/1000
#		Cycles=x10.value(logval)
#		nvalue=math.pow(10,C-m*Cycles)
#		N.append(nvalue)
#	print N
	N=[]
	x=1
	for x in range(1,len(stressrange)):
		logval=math.log(stressrange[x],10)-3
		nvalue=math.pow(10,C-m*logval)
		x+=1
		N.append(nvalue)
	N.insert(0,0)
	D=[]
	i=1
	for i in range(1,len(pressure_range)):
		damge=Sum_w[i]/N[i]
		i+=1
		D.append(damge)
	D.insert(0,0)
	CumD=[]
	Sum=0
	for i in range(1,len(D)):
		Sum=Sum+D[i]
		CumD.append(Sum)
	CumD.insert(0,0)
	print CumD
	cumulative_damage=CumD[-1]
	str_level=13000
	SMYS=pyds3[2][1]
	SSI=cumulative_damage*math.pow(10,C-m*(math.log(str_level,10)-m))
	SSI_stresspercent=str_level/SMYS*100
	remaining_life=1/(cumulative_damage/(max(Load_Array)/(356*1440)))
	pro_of_failure=1-math.pow(math.e,(-1)*math.pow(5*cumulative_damage,2.5))
	print SSI
	print SSI_stresspercent
	print remaining_life
	print pro_of_failure
	print cumulative_damage
	headers=["SSI","SSI%","remaining_life","stresslevel","pro_of_failure","cumulativedamge"]
	data=[]
	data.append([SSI,SSI_stresspercent,remaining_life,str_level,pro_of_failure,cumulative_damage])
	system.tag.writeBlocking("[default]pressure",system.dataset.toDataset(headers,data),pressure)
#	pressurecycles=[]
#	i=0
#	for i in range(0,len(pressure_range)):
#		pressurecycles.append([pressure_range[i],Sum_w[i],stressrange[i],N[i],D[i],CumD[i]])
#	system.tag.writeBlocking("[default]pressurecycles",system.dataset.toDataSet(['P','n','stressrange','N','D','CumD'],pressurecycles))

The function is system.dataset.toDataSet

notice the Capital S, you don’t want to know how many times I’ve seen that fault. Remember that case sensitivity is a thing in jython/python.

Thank you, after I change the Captial S. I still get the error,IndexError: Row 0 doesn’t have the same number of columns as header list.

Can you post the full error?

Even without it I can tell you something is wrong with your system.tag.writeBlocking code because the first 2 arguments should be lists and if you use a 3rd argument it’s only for a timeout value.

waterfall.handler3.finaloutput()
25.9965292099
37.1428571429
18232.6622794
2.67019739653e-12
4.69510438502e-06
Traceback (most recent call last):
File “”, line 1, in
File “module:waterfall.handler3”, line 94, in finaloutput
IndexError: Row 0 doesn’t have the same number of columns as header list.

What line is line 94?

system.tag.writeBlocking("[default]pressure",system.dataset.toDataSet([headers,data],pressure))

Ok, well what @Kevin.Herron said. You’re trying to write a dataset to a pressure tag, that seems wrong, and you’re passing a variable called ‘pressure’ as the write time out. That also seems wrong

Oh wait, you changed it. But it still looks wrong, as now you’ve moved the pressure inside of the to dataset function

Both your method calls are wrong here :frowning:

Try this, broken out for clarity:

ds = system.dataset.toDataSet(headers,data)
system.tag.writeBlocking("[default]pressure", ds)

Except I have no idea what you were trying to do with the pressure variable.

Based on the tag name maybe you just want to write the pressure variable to the pressure tag, but then I don’t know what you’re doing with the DataSet.

I can’t even see where that pressure variable is defined in your code, unless it’s only a snippet?

after trying this

pressure=[]
	headers=["SSI","SSI%","remaining_life","stresslevel","pro_of_failure","cumulativedamge"]
	data=pressure.append([SSI,SSI_stresspercent,remaining_life,str_level,pro_of_failure,cumulative_damage])
	ds = system.dataset.toDataSet(headers,data)
	system.tag.writeBlocking("[default]pressure", ds)

I get the new error:Java Traceback:
Traceback (most recent call last):
File “”, line 1, in
File “module:waterfall.handler3”, line 94, in finaloutput
at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.toDataSet(DatasetUtilities.java:516)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.lang.NullPointerException: java.lang.NullPointerException

The output pressure tag should made from several numbers which is SSI,SSI% I have print it out, I want them get a tag in ignition. thanks

You shouldnt be assigning data to the result of that append. Append doesn’t return the list, it mutates the list itself. You need to do this in two steps.
pressure.append([…])
data=pressure

1 Like
pressure=[]
	headers=["SSI","SSI%","remaining_life","stresslevel","pro_of_failure","cumulativedamge"]
	pressure.append([SSI,SSI_stresspercent,remaining_life,str_level,pro_of_failure,cumulative_damage])
	data=pressure
	ds = system.dataset.toDataSet(headers,data)
	system.tag.writeBlocking("[default]pressure", ds)

Thank you so much, I get the tag.