-
Notifications
You must be signed in to change notification settings - Fork 0
/
knurls.py
57 lines (47 loc) · 1.81 KB
/
knurls.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
# -*- coding: utf-8 -*-
#Author-Lukas Koch
#Description-Add knurls to flat surfaces.
import adsk.core, adsk.fusion, adsk.cam, traceback
from .flat_knurl import add_to_button as flat_knurl_button
debug = False
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
if debug:
ui.messageBox('Run addin')
# Get the CommandDefinitions collection.
cmd_defs = ui.commandDefinitions
# Create a button command definition.
button = cmd_defs.addButtonDefinition('KnurlButtonId',
'Knurl button',
'Knurl button tooltip',
'./resources/command')
# Connect to the command.
flat_knurl_button(button)
# Get the ADD-INS panel in the model workspace.
addins_panel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
# Add the button to the bottom of the panel.
addins_panel.controls.addCommand(button)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
if debug:
ui.messageBox('Stop addin')
# Clean up the UI.
cmd_def = ui.commandDefinitions.itemById('KnurlButtonId')
if cmd_def:
cmd_def.deleteMe()
addins_panel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cntrl = addins_panel.controls.itemById('KnurlButtonId')
if cntrl:
cntrl.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))