This factory function trick I found in the old SpurGear script. :)
Unfortunatelly, I can't find the original thread and the author name of this script.
Hello, I made an update to the gear script.
It adds a checkbox for planetary gears, and creates properly-meshing ring-gear.
Simply Addendum and Dedendum values are switched.