What's new

I want a dropdown box with text values that returns an integer

albie0803

Alibre Super User
Code:
KeySizes = ['2x2', '3x3', '4x4', '5x5', '6x6', '8x7', '10x8', '12x8', '14x9', '16x10', '18x11', '20x12', '22x14', '25x14', '28x16', '32x18', '36x20', '40x22', '45x25', '50x28']

# called when an input changes in the dialog window
def InputChanged(Index, Value):
  # size changed
  if Index == 0:
    global KS
    KS = KeySizes[Value]

# called when user confirms selections
def SelectionMade(Values):
  # get values
  global KS
  KS= KeySizes[Values[0]]

Win = Windows()

Options = []
Options.append([None, WindowsInputTypes.Label, 'Ok to accept or select desired size then Ok'])
Options.append(['Key Size', WindowsInputTypes.StringList, KeySizes, KN])
ValueC = Win.UtilityDialog('This will create a %d x %d Key - %d Deep' % (KW,KH,KD), 'Apply', SelectionMade, InputChanged, Options, 90)
if ValueC == None:
  sys.exit()

KeySeatData = {}
KeySeatData[1] = [2, 2, 1, 0.16, '2x2']
KeySeatData[2] = [3, 3, 1.6, 0.16,'3x3']
KeySeatData[3] = [4, 4, 2.5, 0.16,'4x4']

CD = float(CylDia)
KW = float(KeySeatData[CylDiaRanCho][0]) #KW key width
KH = float(KeySeatData[CylDiaRanCho][1]) #KH key height
KD = float(KeySeatData[CylDiaRanCho][2]) #KD key depth
KR = float(KeySeatData[CylDiaRanCho][3]) #KR key radius
KN = KeySeatData[CylDiaRanCho][4] #KN key name

upload_2018-11-15_14-28-9.png

When I click apply I get: python list indices must be integer or slice, not none

What I am trying to do is put the sizes in a list and get a value back to use to read from the data list

Educate me please someone :)
 

idslk

Alibre Super User
Hello Albie,

if you use the WindowsClass in Alibre Script each Option has a own Value.
First appended Option populates Values[0],
second appended Option populates Values[1] and so on...
The options .Image and .Label will create a Value None.
So Values[] will contain also this None from your first element in Win.UtilityDialog.
Try to use the second Value/Values... KS= KeySizes[Values[1]]

Also the if ValueC == None: will get the first option (this is your Label) and this is None
So you will ever get an sys.exit().
This will be the same no matter on which position you add a label or image...
As far as you are using the UtilityDialog there will be no chance to leave the Requester without a Value.
The Dialog calls always SelectionMade or InputChanged. The sys.exit makes no real sense i think.

Regards
Stefan
 

NateLiquidGravity

Alibre Super User
As Stefan mentioned Values will have something for every option even if the options are just labels or pictures.

However there are a bunch of errors and some things that won't work currently in your script. I will try to fix them tonight and reply back.
 

albie0803

Alibre Super User
Hey Nate I saw Stefan's reply last night and slept on it and it made sense in the morning as it gelled with what I had already learnt. I have been able to fix it , understand why it is fixed and get the script working the way I want.

Thanks Stefan so much for your insight and instruction, most appreciated.
 
Top