-
Notifications
You must be signed in to change notification settings - Fork 0
/
NESTER.py
78 lines (61 loc) · 2.42 KB
/
NESTER.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
import logging, os, sys, adsk
appPath = os.path.dirname(os.path.abspath(__file__))
if appPath not in sys.path:
sys.path.insert(0, appPath)
logLevel = logging.DEBUG
# logging.shutdown()
logger = logging.getLogger('Nester')
logger.setLevel(logLevel)
for handler in logger.handlers:
if isinstance(handler, logging.FileHandler):
handler.close()
logger.removeHandler(handler)
# formatter = logging.Formatter('%(asctime)s; %(module)s; %(levelname)s; %(lineno)d; %(funcName)s ; %(message)s')
formatter = logging.Formatter('%(levelname)s; %(module)s; %(funcName)s; %(lineno)d; %(message)s')
logHandler = logging.FileHandler(os.path.join(appPath, 'nester.log'), mode='a+')
logHandler.setFormatter(formatter)
logHandler.setLevel(logLevel)
logHandler.flush()
logger.addHandler(logHandler)
streamHandler = logging.StreamHandler()
streamHandler.setLevel(logLevel)
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)
from . import NesterCommand
from .common import nestFacesDict
app = adsk.core.Application.get()
nestFaces = nestFacesDict.setdefault(app.activeDocument.name, NesterCommand.NestFaces())
logger.info('------------------------------start------------------------------')
commandName1 = 'Nester'
commandDescription1 = 'Basic Nesting for Fusion 360'
commandResources1 = './resources'
cmdId1 = 'cmdID_Nester'
myWorkspace1 = 'FusionSolidEnvironment'
myToolbarTabID1 = 'Nest'
myToolbarPanelID1 = 'SolidScriptsAddinsPanel'
# exportCmdId = cmdId1 + '_export'
newCommand1 = NesterCommand.NesterCommand(commandName1,
commandDescription1,
commandResources1,
cmdId1,
myWorkspace1,
myToolbarPanelID1,
nestFaces)
def run(context):
app = adsk.core.Application.get()
ui = app.userInterface
commandDefinitions = ui.commandDefinitions
cmdDef = commandDefinitions.itemById(commandName1)
if cmdDef:
cmdDef.deleteMe()
adsk.autoTerminate(False)
newCommand1.onRun()
def stop(context):
# self.savedTab.activate()
for handler in logger.handlers:
if isinstance(handler, logging.FileHandler):
handler.flush()
handler.close()
logger.removeHandler(handler)
logging.info('-------------Restart')
newCommand1.onStop()