What's new

Python Gear Generator script

jcdammeyer

Senior Member
I've updated my copy of the GearGenerator Script so that I can use module instead of Pitch Diameter. I'd also like to be able to specify internal or external gears like FreeCAD can.
Here's the python code with the changes.
# Gear Generator Script # Used as a demonstration of how to create a custom utility # for use with Alibre Design # 18DEC2021 -- John Dammeyer # -- Added Module parameter Units.Current = UnitTypes.Millimeters # default settings NumberofTeeth = 20 Module = 1.0 PitchDiameter = 0 PressureAngle = 20 Thickness = 3 Win = Windows() ScriptName = 'Gear Generator' # create dialog window and show to user Options = [] Options.append([None, WindowsInputTypes.Image, 'GearGenerator.png', 170]) Options.append(['Number of Teeth', WindowsInputTypes.Integer, NumberofTeeth]) Options.append(['Module (mm)', WindowsInputTypes.Real, Module]) Options.append(['Pitch Diameter (mm)', WindowsInputTypes.Real, PitchDiameter]) Options.append(['Pressure Angle', WindowsInputTypes.Real, PressureAngle]) Options.append(['Thickness (mm)', WindowsInputTypes.Real, Thickness]) Values = Win.OptionsDialog(ScriptName, Options, 170) if Values == None: sys.exit() print "Working..." # get user inputs NumberofTeeth = Values[1] Module = Values[2] PitchDiameter = Values[3] PressureAngle = Values[4] Thickness = Values[5] # get current part MyPart = CurrentPart() # get the plane to create the gear on GearPlane = MyPart.XYPlane if (PitchDiameter==0): PitchDiameter = NumberofTeeth * Module; else: if (NumberofTeeth != 0): Module = PitchDiameter/NumberofTeeth; # create the sketch then extrude it ProfileSketch = MyPart.AddGearNP("Profile", NumberofTeeth, PitchDiameter, PressureAngle, 0, 0, False, GearPlane) Gear = MyPart.AddExtrudeBoss("Gear", ProfileSketch, Thickness, False) print "Done"

Where do I find documentation on AddGearNP(...)? Is one of the other parameters for inner or outer?

Thanks
John
 

simonb65

Alibre Super User
Just a tip on posting code, use the Code tag to automatically format text for you, makes it much easier to read ...

1639920630630.png

i.e.

Python:
# Gear Generator Script
# Used as a demonstration of how to create a custom utility
# for use with Alibre Design
# 18DEC2021 -- John Dammeyer
#   -- Added Module parameter

Units.Current = UnitTypes.Millimeters

# default settings
NumberofTeeth = 20
Module = 1.0
PitchDiameter = 0
PressureAngle = 20
Thickness = 3

Win = Windows()

ScriptName = 'Gear Generator'

# create dialog window and show to user
Options = []
Options.append([None, WindowsInputTypes.Image, 'GearGenerator.png', 170])
Options.append(['Number of Teeth', WindowsInputTypes.Integer, NumberofTeeth])
Options.append(['Module (mm)', WindowsInputTypes.Real, Module])
Options.append(['Pitch Diameter (mm)', WindowsInputTypes.Real, PitchDiameter])
Options.append(['Pressure Angle', WindowsInputTypes.Real, PressureAngle])
Options.append(['Thickness (mm)', WindowsInputTypes.Real, Thickness])
Values = Win.OptionsDialog(ScriptName, Options, 170)
if Values == None:
  sys.exit()

print "Working..."

# get user inputs
NumberofTeeth = Values[1]
Module = Values[2]
PitchDiameter = Values[3]
PressureAngle = Values[4]
Thickness = Values[5]

# get current part
MyPart = CurrentPart()

# get the plane to create the gear on
GearPlane = MyPart.XYPlane
if (PitchDiameter==0):
  PitchDiameter = NumberofTeeth * Module;
else:
  if (NumberofTeeth != 0):
    Module = PitchDiameter/NumberofTeeth;

# create the sketch then extrude it
ProfileSketch = MyPart.AddGearNP("Profile", NumberofTeeth, PitchDiameter, PressureAngle, 0, 0, False, GearPlane)
Gear = MyPart.AddExtrudeBoss("Gear", ProfileSketch, Thickness, False)

print "Done"
 

albie0803

Alibre Super User
documentation on AddGearNP(...)
Look it up in the reference guide on the script tab and no, these functions are for external gears only. These functions create "default" gears, in that you can't play with centre distances if you want to. These are also not true involute curve gear faces either, and are really only suitable for model placeholder gears. That being the case, I wrote an extrude Cut int/ext script that approximates the tooth shape but has the correct depth from the OD, (Therefore variable), and can do helicals. It only does 1 tooth as patterns are not scriptable at this time but it works for me. I work in a gear shop so nothing I draw has to be accurate as far as tooth shape is concerned as it's all machine generated.
 

jcdammeyer

Senior Member
Look it up in the reference guide on the script tab and no, these functions are for external gears only. These functions create "default" gears, in that you can't play with centre distances if you want to. These are also not true involute curve gear faces either, and are really only suitable for model placeholder gears. That being the case, I wrote an extrude Cut int/ext script that approximates the tooth shape but has the correct depth from the OD, (Therefore variable), and can do helicals. It only does 1 tooth as patterns are not scriptable at this time but it works for me. I work in a gear shop so nothing I draw has to be accurate as far as tooth shape is concerned as it's all machine generated.
The AddGearNP() method is what creates the tooth profile. I could probably create one involute gear tooth profile and then repeat it. However I think that should be the job of AlibreCAD or that AddGearNP() function. But you are right, ultimately the profile is made by cutters so it doesn't matter. But it would be nice if it were accurate.
 
Top