-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFusion101.py
More file actions
129 lines (102 loc) · 4.8 KB
/
Fusion101.py
File metadata and controls
129 lines (102 loc) · 4.8 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Author-Julia & Sören
# Description-Fusion101 provides you a gentle introduction into the basics of Fusion360 by providing step-by-step tutorials to multiple topics.
import adsk.core
import adsk.fusion
import adsk.cam
import traceback
from .PopUpCommandHandler import PopUpCommandCreatedEventHandler
from .TutorialButtonHandler import CommandCreatedEventHandlerQATRight
from .ShowPalletEventHandler import ShowPaletteCommandCreatedHandler
from .constants import PALLET_ID
# global set of event handlers to keep them referenced for the duration of the command
handlers = []
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)
num = 0
isDontShowAgain = False
extrudeCount = 0
def run(context):
try:
global _ui, _app
_app = adsk.core.Application.get()
_ui = _app.userInterface
# Add a command that displays the panel.
showPaletteCmdDef = _ui.commandDefinitions.itemById('showPalette')
if not showPaletteCmdDef:
showPaletteCmdDef = _ui.commandDefinitions.addButtonDefinition('showPalette', 'Show Fusion 101',
'Show the custom palette', '')
# Connect to Command Created event.
onCommandCreated = ShowPaletteCommandCreatedHandler(handlers)
showPaletteCmdDef.commandCreated.add(onCommandCreated)
handlers.append(onCommandCreated)
# AddInSAMPLE
cmdDef = _ui.commandDefinitions
# add a button command on Quick Access Toolbar
if not _ui.toolbars.itemById('QATRight').controls.itemById('TutorialButtonOnQATRight'):
btnCmdDefinitionQATRight_ = cmdDef.itemById('TutorialButtonOnQATRight')
if not btnCmdDefinitionQATRight_:
btnCmdDefinitionQATRight_ = cmdDef.addButtonDefinition('TutorialButtonOnQATRight', 'Tutorial Command',
'Tutorial Command', './resources')
onButtonCommandCreated = CommandCreatedEventHandlerQATRight(handlers)
btnCmdDefinitionQATRight_.commandCreated.add(onButtonCommandCreated)
# keep the handler referenced beyond this function
handlers.append(onButtonCommandCreated)
# Connect to Command Created event.
handlers.append(onCommandCreated)
_ui.toolbars.itemById('QATRight').controls.addCommand(btnCmdDefinitionQATRight_).isVisible = True
# Create the popUpButton command definition
popUpButton = cmdDef.addButtonDefinition(
'popUpButton01PYTHON',
'Tutorial PopUp',
'Imaginary tutorial PopUp Button that is not visible anywhere in the UI',
''
)
# Connect to the command created event
popUpCommandCreated = PopUpCommandCreatedEventHandler(handlers)
popUpButton.commandCreated.add(popUpCommandCreated)
handlers.append(popUpCommandCreated)
cmd = cmdDef.itemById('popUpButton01PYTHON')
cmd.execute()
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
############addinsample######
objArrayQATRight = []
if _ui.toolbars.itemById('QATRight').controls.itemById('TutorialButtonOnQATRight'):
objArrayQATRight.append(_ui.toolbars.itemById('QATRight').controls.itemById('TutorialButtonOnQATRight'))
btnCmdDefinitionQATRight_ = _ui.commandDefinitions.itemById('TutorialButtonOnQATRight')
if btnCmdDefinitionQATRight_:
objArrayQATRight.append(btnCmdDefinitionQATRight_)
for obj in objArrayQATRight:
if _ui and obj:
if obj.isValid:
obj.deleteMe()
else:
_ui.messageBox('obj is not a valid object')
#############addinsample######
# Delete the palette created by this add-in.
palette = _ui.palettes.itemById(PALLET_ID)
if palette:
palette.deleteMe()
# Delete controls and associated command definitions created by this add-ins
panel = _ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cmd = panel.controls.itemById('showPalette')
if cmd:
cmd.deleteMe()
cmdDef = _ui.commandDefinitions.itemById('showPalette')
if cmdDef:
cmdDef.deleteMe()
cmd = panel.controls.itemById('sendInfoToHTML')
if cmd:
cmd.deleteMe()
cmdDef = _ui.commandDefinitions.itemById('sendInfoToHTML')
if cmdDef:
cmdDef.deleteMe()
popUp = _ui.commandDefinitions.itemById('popUpButton01PYTHON')
if popUp:
popUp.deleteMe()
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))