What's new

Trouble reading from an excel file

albie0803

Alibre Super User
Interestingly I found that adding a new parameter to a gear didn't have it list last when I ran your initial "get parameters" script. This got me thinking that a future edit to a part could screw up my lists, so I added a number to the front of each parameter name and stripped it out as each parameter was read and then loaded the correct value from the list using that number.

G01_Face_Angle >> 01 >> int = 1 >> Eparams[1]
 

idslk

Alibre Super User
Hello albie0803,

if you have "names" in your table like:
upload_2019-8-2_13-46-22.png
you can read the 'G14' and 'H14' and put the value from 'H14' to the EditorVariable with the Name from 'G14'...

Regards
Stefan
 

idslk

Alibre Super User
Hello albie0803,

a little example for post #22, so there is a need to have an excel-file with these cells...
i've added a test variable to an old part of mine:
upload_2019-8-2_14-42-6.png upload_2019-8-2_14-43-25.png
Code:
from openpyxl import load_workbook
from openpyxl import workbook
win = Windows()
cp = CurrentPart()
filename = win.OpenFileDialog('Select an Excel Parameter file', 'ExcelFiles|*.xls*', '*.xls*')
wb = load_workbook(filename)
ws = wb.active
variable_to_search = ws['G14'].value
#print variable_to_search
list = []
for i in cp.Parameters:
  list.append(i.Name)
if variable_to_search in list:
  print variable_to_search,'is on place',list.index(variable_to_search),'and has a value of',cp.Parameters[list.index(variable_to_search)].Value
x = ws['G14'].value
print 'x =',x
y = cp.Parameters[list.index(variable_to_search)].Name
print 'y =',y
print 'x equals y is',x==y
if x == y:
  cp.Parameters[list.index(variable_to_search)].Value = ws['H14'].value
else:
  print 'something went wrong...'
print variable_to_search,'is still on place',list.index(variable_to_search),'and has now a value of',cp.Parameters[list.index(variable_to_search)].Value
and got this output on the console:
upload_2019-8-2_15-3-39.png

As far as the indexnumber of the parameter is calculated every time the skript is started, you will get the actual position of your variable...
For a test:
upload_2019-8-2_14-52-35.png
this puts G_Addendum one place later in the list...
upload_2019-8-2_15-5-5.png

Regards
Stefan
 
Top