# CodeExecute Module **Multi-language code execution framework for Revit development.** Execute Python scripts and C# assemblies directly within Revit, with automatic dependency management, debugging support, and file watching. ![Python Demo](images/RevitDevTool_PythonDemo.gif) --- ## What It Does CodeExecute provides a unified framework for running code inside Revit: - 🐍 **Python Scripts** - CPython 3.13 with full ecosystem access - 🔧 **C# Assemblies** - IExternalCommand discovery and execution **Core capabilities:** - Automatic folder scanning and hierarchical organization - File watching for instant reload on changes - Unified tree model for consistent UI - Output capture to Trace panel --- ## Python Execution **Modern Python with zero-friction dependency management.** ### Key Features - **CPython 3.13** - Latest Python with full ecosystem - **PEP 723 inline dependencies** - No separate requirements.txt - **UV resolver** - Automatic package installation (10-15x faster than pip) - **VSCode debugger** - Full IDE debugging with breakpoints - **Module isolation** - Clean cache between runs ### Quick Example ```python # /// script # dependencies = ["pandas==1.5.3"] # /// import pandas as pd from Autodesk.Revit import DB doc = __revit__.ActiveUIDocument.Document walls = DB.FilteredElementCollector(doc).OfClass(DB.Wall).ToElements() data = [{"Name": w.Name, "Level": w.LevelName} for w in walls] df = pd.DataFrame(data) print(df.groupby("Level").size()) ``` **What happens:** System auto-installs pandas → executes script → outputs to Trace panel. **Learn more:** - [Python Execution](CodeExecute-PythonExecution.md) - Complete workflow and dependency management - [Python Debugging](CodeExecute-PythonDebugging.md) - VSCode debugger setup - [Stub Generation](CodeExecute-StubGeneration.md) - IDE autocomplete --- ## .NET Execution **C# assembly execution inspired by RevitAddinManager.** ### Key Features - **IExternalCommand discovery** - Automatic command detection - **FileWatcher** - Auto-reload on assembly changes - **Dependency loading** - All referenced DLLs loaded automatically - **No temp folder** - Direct execution for Revit 2024- (.NET 4.8) ### Improvements Over RevitAddinManager | Feature | RevitDevTool | RevitAddinManager | |---------|--------------|-------------------| | **FileWatcher** | ✅ Automatic detection | ❌ Manual reload | | **Dependencies** | ✅ Auto-loaded | ⚠️ Manual setup | | **Temp folder (2024-)** | ✅ No copy | ❌ Copies to temp | | **Unnecessary features** | ✅ Removed | ⚠️ Many extras | **Learn more:** [.NET Execution](CodeExecute-DotNetExecution.md) --- ## Comparison with Other Tools ### vs pyRevit **Different target audiences:** | Aspect | RevitDevTool | pyRevit | |--------|--------------|---------| | **Target User** | Developers & researchers | End users | | **Primary Use** | Code development & research | Ribbon automation | | **Python** | CPython 3.13 | IronPython 2.7 (default) | | **Packages** | Full ecosystem (pandas, numpy, AI/ML) | Limited (Revit API only) | | **Debugging** | VSCode (full IDE) | pdb (command-line) | | **Dependencies** | Automatic (PEP 723 + UV) | Manual pip install | | **Best For** | Computational design, data science, AI | Automation buttons for teams | **Learn more:** [vs pyRevit](CodeExecute-VsPyRevit.md) ### Python Ecosystem Options | Tool | Python | Auto-dependencies | VSCode Debugger | Best For | |------|--------|-------------------|-----------------|----------| | **pyRevit** | IronPython 2.7 | ❌ | ❌ | End-user automation | | **Dynamo** | CPython 3.9 | ❌ | ❌ | Visual programming | | **RevitDevTool** | CPython 3.13 | ✅ UV | ✅ debugpy | Development & research | **Learn more:** [Python Ecosystems](CodeExecute-PythonEcosystems.md) --- ## Common Workflows ### 1. Python Script with Packages **Scenario:** Analyze building data with pandas ```python # /// script # dependencies = ["pandas==1.5.3"] # /// import pandas as pd # ... your code ``` 1. Declare dependencies inline 2. Click execute 3. System auto-installs packages 4. Script runs with full pandas support ### 2. VSCode Debugging **Scenario:** Debug complex algorithm 1. Set breakpoints in VSCode 2. Press F5 → Attach to Revit 3. Execute script 4. Debugger pauses at breakpoints 5. Inspect variables, step through code ### 3. C# Assembly Execution **Scenario:** Run custom IExternalCommand 1. Build your C# project 2. Load DLL in RevitDevTool 3. FileWatcher detects commands 4. Click command → Execute --- ## Architecture For developers contributing to RevitDevTool or building custom providers, see architecture documentation in the repository: **Location:** `docs/CodeExecute/architecture/` - System design and patterns - Provider and strategy patterns - Tree model implementation - Python.NET integration details --- ## See Also ### Execution Guides - [Python Execution](CodeExecute-PythonExecution.md) - Complete Python workflow - [.NET Execution](CodeExecute-DotNetExecution.md) - C# assembly execution - [Python Debugging](CodeExecute-PythonDebugging.md) - VSCode debugger - [Stub Generation](CodeExecute-StubGeneration.md) - IDE autocomplete ### Comparisons - [vs pyRevit](CodeExecute-VsPyRevit.md) - Target audience and use cases - [Python Ecosystems](CodeExecute-PythonEcosystems.md) - All Python options for Revit ### Examples - [Dashboard Example](Examples-Dashboard.md) - WebView2 + Plotly - [Data Analysis Example](Examples-DataAnalysis.md) - Polars analytics