What's new

Scripting Help

albie0803

Alibre Super User
Why does the following code throw an error on line 25?
I get
>>>
File "", line 25
SKey = [
^
SyntaxError: unexpected token 'SKey'
>>>

Python:
Win = Windows()

Units.Current = UnitTypes.Millimeters

P = CurrentPart()
P.Regenerate

stringlist_no = ['No Edge selected...']
KeySizes = [stringlist_no[0]]

RKey = [
[7.9375,6.35,3.7846,0.254,'5/16x1/4',25.4,31.75,1],
[9.525,6.35,3.8862,0.254,'3/8x1/4',31.75,38.1,2],
[11.1125,7.9375,4.8006,0.508,'7/16x5/16',38.1,44.45,3],
[12.7,7.2644,4.9022,0.508,'1/2x5/16',44.45,50.8,4],
[15.875,11.1125,6.6802,0.508,'5/8x7/16',50.8,63.5,5],
[19.05,12.7,7.6708,0.508,'3/4x1/2',63.5,76.2,6],
[22.225,15.875,9.4742,1.5748,'7/8x5/8',76.2,88.9,7],
[25.4,19.05,11.2776,1.5748,'1x3/4',88.9,101.4,8,
[28.575,22.25,112,1.5748,'1-1/8',101.4,116,9],
[31.75,22.25,13.2334,1.5748,'1-1/4x7/8',116,127,10],
[38.1,25.4,15.2908,1.5748,'1-1/2x1',127,152.4,11]
]

SKey = [
[3.175,3.175,1.905,0.254,'1/8',6.35,12.7,1],
[4.7625,4.7625,2.794,0.254,'3/16',12.7,19.05,2],
[6.35,6.35,3.683,0.254,'1/4',19.05,25.4,3],
[7.9375,7.9375,4.572,0.254,'5/16',25.4,31.75,4],
[9.525,9.525,5.4864,0.254,'3/8',31.75,38.1,5],
[11.1125,11.1125,6.3754,0.508,'7/16',38.1,44.45,6],
[12.7,12.7,7.9375,0.508,'1/2',44.45,50.8,7],
[15.875,15.875,9.0678,0.508,'5/8',50.8,63.5,8],
[19.05,19.05,10.8458,508,'3/4',63.5,76.2,9],
[22.225,22.225,12.6492,1.5748,'7/8',76.2,88.9,10],
[25.4,25.4,14.4526,1.5748,'1',88.9,101.4,11],
[28.575,28.575,16.2,1.5748,'1-1/8',101.4,116,12],
[31.75,31.75,18.034,1.5748,'1-1/4',116,127,13],
[38.1,38.1,21.6154,1.5748,'1-1/2',127,152.4,14]
]
 
Last edited:

albie0803

Alibre Super User
Next Question: Does Scripting have a list input box for multiple selections?
Probably not, but I thought I'd ask the question
 
Last edited:

NateLiquidGravity

Alibre Super User
Keep in mind running scripts with WindowsInputTypes.StringList on a Windows 7 pc will most likely cause Alibre to become completely frozen. The only current workaround to that is to build your own forms - not an easy task,
 

albie0803

Alibre Super User
OK, I have implemented the following code, I just need help with the updateuiF command.
Python:
  FL = []
    
  def updateuiF()
    #code to change the label text to show the number of edges selected.
    pass

  def onchangeF(index,value):
    global cnt
    if index == 0:
      FL.append(value)
      cnt = cnt+1

  Options = []
  Options.append(["Select Key Edges to Fillet", WindowsInputTypes.Edge, None])
  Options.append([None, WindowsInputTypes.Label, 'Edges Selected:'])
  Value = Win.OptionsDialog("Metric Shaft Keyway Generator - Dialog 2/2", Options, 90, onchangeF,updateuiF)
  if Value == None:
    sys.exit()

  P.AddFillet('%sKey-R%.2f' % (KN,KR), FL, KR, True)
 
Last edited:

NateLiquidGravity

Alibre Super User
OK, I have implemented the following code, I just need help with the updateuiF command.
Thats a lot of work to accomplish what you could do by just changing WindowsInputTypes.Edge to WindowsInputTypes.Edges and holding down shift when selecting:
Python:
Win = Windows()
Options = []
Options.append(["Select Key Edges to Fillet", WindowsInputTypes.Edges, None])
Value = Win.OptionsDialog("Metric Shaft Keyway Generator - Dialog 2/2", Options, 200)
if Value == None:
    sys.exit()
 

albie0803

Alibre Super User
Thanks, I did try edges but forgot to hold shift so I could only get one edge to show.

what is the correct syntax for:

Alibre Script: AlibreScript.API Namespace Reference
Optional settings:
  • Input box height in pixels (integer)
 

albie0803

Alibre Super User
How do you implement win.DisableInput() so that an option is disabled when the window first appears?

I know how to use enable/disable in an onchange function but not at startup.
 

idslk

Alibre Super User
Using Nate's Example:

Python:
Win = Windows()

def disable_on_startup():
  Win.DisableInput(0)

Options = []
Options.append(["Select Key Edges to Fillet", WindowsInputTypes.Edges, None])
Value = Win.OptionsDialog("Metric Shaft Keyway Generator - Dialog 2/2", Options, 200,None,disable_on_startup)
if Value == None:
    sys.exit()

Regards
Stefan
 

idslk

Alibre Super User
using your example:

Python:
Win = Windows()

cnt=0
toggle_input = True
toggle_input_nr = 2
FL = []
    
def updateuiF():
  global toggle_input
  if toggle_input == True:
    Win.DisableInput(toggle_input_nr)
    print "done off"
  if toggle_input == False:
    Win.EnableInput(toggle_input_nr)
    print "done on"
  pass

def onchangeF(index,value):
  global cnt, toggle_input
  if index == 0:
    FL.append(value)
    cnt = cnt+1
  if index == 3 and value == True:
    toggle_input = False
  elif index == 3 and value == False:
    toggle_input = True
  updateuiF()

Options = []
Options.append(["Select Key Edges to Fillet", WindowsInputTypes.Edge, None])
Options.append(['None', WindowsInputTypes.Label, 'Edges Selected:'])
Options.append(['Select a face', WindowsInputTypes.Face, None]) # 8
Options.append(['disable/enable select face', WindowsInputTypes.Boolean, None]) # 8
Value = Win.OptionsDialog("Metric Shaft Keyway Generator - Dialog 2/2", Options, 90, onchangeF,updateuiF)
if Value == None:
  sys.exit()
 

NateLiquidGravity

Alibre Super User
Here was the script I made years ago testing: Example of all WindowsInputTypes for an OptionsDialog

It is older and doesn't have some of the optional things for the WindowsInputTypes or some of the newer Windows() functions like:
CloseForm (string SessionIdentifier)
GetInputValue (int Index)
SetInputValue (int Index, object Value)
SetStringList (int Index, object Strings)
GetDisplayedForm (string SessionIdentifier)

I do have some scripts that use these other things though so ask if you need examples.
 
Top