albie0803
Alibre Super User
My keyway in a bore script is now throwing the following error
Can someone please have a look for me? It dies after entering the face and edge detail.
Code:
System.Collections.Generic.KeyNotFoundException: KeyError
at IronPython.Runtime.PythonDictionary.GetItem(Object key)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at AlibreScript.UI.IronTextBoxControl.#ijb(Object #9A)
Can someone please have a look for me? It dies after entering the face and edge detail.
Code:
print "******************** INSTRUCTIONS ********************\n"
print "1. Open part in Alibre Design."
print "2. Launch AlibreScript."
print "3. Open this script."
print "4. Fill in the prompts as presented."
print "5. Repeat 4 as required"
print "6. VOILA! And there is/are your keyseat/keyseats."
print "\n\nFor this script to function properly you will need to enter the following information..."
print "#1 The edge number of the hole in which you will be inserting the keyseat. The script generates the plane."
print "#2 The face number the key sketch is to be created on. The script generates the plane."
print "#3 The length of the key."
Units.Current = UnitTypes.Millimeters
try:
Ass = CurrentAssembly()
for P in Ass.Parts:
PName = str(P)
if "Boss" in PName:
PN = PName + "<1>"
Hub = Ass.GetPart(PN)
except:
Hub = CurrentPart()
Hub.Regenerate()
Finished = Hub.AddConfiguration('Finished')
Finished.SetLocks(LockTypes.SuppressNewFeatures)
Finished.Activate()
Win = Windows()
if Win.QuestionDialog('Do you want to cut finished bore size?', 'Optional Extra') == True:
Options = []
Options.append(["Finished Bore Diameter", WindowsInputTypes.Real, 0])
Values = Win.OptionsDialog("Finished Bore Diameter", Options, 250)
BD = float(Values[0])
# AddPlane and Sketch
S1 = Hub.AddSketch('BoreProfile', Hub.GetPlane("ZX-Plane"))
S1.AddCircle(0, 0, BD, False)
Hub.AddExtrudeCut('Bore', S1, 0, True, Part.EndCondition.ThroughAll, None, 0, Part.DirectionType.Normal, None, 0, False)
Win.InfoDialog('Activate Finished config to see key', 'Note')
TH = 0
LG = 0
WD = 0
# 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]]
KeySizes = ['2x2', '3x3', '4x4', '5x5', '6x6', '8x7', '10x8', '12x8', '14x9', '16x10', '18x11', '20x12', '22x14', '25x14', '28x16', '32x18', '36x20', '40x22', '45x25', '50x28']
Options = []
Options.append(["Choose Hole Edge", WindowsInputTypes.Edge, None])
Options.append(['Choose Key Face', WindowsInputTypes.Face, None])
Options.append(["Length: 0 for Through All", WindowsInputTypes.Real, LG])
Options.append([None, WindowsInputTypes.Image, 'HKey.png', 100])
Values = Win.OptionsDialog("Metric Hole Keyway Generator", Options, 100)
if Values == None:
sys.exit()
E = Values[0]
F = Values[1]
LG = Values[2]
Length = float(LG)
CylDia = E.Diameter
CylRad = CylDia / 2
CylDiaRanCho = 0
if CylDia > 6 and CylDia <= 8:
CylDiaRanCho = 1
elif CylDia > 8 and CylDia <= 10:
CylDiaRanCho = 2
elif CylDia > 10 and CylDia <= 12:
CylDiaRanCho = 3
elif CylDia > 12 and CylDia <= 17:
CylDiaRanCho = 4
elif CylDia > 17 and CylDia <= 22:
CylDiaRanCho = 5
elif CylDia > 22 and CylDia <= 30:
CylDiaRanCho = 6
elif CylDia > 30 and CylDia <= 38:
CylDiaRanCho = 7
elif CylDia > 38 and CylDia <= 44:
CylDiaRanCho = 8
elif CylDia > 44 and CylDia <= 50:
CylDiaRanCho = 9
elif CylDia > 50 and CylDia <= 58:
CylDiaRanCho = 10
elif CylDia > 58 and CylDia <= 65:
CylDiaRanCho = 11
elif CylDia > 65 and CylDia <= 75:
CylDiaRanCho = 12
elif CylDia > 75 and CylDia <= 85:
CylDiaRanCho = 13
elif CylDia > 85 and CylDia <= 95:
CylDiaRanCho = 14
elif CylDia > 95 and CylDia <= 110:
CylDiaRanCho = 15
elif CylDia > 110 and CylDia <= 130:
CylDiaRanCho = 16
elif CylDia > 130 and CylDia <= 150:
CylDiaRanCho = 17
elif CylDia > 150 and CylDia <= 170:
CylDiaRanCho = 18
elif CylDia > 170 and CylDia <= 200:
CylDiaRanCho = 19
elif CylDia > 200 and CylDia <= 230:
CylDiaRanCho = 20
# KW = Key Width, KH = Square Key Height, KD = Square Key Depth, KR = Keyseat Radius
# KW KH KD KR
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']
KeySeatData[4] = [5, 5, 3, 0.25,'5x5']
KeySeatData[5] = [6, 6, 3.5, 0.25,'6x6']
KeySeatData[6] = [8, 7, 4, 0.25,'8x7']
KeySeatData[7] = [10, 8, 5, 0.4,'10x8']
KeySeatData[8] = [12, 8, 5, 0.4,'12x8']
KeySeatData[9] = [14, 9, 5.5, 0.4,'14x9']
KeySeatData[10] = [16, 10, 6, 0.4,'16x10']
KeySeatData[11] = [18, 11, 7, 0.4,'18x11']
KeySeatData[12] = [20, 12, 7.5, 0.6,'20x12']
KeySeatData[13] = [22, 14, 9, 0.6,'22x14']
KeySeatData[14] = [25, 14, 9, 0.6,'25x14']
KeySeatData[15] = [28, 16, 10, 0.6,'28x16']
KeySeatData[16] = [32, 18, 11, 0.6,'32x18']
KeySeatData[17] = [36, 20, 12, 1,'36x20']
KeySeatData[18] = [40, 22, 13, 1,'40x22']
KeySeatData[19] = [45, 25, 15, 1,'45x25']
KeySeatData[20] = [50, 28, 17, 1,'50x28']
KN = KeySeatData[CylDiaRanCho][4] #KN key name
Options = []
Options.append(['Key Size', WindowsInputTypes.StringList, KeySizes, KN])
ValueC = Win.UtilityDialog('Select Key Size', 'Apply', SelectionMade, InputChanged, Options, 150)
sum = 0
for i in KeySizes:
if i == KS:
print i
print sum
readTh = sum
sum += 1
CylDiaRanCho = readTh + 1
CR = CylRad
KW = float(KeySeatData[CylDiaRanCho][0])
KH = float(KeySeatData[CylDiaRanCho][1])
KD = float(KeySeatData[CylDiaRanCho][2])
KR = float(KeySeatData[CylDiaRanCho][3])
X1 = CylRad + KD - KH
X2 = CylRad + KD
Y1 = KW / 2
print Y1
# AddPlane and Sketch
S = Hub.AddSketch('KeyseatProfile', Hub.AddPlane('KeyseatPlane', F, 0))
# draw lines
S.AddLine(X1, Y1, X2 - KR, Y1, False)
S.AddLine(X1, -Y1, X2 - KR, -Y1, False)
S.AddLine(X1, Y1, X1, -Y1, False)
S.AddLine(X2, Y1 - KR, X2, -Y1 + KR, False)
# dwaw arcs
S.AddArcCenterStartEnd(X2 - KR, Y1 - KR, X2, Y1 - KR, X2 - KR, Y1, False)
S.AddArcCenterStartEnd(X2 - KR, -Y1 + KR, X2 - KR, -Y1, X2, -Y1 + KR, False)
if Length == 0:
Hub.AddExtrudeCut('KeyCut %dx%d' % (KW,KH), S, Length , True, Part.EndCondition.ThroughAll, None, 0, Part.DirectionType.Normal, None, 0, False)
else:
Hub.AddExtrudeCut('KeyCut %dx%d' % (KW,KH), S, Length , True)
Hub.Regenerate()
Win.InfoDialog("Activate Finished config to see key", 'Note')