Skip to content

fix manual preview button #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GridfinityGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def run(context):
commands.start()

except:
futil.handle_error('run')
futil.handle_error("run")


def stop(context):
Expand All @@ -21,4 +21,4 @@ def stop(context):
commands.stop()

except:
futil.handle_error('stop')
futil.handle_error("stop")
2 changes: 1 addition & 1 deletion commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def start():
# The stop function will be run when the add-in is stopped.
def stop():
for command in commands:
command.stop()
command.stop()
725 changes: 531 additions & 194 deletions commands/commandCreateBaseplate/entry.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions commands/commandCreateBaseplate/inputState.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict
from dataclasses import dataclass


@dataclass
class InputState:
baseWidth: float
Expand Down
1,570 changes: 1,152 additions & 418 deletions commands/commandCreateBin/entry.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
DEBUG = True

# Gets the name of the add-in from the name of the folder the py file is in.
# This is used when defining unique internal names for various UI elements
# that need a unique name. It's also recommended to use a company name as
# This is used when defining unique internal names for various UI elements
# that need a unique name. It's also recommended to use a company name as
# part of the ID to better ensure the ID is unique.
ADDIN_NAME = 'GridfinityGenerator'
COMPANY_NAME = 'LevMishin'
ADDIN_NAME = "GridfinityGenerator"
COMPANY_NAME = "LevMishin"

# Palettes
sample_palette_id = f'{COMPANY_NAME}_{ADDIN_NAME}_palette_id'
sample_palette_id = f"{COMPANY_NAME}_{ADDIN_NAME}_palette_id"
29 changes: 17 additions & 12 deletions lib/configUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import os
import json

CONFIG_FILE_NAME = 'config.ini'
CONFIG_FILE_NAME = "config.ini"


def getDefaultConfig():
config = configparser.ConfigParser()
config['UI'] = {'IS_PROMOTED': 'yes'}
config["UI"] = {"IS_PROMOTED": "yes"}
return config


def readConfig(path: str):
CONFIG_FILE_PATH = os.path.join(path, CONFIG_FILE_NAME)
config = configparser.ConfigParser()
Expand All @@ -22,24 +24,26 @@ def readConfig(path: str):
except:
return getDefaultConfig()


def writeConfig(config: configparser.ConfigParser, path: str):
try:
CONFIG_FILE_PATH = os.path.join(path, CONFIG_FILE_NAME)
if not os.path.exists(path):
os.mkdir(path)
with open(CONFIG_FILE_PATH, 'w') as configfile:
with open(CONFIG_FILE_PATH, "w") as configfile:
config.write(configfile)
return True
except:
return False


def deleteConfigFile(path: str):
try:
if os.path.exists(path):
os.remove(path)
return True
except:
futil.log(f'Couldn\'t delete config file from {path}')
futil.log(f"Couldn't delete config file from {path}")
return None


Expand All @@ -49,20 +53,21 @@ def readJsonConfig(path: str):
with open(path) as configFile:
return json.load(configFile)
except:
futil.log(f'Couldn\'t load config file from {path}')
futil.log(f"Couldn't load config file from {path}")
return None



def dumpJsonConfig(path: str, config: any):
try:
futil.log(f'Writing config to path {os.path.dirname(path)}')
futil.log(f"Writing config to path {os.path.dirname(path)}")
if os.path.exists(os.path.dirname(path)):
with open(path, 'w+') as configFile:
with open(path, "w+") as configFile:
json.dump(config, configFile, indent=True)
return True
else:
futil.log(f'Config folder doesn\'t exist {os.path.dirname(path)}')
futil.log(f"Config folder doesn't exist {os.path.dirname(path)}")
return False

except Exception as err:
futil.log(f'Couldn\'t write config file to {path}, error: {err}')
return None
futil.log(f"Couldn't write config file to {path}, error: {err}")
return None
29 changes: 14 additions & 15 deletions lib/fusion360utils/event_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@


def add_handler(
event: adsk.core.Event,
callback: Callable,
*,
name: str = None,
local_handlers: list = None
event: adsk.core.Event,
callback: Callable,
*,
name: str = None,
local_handlers: list = None
):
"""Adds an event handler to the specified event.

Expand All @@ -40,32 +40,31 @@ def add_handler(
This argument must be specified by its keyword. If not
specified the handler is added to a global list and can
be cleared using the clear_handlers function. You may want
to maintain your own handler list so it can be managed
to maintain your own handler list so it can be managed
independently for each command.

:returns:
The event handler that was created. You don't often need this reference, but it can be useful in some cases.
"""
"""
module = sys.modules[event.__module__]
handler_type = module.__dict__[event.add.__annotations__['handler']]
handler_type = module.__dict__[event.add.__annotations__["handler"]]
handler = _create_handler(handler_type, callback, event, name, local_handlers)
event.add(handler)
return handler


def clear_handlers():
"""Clears the global list of handlers.
"""
"""Clears the global list of handlers."""
global _handlers
_handlers = []


def _create_handler(
handler_type,
callback: Callable,
event: adsk.core.Event,
name: str = None,
local_handlers: list = None
handler_type,
callback: Callable,
event: adsk.core.Event,
name: str = None,
local_handlers: list = None,
):
handler = _define_handler(handler_type, callback, name)()
(local_handlers if local_handlers is not None else _handlers).append(handler)
Expand Down
23 changes: 14 additions & 9 deletions lib/fusion360utils/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@
# Attempt to read DEBUG flag from parent config.
try:
from ... import config

DEBUG = config.DEBUG
except:
DEBUG = False


def log(message: str, level: adsk.core.LogLevels = adsk.core.LogLevels.InfoLogLevel, force_console: bool = False):
def log(
message: str,
level: adsk.core.LogLevels = adsk.core.LogLevels.InfoLogLevel,
force_console: bool = False,
):
"""Utility function to easily handle logging in your app.

Arguments:
message -- The message to log.
level -- The logging severity level.
force_console -- Forces the message to be written to the Text Command window.
"""
force_console -- Forces the message to be written to the Text Command window.
"""
# Always print to console, only seen through IDE.
print(message)
print(message)

# Log all errors to Fusion log file.
if level == adsk.core.LogLevels.ErrorLogLevel:
Expand All @@ -53,12 +58,12 @@ def handle_error(name: str, show_message_box: bool = False):
name -- A name used to label the error.
show_message_box -- Indicates if the error should be shown in the message box.
If False, it will only be shown in the Text Command window
and logged to the log file.
"""
and logged to the log file.
"""

log('===== Error =====', adsk.core.LogLevels.ErrorLogLevel)
log(f'{name}\n{traceback.format_exc()}', adsk.core.LogLevels.ErrorLogLevel)
log("===== Error =====", adsk.core.LogLevels.ErrorLogLevel)
log(f"{name}\n{traceback.format_exc()}", adsk.core.LogLevels.ErrorLogLevel)

# If desired you could show an error as a message box.
if show_message_box:
ui.messageBox(f'{name}\n{traceback.format_exc()}')
ui.messageBox(f"{name}\n{traceback.format_exc()}")
Loading