|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance for AI assistants working with the pyRevit codebase. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +pyRevit is a Rapid Application Development (RAD) environment for Autodesk Revit. It allows users to create automation tools and add-ins using Python (IronPython 2.7.12 default, CPython 3.12.3, or IronPython 3.4.0), C#, or VB.NET. The project includes a CLI utility for deployment and a telemetry server for usage tracking. |
| 8 | + |
| 9 | +## Repository Structure |
| 10 | + |
| 11 | +- `bin/` - Pre-built binaries (DLLs) and Python engines (IPY2712PR, IPY342, CPY3123) |
| 12 | +- `dev/` - C# source code, build scripts, and solution files |
| 13 | +- `docs/` - Documentation source for the website (mkdocs) |
| 14 | +- `extensions/` - pyRevit extensions (tools visible in Revit ribbon) |
| 15 | +- `extras/` - Additional resources (icons, dark mode generator) |
| 16 | +- `licenses/` - Third-party library licenses |
| 17 | +- `pyrevitlib/` - Python libraries for Revit API development |
| 18 | +- `release/` - Build artifacts and installer configurations |
| 19 | +- `site-packages/` - Third-party Python packages (must be IronPython 2.7.12 compatible) |
| 20 | + |
| 21 | +## Languages and Technologies |
| 22 | + |
| 23 | +- **Python**: IronPython 2.7.12 (default), CPython 3.12.3, IronPython 3.4.0 |
| 24 | +- **C#**: .NET Framework 4.8 (Revit 2017-2024), .NET 8.0 (Revit 2025+) |
| 25 | +- **Go**: Telemetry server (`dev/pyRevitTelemetryServer/`) |
| 26 | +- **Build Tools**: Visual Studio 2022, pipenv, MSBuild, Inno Setup |
| 27 | + |
| 28 | +## Build Commands |
| 29 | + |
| 30 | +All build commands use pipenv. Run from the repository root: |
| 31 | + |
| 32 | +```bash |
| 33 | +# Setup environment |
| 34 | +pipenv install |
| 35 | +pipenv run pyrevit check # Verify build environment |
| 36 | + |
| 37 | +# Build commands |
| 38 | +pipenv run pyrevit build products # Build all C# DLLs (Release mode) |
| 39 | +pipenv run pyrevit build products Debug # Build in Debug mode |
| 40 | +pipenv run pyrevit build labs # Build main project only |
| 41 | +pipenv run pyrevit build engines # Build Python engines |
| 42 | +pipenv run pyrevit build installers # Create Inno Setup installers |
| 43 | +pipenv run pyrevit build telem # Build telemetry server |
| 44 | + |
| 45 | +# Cleaning |
| 46 | +pipenv run pyrevit clean labs # Clean build artifacts |
| 47 | + |
| 48 | +# Version management |
| 49 | +pipenv run pyrevit set version <ver> # Set version number |
| 50 | +pipenv run pyrevit set build wip # Set as work-in-progress |
| 51 | +pipenv run pyrevit set build release # Set as release build |
| 52 | +``` |
| 53 | + |
| 54 | +## Documentation |
| 55 | + |
| 56 | +- Main website: https://pyrevitlabs.io/ |
| 57 | +- Technical docs: https://docs.pyrevitlabs.io/ (mkdocs, built from `docs/` folder) |
| 58 | + |
| 59 | +```bash |
| 60 | +pipenv run docs # Build documentation (mkdocs) |
| 61 | +pipenv run check-docstrings # Lint docstrings with ruff |
| 62 | +``` |
| 63 | + |
| 64 | +## Testing |
| 65 | + |
| 66 | +```bash |
| 67 | +# Test telemetry server (requires Docker) |
| 68 | +pipenv run pyrevit test telem |
| 69 | + |
| 70 | +# Python unit tests are in pyrevitlib/pyrevit/unittests/ |
| 71 | +# C# unit tests are in dev/pyRevitLabs/pyRevitLabs.UnitTests/ |
| 72 | +``` |
| 73 | + |
| 74 | +To test in Revit: |
| 75 | +```bash |
| 76 | +pyrevit clones add dev <path-to-repo> |
| 77 | +pyrevit attach dev default --installed |
| 78 | +``` |
| 79 | + |
| 80 | +## Development Workflow |
| 81 | + |
| 82 | +1. Fork and clone the repository |
| 83 | +2. Checkout `develop` branch (active development) |
| 84 | +3. Initialize submodules: `git submodule update --init --recursive` |
| 85 | +4. Install dependencies: `pipenv install` |
| 86 | +5. Build: `pipenv run pyrevit build products Debug` |
| 87 | +6. Test in Revit by attaching the clone |
| 88 | + |
| 89 | +For debugging C# code: |
| 90 | +1. Build in Debug mode |
| 91 | +2. Open the appropriate `.sln` file in Visual Studio |
| 92 | +3. Attach debugger to `revit.exe` process |
| 93 | + |
| 94 | +## Architecture Overview |
| 95 | + |
| 96 | +### Loading Sequence |
| 97 | +1. Revit reads `.addin` manifest from Addins folder |
| 98 | +2. Manifest points to `pyRevitLoader.dll` (C#) |
| 99 | +3. Loader launches `pyrevitloader.py` in IronPython |
| 100 | +4. Python script calls `pyrevit.loader.sessionmgr.load_session()` |
| 101 | +5. Extensions are discovered and UI is built |
| 102 | + |
| 103 | +### Key Components |
| 104 | +- **pyRevitLoader** (`dev/pyRevitLoader/`): Revit add-in entry point |
| 105 | +- **PyRevit.Runtime** (`dev/pyRevitLabs/pyRevitLabs.PyRevit.Runtime/`): Command execution |
| 106 | +- **pyrevitlib** (`pyrevitlib/pyrevit/`): Python API for scripts |
| 107 | +- **CLI** (`dev/pyRevitLabs/pyRevitLabs.PyRevit/`): Command-line management |
| 108 | + |
| 109 | +### Script Engines |
| 110 | +Located in `dev/pyRevitLabs/pyRevitLabs.PyRevit.Runtime/`: |
| 111 | +- `IronPythonEngine.cs` - Default Python engine |
| 112 | +- `CPythonEngine.cs` - Modern Python (3.12) |
| 113 | +- `CLREngine.cs` - C#/VB.NET execution |
| 114 | +- `DynamoBIMEngine.cs` - Dynamo graphs |
| 115 | +- `GrasshopperEngine.cs` - Grasshopper definitions |
| 116 | + |
| 117 | +## Extension Bundle Structure |
| 118 | + |
| 119 | +Extensions follow this hierarchy: |
| 120 | +``` |
| 121 | +MyExtension.extension/ |
| 122 | + MyTab.tab/ |
| 123 | + MyPanel.panel/ |
| 124 | + MyButton.pushbutton/ |
| 125 | + bundle.yaml # Button configuration |
| 126 | + script.py # Python script |
| 127 | + icon.png # Button icon |
| 128 | +``` |
| 129 | + |
| 130 | +Supported bundle types: pushbutton, smartbutton, pulldown, splitbutton, panelbutton |
| 131 | + |
| 132 | +## Key Configuration Files |
| 133 | + |
| 134 | +- `Pipfile` - Python dependencies (requires Python 3.10) |
| 135 | +- `pyRevitfile` - Engine definitions and deployment profiles |
| 136 | +- `pyproject.toml` - Ruff linting config (Google docstring convention) |
| 137 | +- `mkdocs.yml` - Documentation generation |
| 138 | +- `.gitmodules` - Git submodules for dependencies |
| 139 | + |
| 140 | +## Code Style |
| 141 | + |
| 142 | +- Python: Google docstring convention, formatted with black, linted with ruff |
| 143 | +- C#: Standard .NET conventions |
| 144 | + |
| 145 | +## Supported Revit Versions |
| 146 | + |
| 147 | +2017-2027, with separate builds per version: |
| 148 | +- Revit 2017-2024: .NET Framework 4.7.2/4.8 |
| 149 | +- Revit 2025+: .NET 8.0 |
| 150 | + |
| 151 | +## Git Workflow |
| 152 | + |
| 153 | +- `develop` branch: Active development (always start here) |
| 154 | +- `master` branch: Release material only |
| 155 | +- `docs` branch: Documentation website |
| 156 | +- Feature branches from `develop`, PRs back to `develop` |
| 157 | +- Run `git submodule update` after switching branches |
0 commit comments