-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathSynthesis.py
138 lines (103 loc) · 3.34 KB
/
Synthesis.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
import os
import sys
from typing import Any
import adsk.core
# Required for absolute imports.
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from src.Dependencies import resolveDependencies
from src.Logging import logFailure, setupLogger
logger = setupLogger()
try:
# Attempt to import required pip dependencies to verify their installation.
import requests
from src.Proto import (
assembly_pb2,
joint_pb2,
material_pb2,
motor_pb2,
signal_pb2,
types_pb2,
)
except (ImportError, ModuleNotFoundError, BaseException) as error: # BaseException required to catch proto.VersionError
logger.warn(f"Running resolve dependencies with error of:\n{error}")
result = resolveDependencies()
if result:
adsk.core.Application.get().userInterface.messageBox("Installed required dependencies.\nPlease restart Fusion.")
from src import APP_NAME, DESCRIPTION, INTERNAL_ID, gm
from src.UI import (
HUI,
Camera,
ConfigCommand,
MarkingMenu,
ShowAPSAuthCommand,
ShowWebsiteCommand,
)
from src.UI.Toolbar import Toolbar
@logFailure
def run(_context: dict[str, Any]) -> None:
"""## Entry point to application from Fusion.
Arguments:
**context** *context* -- Fusion context to derive app and UI.
"""
# Remove all items prior to start just to make sure
unregister_all()
# creates the UI elements
register_ui()
app = adsk.core.Application.get()
ui = app.userInterface
MarkingMenu.setupMarkingMenu(ui)
@logFailure
def stop(_context: dict[str, Any]) -> None:
"""## Fusion exit point - deconstructs buttons and handlers
Arguments:
**context** *context* -- Fusion Data.
"""
unregister_all()
app = adsk.core.Application.get()
ui = app.userInterface
MarkingMenu.stopMarkingMenu(ui)
# nm.deleteMe()
logger.cleanupHandlers()
gm.clear()
@logFailure
def unregister_all() -> None:
"""Unregisters all UI elements in case any still exist.
- Good place to unregister custom app events that may repeat.
"""
Camera.clearIconCache()
for element in gm.elements:
element.deleteMe()
for tab in gm.tabs:
tab.deleteMe()
@logFailure
def register_ui() -> None:
"""#### Generic Function to add all UI objects in a simple non destructive way."""
# toolbar = Toolbar('SketchFab')
work_panel = Toolbar.getNewPanel(f"{APP_NAME}", f"{INTERNAL_ID}", "ToolsTab")
commandButton = HUI.HButton(
"Synthesis Exporter",
work_panel,
lambda *_: True, # TODO: Should be redone with various refactors.
ConfigCommand.ConfigureCommandCreatedHandler,
description=f"{DESCRIPTION}",
command=True,
)
gm.elements.append(commandButton)
apsButton = HUI.HButton(
"APS",
work_panel,
lambda *_: True, # TODO: Should be redone with various refactors.
ShowAPSAuthCommand.ShowAPSAuthCommandCreatedHandler,
description=f"Login to your Autodesk account",
command=True,
)
gm.elements.append(apsButton)
websiteButton = HUI.HButton(
"Synthesis Website",
work_panel,
lambda *_: True,
ShowWebsiteCommand.ShowWebsiteCommandCreatedHandler,
description=f"Open our tutorials page",
command=True,
)
gm.elements.append(websiteButton)