This example demonstrate file access for an ExternalData tool def
WriteToFile():
list=[]
list.append(GetIntValue('Data.s1'))
list.append(GetFloatValue('Data.s2'))
list.append(GetStringValue('Data.t1'))
list.append(GetBoolValue('Data.l1'))
list.append(GetBoolValue('Data.l2'))
list.append(GetFloatValue('Data.p1_x'))
list.append(GetFloatValue('Data.p1_y'))
print list
f=open('storedtext.txt','w') #file stored in the Scorpion_4 directory
str0='%(list)s' %vars()
f.write(str0) #overwite with the new text
f.close()
def ReadFromFile():
#The script can be put in Central Start
#for automatic reading when Scorpion is started
f=open('storedtext.txt','r') #file stored in the Scorpion_4 directory
l=f.readlines()
print l
a=eval(l[0]) #Make it readable as a Python list
print a
SetValue('Data.s1',a[0])
SetValue('Data.s2',a[1])
SetValue('Data.t1',a[2])
SetValue('Data.l1',a[3])
SetValue('Data.l2',a[4])
SetValue('Data.p1_x',a[5])
SetValue('Data.p1_y',a[6])
f.close()
Example: content of file
[5, 9.0, 'Hello!!', False, True, 2.5, 1.5]
|