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
#--------------------#
# --- INPUTS --- #
#--FILE SELECTOR--#
Win = Windows()
File_Dialog = []
File_Dialog.append(['None', WindowsInputTypes.Label, 'Please enter exact filename.' + '\n' + 'Not case sensitive.'])
File_Dialog.append(['File name to modify ', WindowsInputTypes.String, '<File name>'])
File_Dialog.append(['None', WindowsInputTypes.Label, 'or'])
File_Dialog.append(['Use part in current workspace ', WindowsInputTypes.Boolean, False])
File_Dialog.append(['None', WindowsInputTypes.Label, '\n']) #For spacing
File_Dialog.append(['None', WindowsInputTypes.Label, 'Please check box if target file is an Assembly.'])
File_Dialog.append(['File is an Assembly ', WindowsInputTypes.Boolean, False])
File_Dialog.append(['File is a Part in an Assembly ', WindowsInputTypes.Boolean, False])
File_Dialog.append(['None', WindowsInputTypes.Label, '\n' 'Press OK to continue.' + '\n' + 'Press Cancel to exit script.'])
Values = Win.OptionsDialog('Current File?', File_Dialog)
if Values == None:
sys.exit(0)
File_name = Values[1]
#-- ERROR DIALOG --#
if Values[6] == False:
if Values[3] == True:
MyPart = CurrentPart()
else:
try:
MyPart = Part(File_name, False)
except:
Win.ErrorDialog('No file with that name found. Please open file and try again.', 'Error') + sys.exit(0)
elif Values[7] == True:
if Values[3] == True:
Asm = CurrentAssembly()
MyPart = Asm.GetPart(File_name)
else:
try:
Asm = Assembly(File_name, False)
MyPart = Asm.GetPart(File_name)
except:
Win.ErrorDialog('No file with that name found. Please open file and try again.', 'Error') + sys.exit(0)
else:
if Values[3] == True:
MyPart = CurrentAssembly()
else:
try:
MyPart = Assembly(File_name, False)
except:
Win.ErrorDialog('No file with that name found. Please open file and try again.', 'Error') + sys.exit(0)
#--------------------#
#MyPart = CurrentPart()
MyPart.Regenerate()
TH = 0
LG = 0
WD = 0
Win = Windows()
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)
#E = "Edge<%i>" % InputE
#Edge = MyPart.GetEdge(E)
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
#F = "Face<%i>" % InputF
#KFace = MyPart.GetFace(F)
# 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]
KeySeatData[2] = [3, 3, 1.6, 0.16]
KeySeatData[3] = [4, 4, 1.8, 0.16]
KeySeatData[4] = [5, 5, 2.3, 0.25]
KeySeatData[5] = [6, 6, 2.8, 0.25]
KeySeatData[6] = [8, 7, 3.3, 0.25]
KeySeatData[7] = [10, 8, 3.3, 0.4]
KeySeatData[8] = [12, 8, 3.3, 0.4]
KeySeatData[9] = [14, 9, 3.8, 0.4]
KeySeatData[10] = [16, 10, 4.3, 0.4]
KeySeatData[11] = [18, 11, 4.4, 0.4]
KeySeatData[12] = [20, 12, 4.9, 0.6]
KeySeatData[13] = [22, 14, 5.4, 0.6]
KeySeatData[14] = [25, 14, 5.4, 0.6]
KeySeatData[15] = [28, 16, 6.4, 0.6]
KeySeatData[16] = [32, 18, 7.4, 0.6]
KeySeatData[17] = [36, 20, 8.4, 1]
KeySeatData[18] = [40, 22, 9.4, 1]
KeySeatData[19] = [45, 25, 10.4, 1]
KeySeatData[20] = [50, 28, 11.4, 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 = MyPart.AddSketch('KeyseatProfile', MyPart.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:
MyPart.AddExtrudeCut('KeyCut %dx%d' % (KW,KH), S, Length , True, Part.EndCondition.ThroughAll, None, 0, Part.DirectionType.Normal, None, 0, False)
else:
MyPart.AddExtrudeCut('KeyCut %dx%d' % (KW,KH), S, Length , True)
MyPart.Regenerate()
[CODE/]