diff --git a/ztools/InitGui.py b/ztools/InitGui.py index 2f1fd52..1a6662f 100644 --- a/ztools/InitGui.py +++ b/ztools/InitGui.py @@ -66,13 +66,8 @@ class ZToolsWorkbench(Gui.Workbench): except Exception: pass - from ztools.commands import ( - assembly_pattern_commands, - datum_commands, - pattern_commands, - pocket_commands, - spreadsheet_commands, - ) + # Command imports moved to module scope (after Gui.addWorkbench) so they + # are available before Initialize() runs. See end of file. # ===================================================================== # PartDesign Structure Tools @@ -306,12 +301,6 @@ class ZToolsWorkbench(Gui.Workbench): + self.ztools_spreadsheet_tools, ) - # Register the PartDesign manipulator now that commands exist. - # Guard so it only registers once even if Initialize is called again. - if not getattr(ZToolsWorkbench, "_manipulator_installed", False): - ZToolsWorkbench._manipulator_installed = True - Gui.addWorkbenchManipulator(_ZToolsPartDesignManipulator()) - App.Console.PrintMessage("ztools workbench initialized\n") def Activated(self): @@ -337,11 +326,24 @@ class ZToolsWorkbench(Gui.Workbench): Gui.addWorkbench(ZToolsWorkbench()) +# --------------------------------------------------------------------------- +# Eager command registration +# --------------------------------------------------------------------------- +# Import command modules at module scope so Gui.addCommand() calls run before +# any workbench activates. This ensures the PartDesign manipulator can +# reference them regardless of workbench activation order (#52). + +from ztools.commands import ( + assembly_pattern_commands, + datum_commands, + pattern_commands, + pocket_commands, + spreadsheet_commands, +) + # --------------------------------------------------------------------------- # WorkbenchManipulator: inject ZTools commands into PartDesign workbench # --------------------------------------------------------------------------- -# Registered in ZToolsWorkbench.Initialize() after commands are imported, -# so the commands exist before the manipulator references them. class _ZToolsPartDesignManipulator: @@ -384,3 +386,6 @@ class _ZToolsPartDesignManipulator: "after": "", }, ] + + +Gui.addWorkbenchManipulator(_ZToolsPartDesignManipulator())