FreeCAD workbench to create assembly handbooks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

88 lines
2.4 KiB

import os
import FreeCADGui as Gui
import FreeCAD as App
import ahb_locator
global ahb_icon
ahb_icon = os.path.join(os.path.dirname(ahb_locator.__file__), "resources/assembly-handbook.svg")
class AssemblyHandbookWorkbench(Gui.Workbench):
"""
class which gets initiated at startup of the gui
"""
MenuText = "Assembly handbook"
ToolTip = "A workbench for automating creation of an assembly handbook"
Icon = ahb_icon
dev = True # indicates development mode (enables additional tools, log, debug checks, etc.)
context = None
def GetClassName(self):
return "Gui::PythonWorkbench"
def Initialize(self):
"""
This function is called at the first activation of the workbench.
"""
self.registerCommands()
def Activated(self):
"""
code which should be computed when a user switch to this workbench
"""
if self.context is None:
self.initializeContext()
def Deactivated(self):
"""
code which should be computed when this workbench is deactivated
"""
pass
def initializeContext(self):
import ahb_context
self.context = ahb_context.AHB_Context()
def registerCommands(self):
toolbox = []
self.importModule('ahb_cmd_export_csv')
toolbox.append("AHB_exportCsv")
self.importModule('ahb_cmd_set_active_stage')
toolbox.append("AHB_setActiveStage")
self.importModule('ahb_cmd_set_part_stage')
toolbox.append("AHB_setPartStage")
if self.dev:
self.importModule('ahb_cmd_reload')
toolbox.append("AHB_reload")
self.appendToolbar("Assembly Handbook", toolbox)
self.appendMenu("Assembly Handbook", toolbox)
def reload(self):
# Used for development only
self.removeToolbar("Assembly Handbook")
self.removeMenu("Assembly Handbook")
import importlib
import ahb_context
importlib.reload(ahb_context)
self.initializeContext()
self.registerCommands()
pass
def importModule(self, moduleName):
import importlib
module = importlib.import_module(moduleName)
if self.dev:
importlib.reload(module)
Gui.addWorkbench(AssemblyHandbookWorkbench())