# Blender Integration Plan v2 ## Goal Add an optional step to `main.py` to run `blenderscripts/create_nodegroups.py` and `blenderscripts/create_materials.py` on specified `.blend` files after asset processing is complete. ## Proposed Plan 1. **Update `config.py`:** * Add two new optional configuration variables: `DEFAULT_NODEGROUP_BLEND_PATH` and `DEFAULT_MATERIALS_BLEND_PATH`. These will store the default paths to the Blender files. 2. **Update `main.py` Argument Parser:** * Add two new optional command-line arguments: `--nodegroup-blend` and `--materials-blend`. * These arguments will accept file paths to the respective `.blend` files. * If provided, these arguments will override the default paths specified in `config.py`. 3. **Update `blenderscripts/create_nodegroups.py` and `blenderscripts/create_materials.py`:** * Modify both scripts to accept the processed asset library root path (`PROCESSED_ASSET_LIBRARY_ROOT`) as a command-line argument. This will be passed to the script when executed by Blender using the `--` separator. * Update the scripts to read this path from `sys.argv` instead of using the hardcoded variable. 4. **Update `main.py` Execution Flow:** * After the main asset processing loop (`run_processing`) completes and the summary is reported, check if the `--nodegroup-blend` or `--materials-blend` arguments (or their fallbacks from `config.py`) were provided. * If a path for the nodegroup `.blend` file is available: * Construct a command to execute Blender in the background (`-b`), load the specified nodegroup `.blend` file, run the `create_nodegroups.py` script using `--python`, pass the processed asset root directory as an argument after `--`, and save the `.blend` file (`-S`). * Execute this command using the `execute_command` tool. * If a path for the materials `.blend` file is available: * Construct a similar command to execute Blender in the background, load the specified materials `.blend` file, run the `create_materials.py` script using `--python`, pass the processed asset root directory as an argument after `--`, and save the `.blend` file (`-S`). * Execute this command using the `execute_command` tool. * Include error handling for the execution of the Blender commands. ## Execution Flow Diagram ```mermaid graph TD A[Asset Processing Complete] --> B[Report Summary]; B --> C{Nodegroup Blend Path Specified?}; C -- Yes --> D[Get Nodegroup Blend Path (Arg or Config)]; D --> E[Construct Blender Command for Nodegroups]; E --> F[Execute Command: blender -b nodegroup.blend --python create_nodegroups.py -- -S]; F --> G{Command Successful?}; G -- Yes --> H{Materials Blend Path Specified?}; G -- No --> I[Log Nodegroup Error]; I --> H; H -- Yes --> J[Get Materials Blend Path (Arg or Config)]; J --> K[Construct Blender Command for Materials]; K --> L[Execute Command: blender -b materials.blend --python create_materials.py -- -S]; L --> M{Command Successful?}; M -- Yes --> N[End main.py]; M -- No --> O[Log Materials Error]; O --> N; H -- No --> N; C -- No --> H;