What's new

Passing variables from a function and making them global.

oldfox

Alibre Super User
How can I make "Size" a global variable that I can use through the rest of the script?
************************************************************************************************
# default diameter to show
DefaultDiameter = 'None Selected'

# called when an input changes in the dialog window
def InputChanged(Index, Value):
# size changed
if Index == 0:
Size = DiameterNames[Value]
print "Input Changed Size is %s" % Size

# called when user confirms selections
def SelectionMade(Values):
# get values
Size = DiameterNames[Values[0]]
print "Selection Made Size is %s" % Size

# get access to windows functionality
Win = Windows()

# list of diameters to choose from
DiameterNames = ['None Selected', 'M6', 'M8', 'M10', 'M12']

# create dialog window
Options = []
Options.append(['Size', WindowsInputTypes.StringList, DiameterNames, DefaultDiameter])

# show dialog window to user
DialogWidth = 400
Win.UtilityDialog('Size', 'Apply', SelectionMade, InputChanged, Options, DialogWidth)
 

idslk

Alibre Super User
Hello oldfox,

Code:
# default diameter to show
DefaultDiameter = 'None Selected'

# called when an input changes in the dialog window
def InputChanged(Index, Value):
# size changed
  global Size
  if Index == 0:
    Size = DiameterNames[Value]
    print "Input Changed Size is %s" % Size

# called when user confirms selections
def SelectionMade(Values):
# get values
  global Size
  Size = DiameterNames[Values[0]]
  print "Selection Made Size is %s" % Size

# get access to windows functionality
Win = Windows()

# list of diameters to choose from
DiameterNames = ['None Selected', 'M6', 'M8', 'M10', 'M12']

# create dialog window
Options = []
Options.append(['Size', WindowsInputTypes.StringList, DiameterNames, DefaultDiameter])

# show dialog window to user
DialogWidth = 400
Win.UtilityDialog('Size', 'Apply', SelectionMade, InputChanged, Options, DialogWidth)

print Size

Regards
Stefan
 

oldfox

Alibre Super User
# size changed global Size

Hi Stefan,

Yep. That's what I needed. I just couldn't find anything in the "help" section to let me know how to do it. And I don't know Python.

Thanks a lot. That will open up a whole lot of usefulness on a project I have been working on. (A new script)

Thanks again,
Chris
aka oldfox
 

oldfox

Alibre Super User
Thanks Nate for throwing that back out here. I saw it the first time but it wasn't what I needed at the time so I didn't spend too much time on it.
Now it all makes sense and I can go back to it whenever I want to pass variables again. Thanks again.
 
Top