diff --git a/exporter/SynthesisFusionAddin/Synthesis.py b/exporter/SynthesisFusionAddin/Synthesis.py index 20f3fb35d6..deba3c9551 100644 --- a/exporter/SynthesisFusionAddin/Synthesis.py +++ b/exporter/SynthesisFusionAddin/Synthesis.py @@ -3,35 +3,45 @@ import adsk.core -# Currently required for `resolveDependencies()`, will be required for absolute imports. +# Required for absolute imports. sys.path.append(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "proto", "proto_out"))) -from .src.Dependencies import resolveDependencies # isort:skip +from src.Dependencies import resolveDependencies +from src.Logging import logFailure, setupLogger -# Transition: AARD-1741 -# Import order should be removed in AARD-1737 and `setupLogger()` moved to `__init__.py` -from .src.Logging import getLogger, logFailure, setupLogger # isort:skip - -setupLogger() +logger = setupLogger() try: - from .src.general_imports import APP_NAME, DESCRIPTION, INTERNAL_ID, gm - from .src.UI import ( - HUI, - Camera, - ConfigCommand, - MarkingMenu, - ShowAPSAuthCommand, - ShowWebsiteCommand, + # Attempt to import required pip dependencies to verify their installation. + import requests + from proto.proto_out import ( + assembly_pb2, + joint_pb2, + material_pb2, + motor_pb2, + signal_pb2, + types_pb2, ) - from .src.UI.Toolbar import Toolbar -except (ImportError, ModuleNotFoundError) as error: - getLogger().warn(f"Running resolve dependencies with error of:\n{error}") +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(_): """## Entry point to application from Fusion. @@ -68,28 +78,8 @@ def stop(_): # nm.deleteMe() - logger = getLogger(INTERNAL_ID) logger.cleanupHandlers() - - for file in gm.files: - try: - os.remove(file) - except OSError: - pass - - # removes path so that proto files don't get confused - - import sys - - path = os.path.abspath(os.path.dirname(__file__)) - - path_proto_files = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "proto", "proto_out")) - - if path in sys.path: - sys.path.remove(path) - - if path_proto_files in sys.path: - sys.path.remove(path_proto_files) + gm.clear() @logFailure diff --git a/exporter/SynthesisFusionAddin/src/APS/APS.py b/exporter/SynthesisFusionAddin/src/APS/APS.py index a65728ec23..a6f4f34a5b 100644 --- a/exporter/SynthesisFusionAddin/src/APS/APS.py +++ b/exporter/SynthesisFusionAddin/src/APS/APS.py @@ -10,13 +10,13 @@ import requests -from ..general_imports import INTERNAL_ID, gm, my_addin_path -from ..Logging import getLogger +from src import ADDIN_PATH, gm +from src.Logging import getLogger logger = getLogger() CLIENT_ID = "GCxaewcLjsYlK8ud7Ka9AKf9dPwMR3e4GlybyfhAK2zvl3tU" -auth_path = os.path.abspath(os.path.join(my_addin_path, "..", ".aps_auth")) +auth_path = os.path.abspath(os.path.join(ADDIN_PATH, "..", ".aps_auth")) APS_AUTH = None APS_USER_INFO = None diff --git a/exporter/SynthesisFusionAddin/src/Dependencies.py b/exporter/SynthesisFusionAddin/src/Dependencies.py index b9ad31f7be..c6c1b26b4c 100644 --- a/exporter/SynthesisFusionAddin/src/Dependencies.py +++ b/exporter/SynthesisFusionAddin/src/Dependencies.py @@ -1,7 +1,6 @@ import importlib.machinery import importlib.util import os -import platform import subprocess import sys from pathlib import Path @@ -9,10 +8,10 @@ import adsk.core import adsk.fusion -from .Logging import getLogger, logFailure +from src import SYSTEM +from src.Logging import getLogger, logFailure logger = getLogger() -system = platform.system() # Since the Fusion python runtime is separate from the system python runtime we need to do some funky things # in order to download and install python packages separate from the standard library. @@ -29,13 +28,11 @@ def getInternalFusionPythonInstillationFolder() -> str: pythonStandardLibraryModulePath = importlib.machinery.PathFinder.find_spec("os", sys.path).origin # Depending on platform, adjust to folder to where the python executable binaries are stored. - if system == "Windows": + if SYSTEM == "Windows": folder = f"{Path(pythonStandardLibraryModulePath).parents[1]}" - elif system == "Darwin": - folder = f"{Path(pythonStandardLibraryModulePath).parents[2]}/bin" else: - # TODO: System string should be moved to __init__ after GH-1013 - raise RuntimeError("Unsupported platform.") + assert SYSTEM == "Darwin" + folder = f"{Path(pythonStandardLibraryModulePath).parents[2]}/bin" return folder @@ -100,7 +97,7 @@ def resolveDependencies() -> bool | None: adsk.doEvents() pythonFolder = getInternalFusionPythonInstillationFolder() - pythonExecutableFile = "python.exe" if system == "Windows" else "python" # Confirming 110% everything is fine. + pythonExecutableFile = "python.exe" if SYSTEM == "Windows" else "python" # Confirming 110% everything is fine. pythonExecutablePath = os.path.join(pythonFolder, pythonExecutableFile) progressBar = ui.createProgressDialog() @@ -109,7 +106,7 @@ def resolveDependencies() -> bool | None: progressBar.show("Synthesis", f"Installing dependencies...", 0, len(PIP_DEPENDENCY_VERSION_MAP) * 2 + 2, 0) # Install pip manually on macos as it is not included by default? Really? - if system == "Darwin" and not os.path.exists(os.path.join(pythonFolder, "pip")): + if SYSTEM == "Darwin" and not os.path.exists(os.path.join(pythonFolder, "pip")): pipInstallScriptPath = os.path.join(pythonFolder, "get-pip.py") if not os.path.exists(pipInstallScriptPath): executeCommand("curl", "https://bootstrap.pypa.io/get-pip.py", "-o", pipInstallScriptPath) diff --git a/exporter/SynthesisFusionAddin/src/GlobalManager.py b/exporter/SynthesisFusionAddin/src/GlobalManager.py index a31688d119..6841a58750 100644 --- a/exporter/SynthesisFusionAddin/src/GlobalManager.py +++ b/exporter/SynthesisFusionAddin/src/GlobalManager.py @@ -1,13 +1,8 @@ """ Initializes the global variables that are set in the run method to reduce hanging commands. """ -import logging - import adsk.core import adsk.fusion -from .general_imports import * -from .strings import * - class GlobalManager(object): """Global Manager instance""" @@ -47,6 +42,11 @@ def __init__(self): def __str__(self): return "GlobalManager" + def clear(self): + for attr, value in self.__dict__.items(): + if isinstance(value, list): + setattr(self, attr, []) + instance = None def __new__(cls): diff --git a/exporter/SynthesisFusionAddin/src/Logging.py b/exporter/SynthesisFusionAddin/src/Logging.py index 2bf9ce191b..e5f352f480 100644 --- a/exporter/SynthesisFusionAddin/src/Logging.py +++ b/exporter/SynthesisFusionAddin/src/Logging.py @@ -11,8 +11,8 @@ import adsk.core -from .strings import INTERNAL_ID -from .UI.OsHelper import getOSPath +from src import INTERNAL_ID +from src.UI.OsHelper import getOSPath MAX_LOG_FILES_TO_KEEP = 10 TIMING_LEVEL = 25 @@ -27,7 +27,7 @@ def cleanupHandlers(self) -> None: handler.close() -def setupLogger() -> None: +def setupLogger() -> SynthesisLogger: now = datetime.now().strftime("%H-%M-%S") today = date.today() logFileFolder = getOSPath(f"{pathlib.Path(__file__).parent.parent}", "logs") @@ -46,6 +46,7 @@ def setupLogger() -> None: logger = getLogger(INTERNAL_ID) logger.setLevel(10) # Debug logger.addHandler(logHandler) + return cast(SynthesisLogger, logger) def getLogger(name: str | None = None) -> SynthesisLogger: diff --git a/exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py b/exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py index 9151a7115d..69e9bbef5d 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py +++ b/exporter/SynthesisFusionAddin/src/Parser/ExporterOptions.py @@ -11,9 +11,9 @@ import adsk.core from adsk.fusion import CalculationAccuracy, TriangleMeshQualityOptions -from ..Logging import logFailure, timed -from ..strings import INTERNAL_ID -from ..Types import ( +from src import INTERNAL_ID +from src.Logging import logFailure, timed +from src.Types import ( KG, ExportLocation, ExportMode, diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py index 9556eec6e3..aea709f04a 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Components.py @@ -1,19 +1,18 @@ # Contains all of the logic for mapping the Components / Occurrences -import logging -import traceback -import uuid -from typing import * - import adsk.core import adsk.fusion from proto.proto_out import assembly_pb2, joint_pb2, material_pb2, types_pb2 -from ...Logging import logFailure, timed -from ...Types import ExportMode -from ..ExporterOptions import ExporterOptions -from . import PhysicalProperties -from .PDMessage import PDMessage -from .Utilities import * +from src.Logging import logFailure +from src.Parser.ExporterOptions import ExporterOptions +from src.Parser.SynthesisParser import PhysicalProperties +from src.Parser.SynthesisParser.PDMessage import PDMessage +from src.Parser.SynthesisParser.Utilities import ( + fill_info, + guid_component, + guid_occurrence, +) +from src.Types import ExportMode # TODO: Impelement Material overrides diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/JointHierarchy.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/JointHierarchy.py index c5707ee63c..cf8c5e04b0 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/JointHierarchy.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/JointHierarchy.py @@ -1,17 +1,15 @@ import enum -import logging -import traceback -from typing import * +from typing import Union import adsk.core import adsk.fusion from proto.proto_out import joint_pb2, types_pb2 -from ...general_imports import * -from ...Logging import getLogger, logFailure -from ..ExporterOptions import ExporterOptions -from .PDMessage import PDMessage -from .Utilities import guid_component, guid_occurrence +from src import gm +from src.Logging import getLogger, logFailure +from src.Parser.ExporterOptions import ExporterOptions +from src.Parser.SynthesisParser.PDMessage import PDMessage +from src.Parser.SynthesisParser.Utilities import guid_component, guid_occurrence logger = getLogger() diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Joints.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Joints.py index 981b73fc73..6b1650b3f9 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Joints.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Joints.py @@ -28,14 +28,17 @@ import adsk.core import adsk.fusion -from proto.proto_out import assembly_pb2, joint_pb2, motor_pb2, signal_pb2, types_pb2 - -from ...general_imports import * -from ...Logging import getLogger -from ...Types import JointParentType, SignalType -from ..ExporterOptions import ExporterOptions -from .PDMessage import PDMessage -from .Utilities import construct_info, fill_info, guid_occurrence +from proto.proto_out import assembly_pb2, joint_pb2, signal_pb2, types_pb2 + +from src.Logging import getLogger +from src.Parser.ExporterOptions import ExporterOptions +from src.Parser.SynthesisParser.PDMessage import PDMessage +from src.Parser.SynthesisParser.Utilities import ( + construct_info, + fill_info, + guid_occurrence, +) +from src.Types import JointParentType, SignalType logger = getLogger() diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Materials.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Materials.py index f1dc1e3b38..a077c764b7 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Materials.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Materials.py @@ -1,17 +1,10 @@ -# Should contain Physical and Apperance materials ? -import json -import logging -import math -import traceback - import adsk from proto.proto_out import material_pb2 -from ...general_imports import * -from ...Logging import logFailure, timed -from ..ExporterOptions import ExporterOptions -from .PDMessage import PDMessage -from .Utilities import * +from src.Logging import logFailure +from src.Parser.ExporterOptions import ExporterOptions +from src.Parser.SynthesisParser.PDMessage import PDMessage +from src.Parser.SynthesisParser.Utilities import construct_info, fill_info OPACITY_RAMPING_CONSTANT = 14.0 diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py index 6db886f7b5..338f5a300a 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py @@ -6,14 +6,20 @@ from google.protobuf.json_format import MessageToJson from proto.proto_out import assembly_pb2, types_pb2 -from ...APS.APS import getAuth, upload_mirabuf -from ...general_imports import * -from ...Logging import getLogger, logFailure, timed -from ...Types import ExportLocation, ExportMode -from ...UI.Camera import captureThumbnail, clearIconCache -from ..ExporterOptions import ExporterOptions -from . import Components, JointHierarchy, Joints, Materials, PDMessage -from .Utilities import * +from src import gm +from src.APS.APS import getAuth, upload_mirabuf +from src.Logging import getLogger, logFailure, timed +from src.Parser.ExporterOptions import ExporterOptions +from src.Parser.SynthesisParser import ( + Components, + JointHierarchy, + Joints, + Materials, + PDMessage, +) +from src.Parser.SynthesisParser.Utilities import fill_info +from src.Types import ExportLocation, ExportMode +from src.UI.Camera import captureThumbnail, clearIconCache logger = getLogger() diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/PhysicalProperties.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/PhysicalProperties.py index 1aa91c7569..b178bcb3bb 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/PhysicalProperties.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/PhysicalProperties.py @@ -16,15 +16,12 @@ """ -import logging -import traceback from typing import Union import adsk from proto.proto_out import types_pb2 -from ...general_imports import INTERNAL_ID -from ...Logging import logFailure +from src.Logging import logFailure @logFailure diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/RigidGroup.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/RigidGroup.py index 2172c08fc0..8516cefae6 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/RigidGroup.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/RigidGroup.py @@ -12,13 +12,13 @@ - Success """ -from typing import * +from typing import Union import adsk.core import adsk.fusion from proto.proto_out import assembly_pb2 -from ...Logging import logFailure +from src.Logging import logFailure @logFailure diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Utilities.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Utilities.py index f508f32117..0a5d277766 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Utilities.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Utilities.py @@ -1,11 +1,9 @@ import math import uuid -from adsk.core import Base, Vector3D +from adsk.core import Vector3D from adsk.fusion import Component, Occurrence -# from proto.proto_out import types_pb2 - def guid_component(comp: Component) -> str: return f"{comp.entityToken}_{comp.id}" diff --git a/exporter/SynthesisFusionAddin/src/UI/Camera.py b/exporter/SynthesisFusionAddin/src/UI/Camera.py index 538968034d..02de04083a 100644 --- a/exporter/SynthesisFusionAddin/src/UI/Camera.py +++ b/exporter/SynthesisFusionAddin/src/UI/Camera.py @@ -1,11 +1,9 @@ import os -from adsk.core import SaveImageFileOptions +import adsk.core -from ..general_imports import * -from ..Logging import logFailure, timed -from ..Types import OString -from . import Helper +from src.Logging import logFailure +from src.Types import OString @logFailure @@ -25,7 +23,7 @@ def captureThumbnail(size=250): path = OString.ThumbnailPath(name) - saveOptions = SaveImageFileOptions.create(str(path.getPath())) + saveOptions = adsk.core.SaveImageFileOptions.create(str(path.getPath())) saveOptions.height = size saveOptions.width = size saveOptions.isAntiAliased = True diff --git a/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py b/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py index d7fd6ec6bb..c50c7feed2 100644 --- a/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py +++ b/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py @@ -9,22 +9,17 @@ import adsk.core import adsk.fusion -from ..APS.APS import getAuth, getUserInfo, refreshAuthToken -from ..general_imports import * -from ..Logging import getLogger, logFailure -from ..Parser.ExporterOptions import ExporterOptions -from ..Parser.SynthesisParser.Parser import Parser -from ..Parser.SynthesisParser.Utilities import guid_occurrence -from ..Types import ExportLocation, ExportMode -from . import CustomGraphics, FileDialogConfig, Helper, IconPaths -from .Configuration.SerialCommand import SerialCommand -from .GamepieceConfigTab import GamepieceConfigTab -from .GeneralConfigTab import GeneralConfigTab - -# Transition: AARD-1685 -# In the future all components should be handled in this way. -# This import broke everything when attempting to use absolute imports??? Investigate? -from .JointConfigTab import JointConfigTab +from src import gm +from src.APS.APS import getAuth, getUserInfo +from src.Logging import getLogger, logFailure +from src.Parser.ExporterOptions import ExporterOptions +from src.Parser.SynthesisParser.Parser import Parser +from src.Types import ExportLocation, ExportMode +from src.UI import FileDialogConfig +from src.UI.Configuration.SerialCommand import SerialCommand +from src.UI.GamepieceConfigTab import GamepieceConfigTab +from src.UI.GeneralConfigTab import GeneralConfigTab +from src.UI.JointConfigTab import JointConfigTab # ====================================== CONFIG COMMAND ====================================== diff --git a/exporter/SynthesisFusionAddin/src/UI/Configuration/SerialCommand.py b/exporter/SynthesisFusionAddin/src/UI/Configuration/SerialCommand.py index 16084148c5..663afe9337 100644 --- a/exporter/SynthesisFusionAddin/src/UI/Configuration/SerialCommand.py +++ b/exporter/SynthesisFusionAddin/src/UI/Configuration/SerialCommand.py @@ -7,7 +7,7 @@ import json -from ...Types import OString +from src.Types import OString def generateFilePath() -> str: diff --git a/exporter/SynthesisFusionAddin/src/UI/CreateCommandInputsHelper.py b/exporter/SynthesisFusionAddin/src/UI/CreateCommandInputsHelper.py index 536b93b57d..1f78b469bd 100644 --- a/exporter/SynthesisFusionAddin/src/UI/CreateCommandInputsHelper.py +++ b/exporter/SynthesisFusionAddin/src/UI/CreateCommandInputsHelper.py @@ -1,6 +1,6 @@ import adsk.core -from ..Logging import logFailure +from src.Logging import logFailure @logFailure diff --git a/exporter/SynthesisFusionAddin/src/UI/CustomGraphics.py b/exporter/SynthesisFusionAddin/src/UI/CustomGraphics.py index 52a49fa5d4..3b6bd8e2c2 100644 --- a/exporter/SynthesisFusionAddin/src/UI/CustomGraphics.py +++ b/exporter/SynthesisFusionAddin/src/UI/CustomGraphics.py @@ -1,11 +1,8 @@ -import logging -import traceback - import adsk.core import adsk.fusion -from ..general_imports import * -from ..Logging import logFailure +from src import gm +from src.Logging import logFailure @logFailure diff --git a/exporter/SynthesisFusionAddin/src/UI/Events.py b/exporter/SynthesisFusionAddin/src/UI/Events.py index 281ebf3f0e..64d0f1ea29 100644 --- a/exporter/SynthesisFusionAddin/src/UI/Events.py +++ b/exporter/SynthesisFusionAddin/src/UI/Events.py @@ -1,7 +1,10 @@ -from typing import Sequence, Tuple +import json +from typing import Sequence -from ..general_imports import * -from ..Logging import getLogger +import adsk.core + +from src import gm +from src.Logging import getLogger """ # This file is Special It links all function names to command requests that palletes can make automatically diff --git a/exporter/SynthesisFusionAddin/src/UI/FileDialogConfig.py b/exporter/SynthesisFusionAddin/src/UI/FileDialogConfig.py index 6f6f764cd9..d2465ae29b 100644 --- a/exporter/SynthesisFusionAddin/src/UI/FileDialogConfig.py +++ b/exporter/SynthesisFusionAddin/src/UI/FileDialogConfig.py @@ -1,12 +1,8 @@ -from typing import Union - import adsk.core import adsk.fusion -from ..general_imports import * - -# from ..proto_out import Configuration_pb2 -from ..Types import OString +from src import gm +from src.Types import OString def saveFileDialog(defaultPath: str | None = None, defaultName: str | None = None) -> str | bool: diff --git a/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py b/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py index f0d2f7d4bd..8eb4f80044 100644 --- a/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py +++ b/exporter/SynthesisFusionAddin/src/UI/GamepieceConfigTab.py @@ -1,11 +1,11 @@ import adsk.core import adsk.fusion -from ..Logging import logFailure -from ..Parser.ExporterOptions import ExporterOptions -from ..Types import Gamepiece, PreferredUnits, toKg, toLbs -from . import IconPaths -from .CreateCommandInputsHelper import ( +from src.Logging import logFailure +from src.Parser.ExporterOptions import ExporterOptions +from src.Types import Gamepiece, PreferredUnits, toKg, toLbs +from src.UI import IconPaths +from src.UI.CreateCommandInputsHelper import ( createBooleanInput, createTableInput, createTextBoxInput, diff --git a/exporter/SynthesisFusionAddin/src/UI/GeneralConfigTab.py b/exporter/SynthesisFusionAddin/src/UI/GeneralConfigTab.py index 116b8ca7d7..40a602a406 100644 --- a/exporter/SynthesisFusionAddin/src/UI/GeneralConfigTab.py +++ b/exporter/SynthesisFusionAddin/src/UI/GeneralConfigTab.py @@ -1,18 +1,18 @@ import adsk.core import adsk.fusion -from ..Logging import logFailure -from ..Parser.ExporterOptions import ( +from src.Logging import logFailure +from src.Parser.ExporterOptions import ( ExporterOptions, ExportLocation, ExportMode, PreferredUnits, ) -from ..Types import KG, toKg, toLbs -from . import IconPaths -from .CreateCommandInputsHelper import createBooleanInput, createTableInput -from .GamepieceConfigTab import GamepieceConfigTab -from .JointConfigTab import JointConfigTab +from src.Types import KG, toKg, toLbs +from src.UI import IconPaths +from src.UI.CreateCommandInputsHelper import createBooleanInput, createTableInput +from src.UI.GamepieceConfigTab import GamepieceConfigTab +from src.UI.JointConfigTab import JointConfigTab class GeneralConfigTab: diff --git a/exporter/SynthesisFusionAddin/src/UI/HUI.py b/exporter/SynthesisFusionAddin/src/UI/HUI.py index 3b52de9999..d1a968d642 100644 --- a/exporter/SynthesisFusionAddin/src/UI/HUI.py +++ b/exporter/SynthesisFusionAddin/src/UI/HUI.py @@ -1,6 +1,8 @@ -from ..general_imports import * -from ..Logging import logFailure -from . import Handlers, OsHelper +import adsk.core + +from src import INTERNAL_ID, gm +from src.Logging import logFailure +from src.UI import Handlers, OsHelper # no longer used diff --git a/exporter/SynthesisFusionAddin/src/UI/Handlers.py b/exporter/SynthesisFusionAddin/src/UI/Handlers.py index 710f61e8c8..4529b861db 100644 --- a/exporter/SynthesisFusionAddin/src/UI/Handlers.py +++ b/exporter/SynthesisFusionAddin/src/UI/Handlers.py @@ -1,4 +1,4 @@ -from ..general_imports import * +import adsk.core class HButtonCommandCreatedEvent(adsk.core.CommandCreatedEventHandler): diff --git a/exporter/SynthesisFusionAddin/src/UI/Helper.py b/exporter/SynthesisFusionAddin/src/UI/Helper.py index 7c8e3a5930..ba8bf9b0e9 100644 --- a/exporter/SynthesisFusionAddin/src/UI/Helper.py +++ b/exporter/SynthesisFusionAddin/src/UI/Helper.py @@ -1,8 +1,9 @@ from inspect import getmembers, isfunction -from typing import Union -from ..general_imports import * -from . import HUI, Events +import adsk.core + +from src import APP_NAME, APP_TITLE, INTERNAL_ID, gm +from src.UI import HUI, Events def getDocName() -> str or None: diff --git a/exporter/SynthesisFusionAddin/src/UI/IconPaths.py b/exporter/SynthesisFusionAddin/src/UI/IconPaths.py index 261720494c..2804af221a 100644 --- a/exporter/SynthesisFusionAddin/src/UI/IconPaths.py +++ b/exporter/SynthesisFusionAddin/src/UI/IconPaths.py @@ -1,6 +1,6 @@ import os -from . import OsHelper +from src.UI import OsHelper """ Dictionaries that store all the icon paths in ConfigCommand. All path strings are OS-independent diff --git a/exporter/SynthesisFusionAddin/src/UI/JointConfigTab.py b/exporter/SynthesisFusionAddin/src/UI/JointConfigTab.py index 7e34757783..b06ae6f2af 100644 --- a/exporter/SynthesisFusionAddin/src/UI/JointConfigTab.py +++ b/exporter/SynthesisFusionAddin/src/UI/JointConfigTab.py @@ -1,14 +1,10 @@ -import logging -import traceback - import adsk.core import adsk.fusion -from ..general_imports import INTERNAL_ID -from ..Logging import logFailure -from ..Types import Joint, JointParentType, SignalType, Wheel, WheelType -from . import IconPaths -from .CreateCommandInputsHelper import ( +from src.Logging import logFailure +from src.Types import Joint, JointParentType, SignalType, Wheel, WheelType +from src.UI import IconPaths +from src.UI.CreateCommandInputsHelper import ( createBooleanInput, createTableInput, createTextBoxInput, diff --git a/exporter/SynthesisFusionAddin/src/UI/MarkingMenu.py b/exporter/SynthesisFusionAddin/src/UI/MarkingMenu.py index 30c9f078e6..5b90c1b671 100644 --- a/exporter/SynthesisFusionAddin/src/UI/MarkingMenu.py +++ b/exporter/SynthesisFusionAddin/src/UI/MarkingMenu.py @@ -1,10 +1,7 @@ -import logging.handlers -import traceback - import adsk.core import adsk.fusion -from ..Logging import logFailure +from src.Logging import getLogger, logFailure # Ripped all the boiler plate from the example code: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-c90ce6a2-c282-11e6-a365-3417ebc87622 @@ -15,6 +12,8 @@ entities = [] occurrencesOfComponents = {} +logger = getLogger() + @logFailure(messageBox=True) def setupMarkingMenu(ui: adsk.core.UserInterface): @@ -207,6 +206,7 @@ def stopMarkingMenu(ui: adsk.core.UserInterface): if obj.isValid: obj.deleteMe() else: - ui.messageBox(str(obj) + " is not a valid object") + logger.warn(f"{str(obj)} is not a valid object") + cmdDefs.clear() handlers.clear() diff --git a/exporter/SynthesisFusionAddin/src/UI/ShowAPSAuthCommand.py b/exporter/SynthesisFusionAddin/src/UI/ShowAPSAuthCommand.py index bd45cfc062..999abd1176 100644 --- a/exporter/SynthesisFusionAddin/src/UI/ShowAPSAuthCommand.py +++ b/exporter/SynthesisFusionAddin/src/UI/ShowAPSAuthCommand.py @@ -1,15 +1,13 @@ import json -import os import time import traceback import urllib.parse import urllib.request -import webbrowser import adsk.core +from src import gm from src.APS.APS import CLIENT_ID, auth_path, convertAuthToken, getCodeChallenge -from src.general_imports import APP_NAME, DESCRIPTION, INTERNAL_ID, gm, my_addin_path from src.Logging import getLogger logger = getLogger() diff --git a/exporter/SynthesisFusionAddin/src/UI/ShowWebsiteCommand.py b/exporter/SynthesisFusionAddin/src/UI/ShowWebsiteCommand.py index d7e1539e5e..cc99cffb07 100644 --- a/exporter/SynthesisFusionAddin/src/UI/ShowWebsiteCommand.py +++ b/exporter/SynthesisFusionAddin/src/UI/ShowWebsiteCommand.py @@ -1,8 +1,9 @@ +import traceback import webbrowser import adsk.core -from ..general_imports import * +from src import gm class ShowWebsiteCommandExecuteHandler(adsk.core.CommandEventHandler): diff --git a/exporter/SynthesisFusionAddin/src/UI/Toolbar.py b/exporter/SynthesisFusionAddin/src/UI/Toolbar.py index bfcc34189a..f9d150cc3c 100644 --- a/exporter/SynthesisFusionAddin/src/UI/Toolbar.py +++ b/exporter/SynthesisFusionAddin/src/UI/Toolbar.py @@ -1,6 +1,5 @@ -from ..general_imports import * -from ..Logging import logFailure -from ..strings import INTERNAL_ID +from src import INTERNAL_ID, gm +from src.Logging import logFailure class Toolbar: diff --git a/exporter/SynthesisFusionAddin/src/__init__.py b/exporter/SynthesisFusionAddin/src/__init__.py new file mode 100644 index 0000000000..1e426279bb --- /dev/null +++ b/exporter/SynthesisFusionAddin/src/__init__.py @@ -0,0 +1,17 @@ +import os +import platform + +from src.GlobalManager import GlobalManager + +APP_NAME = "Synthesis" +APP_TITLE = "Synthesis Robot Exporter" +DESCRIPTION = "Exports files from Fusion into the Synthesis Format" +INTERNAL_ID = "Synthesis" +ADDIN_PATH = os.path.dirname(os.path.realpath(__file__)) + +SYSTEM = platform.system() +assert SYSTEM != "Linux" + +gm = GlobalManager() + +__all__ = ["APP_NAME", "APP_TITLE", "DESCRIPTION", "INTERNAL_ID", "ADDIN_PATH", "SYSTEM", "gm"] diff --git a/exporter/SynthesisFusionAddin/src/general_imports.py b/exporter/SynthesisFusionAddin/src/general_imports.py deleted file mode 100644 index aabdae5cac..0000000000 --- a/exporter/SynthesisFusionAddin/src/general_imports.py +++ /dev/null @@ -1,42 +0,0 @@ -import json -import os -import pathlib -import sys -import traceback -import uuid -from datetime import datetime -from time import time -from types import FunctionType - -import adsk.core -import adsk.fusion - -from .GlobalManager import * -from .Logging import getLogger -from .strings import * - -logger = getLogger() - -# hard coded to bypass errors for now -PROTOBUF = True -DEBUG = True - -try: - path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) - - path_proto_files = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "proto", "proto_out")) - - if not path in sys.path: - sys.path.insert(1, path) - - if not path_proto_files in sys.path: - sys.path.insert(2, path_proto_files) -except: - logger.error("Failed:\n{}".format(traceback.format_exc())) - -try: - # Setup the global state - gm: GlobalManager = GlobalManager() - my_addin_path = os.path.dirname(os.path.realpath(__file__)) -except: - logger.error("Failed:\n{}".format(traceback.format_exc())) diff --git a/exporter/SynthesisFusionAddin/src/strings.py b/exporter/SynthesisFusionAddin/src/strings.py deleted file mode 100644 index b5d79c055c..0000000000 --- a/exporter/SynthesisFusionAddin/src/strings.py +++ /dev/null @@ -1,4 +0,0 @@ -APP_NAME = "Synthesis" -APP_TITLE = "Synthesis Robot Exporter" -DESCRIPTION = "Exports files from Fusion into the Synthesis Format" -INTERNAL_ID = "Synthesis"