This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz_gears2.py

58 lines
2.3 KiB
Python
Raw Normal View History

2020-07-30 01:16:18 +02:00
#!/usr/bin/env python3
'''
Copyright (C) 2013 Matthew Dockrey (gfish @ cyphertext.net)
Based on http://arc.id.au/GearDrawing.html by Dr A.R.Collins
And on the original gears.py by Aaron Spike and Tavmjong Bah
'''
import inkex
from math import *
from lxml import etree
from fablabchemnitz_involute import *
class Gears(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.arg_parser.add_argument("--tab", default="Options", help="The tab selected when OK was pressed")
self.arg_parser.add_argument("-t", "--teeth", type=int, default=24, help="Number of teeth")
self.arg_parser.add_argument("-p", "--pressure_angle", type=float, default="20", help="Pressure angle")
self.arg_parser.add_argument("-y", "--size_type", type=int, default="1", help="Size type (1 = module (mm), 2 = pitch diameter (inches), 3 = diametral pitch (inches)")
self.arg_parser.add_argument("-s", "--size", type=float, default="5", help="Size")
self.arg_parser.add_argument("-o", "--orientation", type=int, default="1", help="Gear orientation")
def effect(self):
Z = self.options.teeth
phi = self.options.pressure_angle
size_type = self.options.size_type
size = self.options.size
orientation = self.options.orientation
# Convert size to module (mm) if needed
if (size_type == 2):
# Pitch diameter
size = 25.4 * size / Z
elif (size_type == 3):
# Diametral pitch
size = 25.4 / size
m = self.svg.unittouu(str(size) + "mm")
if (orientation == 2):
svg = CreateInternalGear(m, Z, phi)
else:
svg = CreateExternalGear(m, Z, phi)
# Insert as a new element
gear_style = { 'stroke': '#000000',
'stroke-width': self.svg.unittouu(str(0.1) + "mm"),
'fill': 'none'
}
g_attribs = {inkex.addNS('label','inkscape'): 'Gear ' + str(Z),
'transform': 'translate(' + str( self.svg.namedview.center[0] ) + ',' + str( self.svg.namedview.center[1] ) + ')',
'style' : str(inkex.Style(gear_style)),
'd' : svg }
g = etree.SubElement(self.svg.get_current_layer(), inkex.addNS('path','svg'), g_attribs)
2020-08-23 21:09:57 +02:00
Gears().run()