-
Notifications
You must be signed in to change notification settings - Fork 5
/
BevelGear.py
59 lines (46 loc) · 2.03 KB
/
BevelGear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#Author- Christopher Mühl
#Description- Creates parametric bevel gears
# PEP-0008 https://www.python.org/dev/peps/pep-0008/#introduction
import adsk.core
import adsk.fusion
import traceback
import math
from .bevel_gear.cfg import handlers
from .bevel_gear.attributes import BevelGearAttributes
from .bevel_gear.handlers.commandCreated import CommandCreatedHandler
BEVEL_GEAR_BUTTON = 'pdrmConstructBevelGear'
def run(context):
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Create a new command definition for an action button and add
# it to the "Create" toolbar in the "Solid" tab
cmdDef = ui.commandDefinitions.addButtonDefinition(BEVEL_GEAR_BUTTON, 'Bevel Gear', 'Constructs a bevel gear pair', 'Resources/icons')
ui.allToolbarPanels.itemById('SolidCreatePanel').controls.addCommand(cmdDef)
# Register our gear command handler to the command created
# event of the command definition
handler = CommandCreatedHandler()
cmdDef.commandCreated.add(handler)
handlers.append(handler)
# Notify the user about a new command only if the add-in
# was started manually (i.e. not at startup)
if context['IsApplicationStartup'] == False:
ui.messageBox('The "Bevel Gear" command has been added\nto the CREATE panel of the MODEL workspace.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Remove the command definition and button from Fusion again
createPanel = ui.allToolbarPanels.itemById('SolidCreatePanel')
gearButton = createPanel.controls.itemById(BEVEL_GEAR_BUTTON)
if gearButton:
gearButton.deleteMe()
cmdDef = ui.commandDefinitions.itemById(BEVEL_GEAR_BUTTON)
if cmdDef:
cmdDef.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))