Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
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
142 changes: 100 additions & 42 deletions python/InvenTreeLink/InvenTreeLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import os

import threading

try:
from .apper import apper
from . import config
Expand All @@ -12,41 +14,13 @@
my_addin = apper.FusionApp(config.app_name, config.company_name, False)
my_addin.root_path = config.app_path

from .commands.ShowPartCommand import ShowPartCommand
from .commands.EditPartCommand import EditPartCommand
from .commands.BOMOverviewCommand import BomOverviewPaletteShowCommand
from .commands.SendBomCommand import SendBomCommand
from .commands.SendBomOnlineCommand import SendBomOnlineCommand
from .commands.SendStepCommand import SendStepCommand

from .commands.GenerateBomCommand import GenerateBomCommand
from .commands.ImportStlCommand import ImportStlCommand
from .commands.ImportPartCommand import ImportPartCommand
# Commands
my_addin.add_command(
'Show part details',
ShowPartCommand,
{
'cmd_description': 'Show the InvenTree part-details for the selected part',
'cmd_id': config.DEF_SEND_PART,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': 'Commands',
'cmd_resources': config.DEF_SEND_PART,
'command_visible': True,
'command_promoted': False,
}
)

my_addin.add_command(
'Upload STEP to attachments',
SendStepCommand,
{
'cmd_description': 'Generates a STEP file and attaches it to a part',
'cmd_id': config.DEF_SEND_STEP,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': 'Commands',
'cmd_resources': config.DEF_SEND_BOM,
'command_visible': True,
'command_promoted': False,
'palette_id': config.ITEM_PALETTE,
}
)

# Palette
my_addin.add_command(
Expand All @@ -56,7 +30,7 @@
'cmd_description': 'Show the BOM overview palette',
'cmd_id': config.DEF_SHOW_PALETTE,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': config.APP_PANEL,
'toolbar_panel_id': config.ToolbarPanelID.INVENTREE_LINK,
'cmd_resources': 'ShowPalette',
'command_visible': True,
'command_promoted': True,
Expand All @@ -75,12 +49,12 @@
# Commands that need the palette
my_addin.add_command(
'Load BOM for assembly',
SendBomCommand,
GenerateBomCommand,
{
'cmd_description': 'Load the BOM for the assembly in the current file',
'cmd_id': config.DEF_SEND_BOM,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': config.APP_PANEL,
'toolbar_panel_id': config.ToolbarPanelID.INVENTREE_LINK,
'cmd_resources': config.DEF_SEND_BOM,
'command_visible': True,
'command_promoted': False,
Expand All @@ -89,14 +63,43 @@
)

my_addin.add_command(
'Get InvenTree Information',
SendBomOnlineCommand,
'Edit Part',
EditPartCommand,
{
'cmd_description': 'Fetch the InvenTree information for all BOM-parts',
'cmd_id': config.DEF_SEND_ONLINE_STATE,
'cmd_description': 'Show the InvenTree part-details for the selected part',
'cmd_id': config.DEF_SEND_PART,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': config.APP_PANEL,
'cmd_resources': config.DEF_SEND_ONLINE_STATE,
'toolbar_panel_id': config.ToolbarPanelID.PART,
'cmd_resources': config.DEF_SEND_PART,
'command_visible': True,
'command_promoted': False,
}
)

my_addin.add_command(
'Import Part',
ImportPartCommand,
{
'cmd_description': 'Import a Part as STL',
'cmd_id': config.DEF_IMPORT_PART,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': config.ToolbarPanelID.PART,
'cmd_resources': config.DEF_SEND_BOM,
'command_visible': True,
'command_promoted': False,
'palette_id': config.ITEM_PALETTE,
}
)

my_addin.add_command(
'Export STEP',
ImportStlCommand,
{
'cmd_description': 'Generates a STEP file and attaches it to a part',
'cmd_id': config.DEF_SEND_STEP,
'workspace': 'FusionSolidEnvironment',
'toolbar_panel_id': config.ToolbarPanelID.PART,
'cmd_resources': 'ShowPalette',
'command_visible': True,
'command_promoted': False,
'palette_id': config.ITEM_PALETTE,
Expand All @@ -113,6 +116,61 @@

functions.init_Fusion360()

# class MyDocumentActivatedHandler(adsk.core.DocumentEventHandler):
# def __init__(self):
# super().__init__()
# def notify(self, args):
# eventArgs = adsk.core.DocumentEventArgs.cast(args)

# # Code to react to the event.
# ui.messageBox('In MyDocumentActivatedHandler event handler.\ndocument: {}'.format(eventArgs.document.name))

# class MyDocumentSavedHandler(adsk.core.DocumentEventHandler):
# def __init__(self):
# super().__init__()

# def notify(self, args):
# eventArgs = adsk.core.DocumentEventArgs.cast(args)

# # Code to react to the event.
# ui.messageBox('In MyDocumentSavedHandler event handler.')

# onDocumentSaved = MyDocumentSavedHandler()
# app.documentSaved.add(onDocumentSaved)

# onDocumentActivated = MyDocumentActivatedHandler()
# app.documentActivated.add(onDocumentActivated)

# def correct_inventree_names_thread():
# # Recursively correct the names to inventree names
# def correct_inventree_names(component):
# part = functions.inventree_get_part(component.id)

# if part:
# if component.name.lower() != part.name.lower():
# print(f"Correcting name of '{component.name}' to '{part.name}'")
# component.name = part.name

# if component.partNumber.lower() != part.IPN.lower():
# print(f"Correcting IPN of '{component.partNumber}' to '{part.IPN}'")
# component.partNumber = part.IPN

# for occurrence in component.occurrences:
# if occurrence.component:
# correct_inventree_names(occurrence.component)

# ao = apper.AppObjects()
# root = ao.product.rootComponent

# for occurrence in root.occurrences:
# if occurrence.component:
# correct_inventree_names(occurrence.component)

# t = threading.Thread(target=correct_inventree_names_thread)
# t.start()

print("InvenTreeLink started.")

except: # noqa: E722
app = adsk.core.Application.get()
ui = app.userInterface
Expand Down
Loading