-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fusion360CommandBase.py
840 lines (676 loc) · 35.1 KB
/
Fusion360CommandBase.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
import adsk.core, adsk.fusion, traceback
import logging, os, sys
from .common import nestFacesDict, handlers
logger = logging.getLogger('Nester.F360CommandBase')
# logger.setLevel(logging.DEBUG)
handlers = []
# Removes the command control and definition
def cleanUpNavDropDownCommand(cmdId, DC_CmdId):
logger.info("cleanUpNavDropDownCommand")
objArrayNav = []
dropDownControl_ = commandControlById_in_NavBar(DC_CmdId)
commandControlNav_ = commandControlById_in_DropDown(cmdId, dropDownControl_)
if commandControlNav_:
objArrayNav.append(commandControlNav_)
commandDefinitionNav_ = commandDefinitionById(cmdId)
if commandDefinitionNav_:
objArrayNav.append(commandDefinitionNav_)
for obj in objArrayNav:
destroyObject(obj)
# Finds command definition in active UI
def commandDefinitionById(cmdId):
logger.info("commandDefinitionById")
app = adsk.core.Application.get()
ui = app.userInterface
if not cmdId:
logger.info('Command Definition: ' + cmdId + ' is not specified')
return None
commandDefinitions_ = ui.commandDefinitions
commandDefinition_ = commandDefinitions_.itemById(cmdId)
return commandDefinition_
def commandControlById_in_NavBar(cmdId):
logger.info("commandControlById_in_NavBar")
app = adsk.core.Application.get()
ui = app.userInterface
if not cmdId:
logger.info('Command Control: ' + cmdId + ' is not specified')
return None
toolbars_ = ui.toolbars
Nav_toolbar = toolbars_.itemById('NavToolbar')
Nav_toolbarControls = Nav_toolbar.controls
cmd_control = Nav_toolbarControls.itemById(cmdId)
if cmd_control is not None:
return cmd_control
# Get a commmand Control in a Nav Bar Drop Down
def commandControlById_in_DropDown(cmdId, dropDownControl):
cmd_control = dropDownControl.controls.itemById(cmdId)
if cmd_control is not None:
return cmd_control
# Destroys a given object
def destroyObject(tobeDeleteObj):
logger.info(f"destroyObject - {tobeDeleteObj.id} ")
app = adsk.core.Application.get()
ui = app.userInterface
if ui and tobeDeleteObj:
if tobeDeleteObj.isValid:
tobeDeleteObj.deleteMe()
else:
logger.info(tobeDeleteObj.id + 'is not a valid object')
# Returns the id of a Toolbar Panel in the given Workspace
def toolbarPanelById_in_Workspace(myWorkspaceID, myToolbarPanelID):
logger.info("toolbarPanelById_in_Workspace")
app = adsk.core.Application.get()
ui = app.userInterface
Allworkspaces = ui.workspaces
thisWorkspace = Allworkspaces.itemById(myWorkspaceID)
allToolbarPanels = thisWorkspace.toolbarPanels
ToolbarPanel_ = allToolbarPanels.itemById(myToolbarPanelID)
return ToolbarPanel_
# Returns the Command Control from the given panel
def commandControlById_in_Panel(cmdId, ToolbarPanel):
logger.info("commandControlById_in_Panel")
app = adsk.core.Application.get()
ui = app.userInterface
if not cmdId:
logger.info('Command Control: ' + cmdId + ' is not specified')
return None
cmd_control = ToolbarPanel.controls.itemById(cmdId)
if cmd_control is not None:
return cmd_control
# Base Class for creating Fusion 360 Commands
class Fusion360CommandBase:
def __init__(self, commandName, commandDescription, commandResources, cmdId, myWorkspace, myToolbarPanelID, nestFaces):
logger.info("Fusion360CommandBase.init")
self.commandName = commandName
self.commandDescription = commandDescription
self.commandResources = commandResources
self.cmdId = cmdId
self.myWorkspace = myWorkspace
self.myToolbarPanelID = myToolbarPanelID
self.DC_CmdId = 'Show Hidden'
self._nestFaces = nestFaces
# global set of event handlers to keep them referenced for the duration of the command
# self.handlers = []
try:
self.app = adsk.core.Application.get()
self.ui = self.app.userInterface
except:
logger.exception('Couldn\'t get app or ui: {}'.format(traceback.format_exc()))
def onPreview(self, command, inputs):
pass
def onDestroy(self, command, inputs, reason_):
pass
def onInputChanged(self, command, inputs, changedInput):
pass
def onExecute(self, command, inputs):
pass
def onCreate(self, command, inputs):
pass
def onRun(self):
# global handlers
logger.info("Fusion360CommandBase.onRun")
try:
app = adsk.core.Application.get()
ui = app.userInterface
allWorkspaces = ui.workspaces
commandDefinitions_ = ui.commandDefinitions
nestWorkspace = adsk.core.Workspace.cast(allWorkspaces.itemById(self.myWorkspace))
self.savedTab = [t for t in nestWorkspace.toolbarTabs if t.isActive][0]
toolbarTabs = nestWorkspace.toolbarTabs
startTabPanels = nestWorkspace.toolbarTabs.itemById('SolidTab').toolbarPanels
startPanel = startTabPanels.itemById(self.cmdId +'_startPanel')
if startPanel is None:
startPanel = startTabPanels.add(self.cmdId + '_startPanel', 'Nest')
self.toolbarTab_ = toolbarTabs.add(self.cmdId +'_Tab', 'Nest')
toolbarTabPanels = self.toolbarTab_.toolbarPanels
toolbarTabPanel = toolbarTabPanels.itemById(self.cmdId +'_TabPanel')
if toolbarTabPanel is None:
toolbarTabPanel = toolbarTabPanels.add(self.cmdId +'_TabPanel', 'Nester')
toolbarTabPanel.isVisible = True
self.toolbarTab_.isVisible = True
# self.toolbarTab_.activate()
toolbarPanel_ = toolbarPanelById_in_Workspace(self.myWorkspace, self.cmdId +'_Panel')
if toolbarPanel_ is None:
toolbarPanel_ = toolbarTabPanels.add(self.cmdId +'_Panel', 'Nester')
allToolbarPanelControls_ = toolbarPanel_.controls
toolbarPanelControl_ = allToolbarPanelControls_.itemById(self.cmdId)
if not toolbarPanelControl_:
commandDefinition_ = commandDefinitions_.itemById(self.cmdId)
if not commandDefinition_:
commandDefinition_ = commandDefinitions_.addButtonDefinition(self.cmdId,
self.commandName,
self.commandDescription,
self.commandResources + '/nesterWorkspace')
onCommandCreatedHandler_ = CommandCreatedEventHandler(self)
commandDefinition_.commandCreated.add(onCommandCreatedHandler_)
handlers.append(onCommandCreatedHandler_)
toolbarPanelControl_ = allToolbarPanelControls_.addCommand(commandDefinition_)
toolbarPanelControl_.isVisible = True
toolbarPanelControl_.isPromoted = True
exportCommandDefinition_ = commandDefinitions_.itemById(self.cmdId+'_export')
if not exportCommandDefinition_:
exportCommandDefinition_ = commandDefinitions_.addButtonDefinition(self.cmdId+'_export',
self.commandName+'_export',
'export>dxf',
self.commandResources+'/export')
onExportCreatedHandler_ = ExportCreatedEventHandler(self)
exportCommandDefinition_.commandCreated.add(onExportCreatedHandler_)
handlers.append(onExportCreatedHandler_)
toolbarPanelControl_ = allToolbarPanelControls_.addCommand(exportCommandDefinition_)
toolbarPanelControl_.isPromoted = True
importCommandDefinition_ = commandDefinitions_.itemById(self.cmdId+'_import')
if not importCommandDefinition_:
importCommandDefinition_ = commandDefinitions_.addButtonDefinition(self.cmdId+'_import',
self.commandName+'_import',
'dxf>import',
self.commandResources+'/import')
onImportCreatedHandler_ = ImportCreatedEventHandler(self)
importCommandDefinition_.commandCreated.add(onImportCreatedHandler_)
handlers.append(onImportCreatedHandler_)
onDocumentOpenedHandler_ = DocumentOpenedHandler(self)
app.documentOpened.add(onDocumentOpenedHandler_)
handlers.append(onDocumentOpenedHandler_)
onDocumentSavingHandler_ = DocumentSavingHandler(self)
app.documentSaving.add(onDocumentSavingHandler_)
handlers.append(onDocumentSavingHandler_)
onDocumentSavedHandler_ = DocumentSavedHandler(self)
app.documentSaved.add(onDocumentSavedHandler_)
handlers.append(onDocumentSavedHandler_)
onDocumentCreatedHandler_ = DocumentCreatedHandler(self)
app.documentCreated.add(onDocumentCreatedHandler_)
handlers.append(onDocumentCreatedHandler_)
onDocumentActivatedHandler_ = DocumentActivatedHandler(self)
app.documentActivated.add(onDocumentActivatedHandler_)
handlers.append(onDocumentActivatedHandler_)
onDocumentDeactivatedHandler_ = DocumentDeactivatedHandler(self)
app.documentDeactivated.add(onDocumentDeactivatedHandler_)
handlers.append(onDocumentDeactivatedHandler_)
toolbarPanelControl_ = allToolbarPanelControls_.addCommand(importCommandDefinition_)
toolbarPanelControl_.isPromoted = True
finishTabPanel = toolbarTabPanels.itemById(self.cmdId +'_FinishTabPanel')
if finishTabPanel is None:
finishTabPanel = toolbarTabPanels.add(self.cmdId +'_FinishTabPanel', 'Finish Nester')
finishTabPanel.isVisible = True
finishTabPanelControls_ = finishTabPanel.controls
finishPanelControl_ = finishTabPanelControls_.itemById(self.cmdId + '_finish')
if not finishPanelControl_:
finishCommandDefinition_ = commandDefinitions_.itemById(self.cmdId + '_finish')
if not finishCommandDefinition_:
finishCommandDefinition_ = commandDefinitions_.addButtonDefinition(self.cmdId+'_finish',
self.commandName+'_finish',
'Finish Nester',
self.commandResources+'/finishOutcomeView')
onFinishCreatedHandler_ = FinishCreatedEventHandler(self)
finishCommandDefinition_.commandCreated.add(onFinishCreatedHandler_)
handlers.append(onFinishCreatedHandler_)
finishPanelControl_ = finishTabPanelControls_.addCommand(finishCommandDefinition_)
finishPanelControl_.isPromoted = True
finishTabPanel.isVisible = True
startPanelControls_ = startPanel.controls
startPanelControl_ = startPanelControls_.itemById(self.cmdId + '_start')
if not startPanelControl_:
startCommandDefinition_ = commandDefinitions_.itemById(self.cmdId + '_start')
if not startCommandDefinition_:
startCommandDefinition_ = commandDefinitions_.addButtonDefinition(self.cmdId+'_start',
self.commandName+'_start',
'Start Nester',
self.commandResources+'/start')
onStartCreatedHandler_ = StartCreatedEventHandler(self)
startCommandDefinition_.commandCreated.add(onStartCreatedHandler_)
handlers.append(onStartCreatedHandler_)
StartPanelControl_ = startPanelControls_.addCommand(startCommandDefinition_)
StartPanelControl_.isPromoted = True
except:
logger.exception('AddIn Start Failed:' )
def onStop(self):
logger.info("Fusion360CommandBase.onStop")
try:
app = adsk.core.Application.get()
ui = app.userInterface
toolbarPanel_ = toolbarPanelById_in_Workspace(self.myWorkspace, self.cmdId +'_Panel') #self.myToolbarPanelID)
finishPanel_ = toolbarPanelById_in_Workspace(self.myWorkspace, self.cmdId +'_FinishTabPanel') #self.myToolbarPanelID)
startPanel_ = toolbarPanelById_in_Workspace(self.myWorkspace, self.cmdId +'_startPanel') #self.myToolbarPanelID)
commandControlPanel_ = commandControlById_in_Panel(self.cmdId, toolbarPanel_)
CommandDefinition_ = commandDefinitionById(self.cmdId)
exportCommandControlPanel_ = commandControlById_in_Panel(self.cmdId+'_export', toolbarPanel_)
exportCommandDefinition_ = commandDefinitionById(self.cmdId+'_export')
importCommandControlPanel_ = commandControlById_in_Panel(self.cmdId+'_import', toolbarPanel_)
importCommandDefinition_ = commandDefinitionById(self.cmdId+'_import')
finishCommandControlPanel_ = commandControlById_in_Panel(self.cmdId+'_finish', finishPanel_)
finishCommandDefinition_ = commandDefinitionById(self.cmdId+'_finish')
startCommandControlPanel_ = commandControlById_in_Panel(self.cmdId+'_start', startPanel_)
startCommandDefinition_ = commandDefinitionById(self.cmdId+'_start')
destroyObject(commandControlPanel_)
destroyObject(CommandDefinition_)
destroyObject(exportCommandControlPanel_)
destroyObject(exportCommandDefinition_)
destroyObject(importCommandControlPanel_)
destroyObject(importCommandDefinition_)
destroyObject(finishCommandControlPanel_)
destroyObject(finishCommandDefinition_)
destroyObject(startCommandControlPanel_)
destroyObject(startCommandDefinition_)
destroyObject
handlers.clear()
except:
logger.exception('AddIn Stop Failed: {}'.format(traceback.format_exc()))
# Intended to create commands in a drop down menu in the nav bar
class Fusion360NavCommandBase:
def __init__(self, commandName, commandDescription, commandResources, cmdId, DC_CmdId, DC_Resources, info):
logger.info('Fusion360NavCommandBase.__init__')
self.commandName = commandName
self.commandDescription = commandDescription
self.commandResources = commandResources
self.cmdId = cmdId
self.info = info
self.DC_CmdId = DC_CmdId
self.DC_Resources = DC_Resources
# global set of event handlers to keep them referenced for the duration of the command
# self.handlers = []
try:
self.app = adsk.core.Application.get()
self.ui = self.app.userInterface
except:
logger.exception('Couldn\'t get app or ui: {}'.format(traceback.format_exc()))
def onPreview(self, command, inputs):
logger.info('')
pass
def onDestroy(self, command, inputs, reason_):
logger.info('')
pass
def onInputChanged(self, command, inputs, changedInput):
logger.info('')
pass
def onExecute(self, command, inputs):
logger.info('')
pass
def onCreate(self, command, inputs):
logger.info('')
pass
def onRun(self):
# global handlers
logger.info('')
try:
app = adsk.core.Application.get()
ui = app.userInterface
commandDefinitions_ = ui.commandDefinitions
toolbars_ = ui.toolbars
navBar = toolbars_.itemById('NavToolbar')
toolbarControlsNAV = navBar.controls
dropControl = toolbarControlsNAV.itemById(self.DC_CmdId)
if not dropControl:
dropControl = toolbarControlsNAV.addDropDown(self.DC_CmdId, self.DC_Resources, self.DC_CmdId)
NAV_Control = toolbarControlsNAV.itemById(self.cmdId)
if not NAV_Control:
commandDefinition_ = commandDefinitions_.itemById(self.cmdId)
if not commandDefinition_:
# commandDefinitionNAV = cmdDefs.addSplitButton(showAllBodiesCmdId, otherCmdDefs, True)
commandDefinition_ = commandDefinitions_.addButtonDefinition(self.cmdId, self.commandName, self.commandDescription, self.commandResources)
onCommandCreatedHandler_ = CommandCreatedEventHandler(self)
commandDefinition_.commandCreated.add(onCommandCreatedHandler_)
handlers.append(onCommandCreatedHandler_)
NAV_Control = dropControl.controls.addCommand(commandDefinition_)
NAV_Control.isVisible = True
except:
logger.exception('AddIn Start Failed: {}'.format(traceback.format_exc()))
def onStop(self):
logger.info('')
ui = None
try:
dropDownControl_ = commandControlById_in_NavBar(self.DC_CmdId)
commandControlNav_ = commandControlById_in_DropDown(self.cmdId, dropDownControl_)
commandDefinitionNav_ = commandDefinitionById(self.cmdId)
destroyObject(commandControlNav_)
destroyObject(commandDefinitionNav_)
if dropDownControl_.controls.count == 0:
commandDefinition_DropDown = commandDefinitionById(self.DC_CmdId)
destroyObject(dropDownControl_)
destroyObject(commandDefinition_DropDown)
except:
logger.exception('AddIn Stop Failed: {}'.format(traceback.format_exc()))
class ExecutePreviewHandler(adsk.core.CommandEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("ExecutePreviewHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("ExecutePreviewHandler.notify")
try:
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
logger.info('Preview: {} execute preview event triggered'.format(command_.parentCommandDefinition.id))
self.myObject_.onPreview(command_, inputs_, args)
except:
logger.exception('Execute preview event failed: {}'.format(traceback.format_exc()))
class DestroyHandler(adsk.core.CommandEventHandler):
def __init__(self, myObject):
logger.info("DestroyHandler")
super().__init__()
self.myObject_ = myObject
def notify(self, args):
logger.info("DestroyHandler")
# Code to react to the event.
try:
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
reason_ = args.terminationReason
# Check the command exists or not
# adsk.terminate()
logger.info(f'Command: {command_.parentCommandDefinition.id} destroyed')
reasons = {0:"Unknown", 1:"OK", 2:"Cancelled", 3:"Aborted", 4:"PreEmpted Termination", 5:"Document closed"}
logger.info("Reason for termination = " + reasons[reason_])
self.myObject_.onDestroy(command_, inputs_, reason_)
except:
logger.exception('Input changed event failed: {}'.format(traceback.format_exc()))
class InputChangedHandler(adsk.core.InputChangedEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("InputChangedHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("InputChangedHandler")
try:
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
changedInput_ = args.input
logger.info('Input: {} changed event triggered'.format(command_.parentCommandDefinition.id))
logger.info('The Input: {} was the command'.format(changedInput_.id))
self.myObject_.onInputChanged(command_, inputs_, changedInput_)
except:
logger.exception('Input changed event failed: {}'.format(traceback.format_exc()))
class CommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("CommandExecuteHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("CommandExecuteHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
# adsk.terminate()
logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onExecute(command_, inputs_)
# adsk.autoTerminate(False)
except:
logger.exception('command executed failed: {}'.format(traceback.format_exc()))
class StartExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("StartExecuteHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("StartExecuteHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
# adsk.terminate()
logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onStartExecute(command_, inputs_)
# adsk.autoTerminate(False)
except:
logger.exception('command executed failed: {}'.format(traceback.format_exc()))
class ExportCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("ExportCommandExecuteHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("ExportCommandExecuteHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
logger.info(f'command: {command_.parentCommandDefinition.id} executed successfully')
self.myObject_.onExportExecute(command_, inputs_)
# adsk.autoTerminate(False)
except:
logger.exception('command executed failed: {}'.format(traceback.format_exc()))
class ImportCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("ImportCommandExecuteHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("ImportCommandExecuteHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
logger.info(f'command: {command_.parentCommandDefinition.id} executed successfully')
self.myObject_.onImportExecute(command_, inputs_)
# adsk.autoTerminate(False)
except:
logger.exception('command executed failed: {}'.format(traceback.format_exc()))
class MouseClickHandler(adsk.core.MouseEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("MouseClickHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("MouseClickHandler")
try:
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.firingEvent.sender
inputs_ = command_.commandInputs
kbModifiers = args.keyboardModifiers
logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onMouseClick(kbModifiers, command_, inputs_)
except:
logger.exception('command mouseClick failed: {}'.format(traceback.format_exc()))
class DocumentOpenedHandler(adsk.core.DocumentEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("DocumentOpenedHandler - init")
self.myObject_ = myObject
def notify(self, args):
logger.info("DocumentOpenedEvent")
try:
command_ = args.firingEvent.sender
# logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onDocumentOpened(command_, args)
except:
logger.exception('command document Opened failed: {}'.format(traceback.format_exc()))
class DocumentSavingHandler(adsk.core.DocumentEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("DocumentSavingHandler - init")
self.myObject_ = myObject
def notify(self, args):
logger.info("DocumentSavingEvent")
try:
command_ = args.firingEvent.sender
# logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onDocumentSaving(command_, args)
except:
logger.exception('command document saved failed: {}'.format(traceback.format_exc()))
class DocumentCreatedHandler(adsk.core.DocumentEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("DocumentCreatedHandler - init")
self.myObject_ = myObject
def notify(self, args):
logger.info("DocumentCreatedEvent")
try:
command_ = args.firingEvent.sender
# logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onDocumentCreated(command_, args)
except:
logger.exception('command document saved failed: {}'.format(traceback.format_exc()))
class DocumentSavedHandler(adsk.core.DocumentEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("DocumentSavedHandler - init")
self.myObject_ = myObject
def notify(self, args):
logger.info("DocumentSavedEvent")
try:
command_ = args.firingEvent.sender
# logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onDocumentSaved(command_, args)
except:
logger.exception('command document saved failed: {}'.format(traceback.format_exc()))
class DocumentActivatedHandler(adsk.core.DocumentEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("DocumentActivatedHandler - init")
self.myObject_ = myObject
def notify(self, args):
logger.info("DocumentActivatedEvent")
try:
command_ = args.firingEvent.sender
# logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onDocumentActivated(command_, args)
except:
logger.exception('command document activated failed: {}'.format(traceback.format_exc()))
class DocumentDeactivatedHandler(adsk.core.DocumentEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("DocumentDeactivatedHandler - init")
self.myObject_ = myObject
def notify(self, args):
logger.info("DocumentDectivatedEvent")
try:
command_ = args.firingEvent.sender
# logger.info('command: {} executed successfully'.format(command_.parentCommandDefinition.id))
self.myObject_.onDocumentDeactivated(command_, args)
except:
logger.exception('command document deactivated failed: {}'.format(traceback.format_exc()))
class CommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("CommandCreatedEventHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("CommandCreatedEvent")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.command
inputs_ = command_.commandInputs
onExecuteHandler_ = CommandExecuteHandler(self.myObject_)
command_.execute.add(onExecuteHandler_)
handlers.append(onExecuteHandler_)
onInputChangedHandler_ = InputChangedHandler(self.myObject_)
command_.inputChanged.add(onInputChangedHandler_)
handlers.append(onInputChangedHandler_)
onDestroyHandler_ = DestroyHandler(self.myObject_)
command_.destroy.add(onDestroyHandler_)
handlers.append(onDestroyHandler_)
onExecutePreviewHandler_ = ExecutePreviewHandler(self.myObject_)
command_.executePreview.add(onExecutePreviewHandler_)
handlers.append(onExecutePreviewHandler_)
onMouseClickHandler_ = MouseClickHandler(self.myObject_)
command_.mouseClick.add(onMouseClickHandler_)
handlers.append(onMouseClickHandler_)
logger.info('Panel command created successfully')
self.myObject_.onCreate(command_, inputs_)
except:
logger.exception('Panel command created failed: {}'.format(traceback.format_exc()))
class ExportCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("ExportCreatedEventHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("ExportCreatedEventHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.command
inputs_ = command_.commandInputs
onExecuteHandler_ = ExportCommandExecuteHandler(self.myObject_)
command_.execute.add(onExecuteHandler_)
handlers.append(onExecuteHandler_)
onDestroyHandler_ = DestroyHandler(self.myObject_)
command_.destroy.add(onDestroyHandler_)
handlers.append(onDestroyHandler_)
logger.info('Panel command created successfully')
self.myObject_.onExportCreate(command_, inputs_)
except:
logger.exception('Panel command created failed: {}'.format(traceback.format_exc()))
class ImportCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("ImportCreatedEventHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("ImportCreatedEventHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.command
inputs_ = command_.commandInputs
onExecuteHandler_ = ImportCommandExecuteHandler(self.myObject_)
command_.execute.add(onExecuteHandler_)
handlers.append(onExecuteHandler_)
onDestroyHandler_ = DestroyHandler(self.myObject_)
command_.destroy.add(onDestroyHandler_)
handlers.append(onDestroyHandler_)
logger.info('Panel command created successfully')
self.myObject_.onExportCreate(command_, inputs_)
except:
logger.exception('Panel command created failed: {}'.format(traceback.format_exc()))
class FinishCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("FinishCreatedEventHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("FinishCreatedEventHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.command
inputs_ = command_.commandInputs
onDestroyHandler_ = DestroyHandler(self.myObject_)
command_.destroy.add(onDestroyHandler_)
handlers.append(onDestroyHandler_)
logger.info('Finish Panel command created successfully')
self.myObject_.onFinishCreate(command_, inputs_)
except:
logger.exception('Finish Panel command created failed: {}'.format(traceback.format_exc()))
class StartCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self, myObject):
super().__init__()
logger.info("StartCreatedEventHandler")
self.myObject_ = myObject
def notify(self, args):
logger.info("StartCreatedEventHandler")
try:
# global handlers
app = adsk.core.Application.get()
ui = app.userInterface
command_ = args.command
inputs_ = command_.commandInputs
onStartExecuteHandler_ = StartExecuteHandler(self.myObject_)
command_.execute.add(onStartExecuteHandler_)
handlers.append(onStartExecuteHandler_)
onDestroyHandler_ = DestroyHandler(self.myObject_)
command_.destroy.add(onDestroyHandler_)
handlers.append(onDestroyHandler_)
logger.info('Finish Panel command created successfully')
self.myObject_.onStartCreate(command_, inputs_)
except:
logger.exception('Finish Panel command created failed: {}'.format(traceback.format_exc()))