From 12e332240a3eae348f14a53eeeda277717d73cff Mon Sep 17 00:00:00 2001 From: forbes Date: Sun, 8 Feb 2026 17:57:54 -0600 Subject: [PATCH] fix: register commands and manipulator at module scope (#52) Move command imports and PartDesign manipulator installation from ZToolsWorkbench.Initialize() to module scope. This ensures commands are registered and the manipulator is available before any workbench activates, fixing the case where PartDesign activates before ZTools and ztools buttons never appear. --- ztools/InitGui.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) 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())