Implement Phase 1: Auto-loading for ztools and Silo addons

- Add src/Mod/Create/ module to handle addon loading
- Init.py adds mods/ztools and mods/silo to sys.path at startup
- InitGui.py loads workbenches from addon InitGui.py files
- CMakeLists.txt installs Create module and mods/ directory
- Set ZToolsWorkbench as default startup workbench in preferences
This commit is contained in:
forbes
2026-01-27 10:03:12 -06:00
parent 6c45f0619f
commit 0e5998312a
5 changed files with 133 additions and 0 deletions

View File

@@ -76,6 +76,9 @@
<FCUInt Name="TreeEditColor" Value="3416717311"/>
<FCUInt Name="TreeActiveColor" Value="2799935999"/>
</FCParamGroup>
<FCParamGroup Name="General">
<FCText Name="AutoloadModule">ZToolsWorkbench</FCText>
</FCParamGroup>
<FCParamGroup Name="MainWindow">
<FCText Name="StyleSheet">KindredCreate.qss</FCText>
</FCParamGroup>

View File

@@ -1,3 +1,7 @@
# Kindred Create core module - always built
# Handles auto-loading of ztools and Silo addons
add_subdirectory(Create)
if(BUILD_ADDONMGR)
if( NOT EXISTS "${CMAKE_SOURCE_DIR}/src/Mod/AddonManager/CMakeLists.txt" )
message(FATAL_ERROR "The Addon Manager has been moved into a git submodule. Please run

View File

@@ -0,0 +1,39 @@
# Kindred Create core module
# Handles auto-loading of ztools and Silo addons
# Install Python init files
install(
FILES
Init.py
InitGui.py
DESTINATION
Mod/Create
)
# Install ztools addon
install(
DIRECTORY
${CMAKE_SOURCE_DIR}/mods/ztools/ztools
DESTINATION
mods/ztools
)
install(
DIRECTORY
${CMAKE_SOURCE_DIR}/mods/ztools/CatppuccinMocha
DESTINATION
mods/ztools
)
install(
FILES
${CMAKE_SOURCE_DIR}/mods/ztools/package.xml
DESTINATION
mods/ztools
)
# Install Silo addon
install(
DIRECTORY
${CMAKE_SOURCE_DIR}/mods/silo/pkg/freecad/
DESTINATION
mods/silo/pkg/freecad
)

45
src/Mod/Create/Init.py Normal file
View File

@@ -0,0 +1,45 @@
# Kindred Create - Core Module
# Console initialization - loads ztools and Silo addons
import os
import sys
import FreeCAD
def setup_kindred_addons():
"""Add Kindred Create addon paths and load their Init.py files."""
# Get the FreeCAD home directory (where src/Mod/Create is installed)
home = FreeCAD.getHomePath()
mods_dir = os.path.join(home, "mods")
# Define built-in addons with their paths relative to mods/
addons = [
("ztools", "ztools/ztools"), # mods/ztools/ztools/
("silo", "silo/pkg/freecad"), # mods/silo/pkg/freecad/
]
for name, subpath in addons:
addon_path = os.path.join(mods_dir, subpath)
if os.path.isdir(addon_path):
# Add to sys.path if not already present
if addon_path not in sys.path:
sys.path.insert(0, addon_path)
# Execute Init.py if it exists
init_file = os.path.join(addon_path, "Init.py")
if os.path.isfile(init_file):
try:
with open(init_file) as f:
exec(compile(f.read(), init_file, "exec"))
FreeCAD.Console.PrintLog(f"Create: Loaded {name} Init.py\n")
except Exception as e:
FreeCAD.Console.PrintWarning(
f"Create: Failed to load {name}: {e}\n"
)
else:
FreeCAD.Console.PrintLog(f"Create: Addon path not found: {addon_path}\n")
setup_kindred_addons()
FreeCAD.Console.PrintLog("Create module initialized\n")

42
src/Mod/Create/InitGui.py Normal file
View File

@@ -0,0 +1,42 @@
# Kindred Create - Core Module
# GUI initialization - loads ztools and Silo workbenches
import os
import sys
import FreeCAD
import FreeCADGui
def setup_kindred_workbenches():
"""Load Kindred Create addon workbenches."""
home = FreeCAD.getHomePath()
mods_dir = os.path.join(home, "mods")
addons = [
("ztools", "ztools/ztools"),
("silo", "silo/pkg/freecad"),
]
for name, subpath in addons:
addon_path = os.path.join(mods_dir, subpath)
if os.path.isdir(addon_path):
# Ensure path is in sys.path
if addon_path not in sys.path:
sys.path.insert(0, addon_path)
# Execute InitGui.py if it exists
init_gui_file = os.path.join(addon_path, "InitGui.py")
if os.path.isfile(init_gui_file):
try:
with open(init_gui_file) as f:
exec(compile(f.read(), init_gui_file, "exec"))
FreeCAD.Console.PrintLog(f"Create: Loaded {name} workbench\n")
except Exception as e:
FreeCAD.Console.PrintWarning(
f"Create: Failed to load {name} GUI: {e}\n"
)
setup_kindred_workbenches()
FreeCAD.Console.PrintLog("Create GUI module initialized\n")