Skip to content

Commit 909df83

Browse files
committed
Updated file system
1 parent edca24a commit 909df83

15 files changed

Lines changed: 157 additions & 14 deletions

.github/workflows/cd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ jobs:
2424
dotnet-version: 8.0.x
2525

2626
- name: Restore
27-
run: dotnet restore source/Revit.Extensions.csproj -p:Configuration=${{ matrix.configuration }}
27+
run: dotnet restore Revit.Extensions/Revit.Extensions.csproj -p:Configuration=${{ matrix.configuration }}
2828

2929
- name: Build
30-
run: dotnet build source/Revit.Extensions.csproj -p:Configuration=${{ matrix.configuration }} --no-restore
30+
run: dotnet build Revit.Extensions/Revit.Extensions.csproj -p:Configuration=${{ matrix.configuration }} --no-restore
3131

3232
- name: Pack
33-
run: dotnet pack source/Revit.Extensions.csproj -p:Configuration=${{ matrix.configuration }} --no-build --output ./nupkgs
33+
run: dotnet pack Revit.Extensions/Revit.Extensions.csproj -p:Configuration=${{ matrix.configuration }} --no-build --output ./nupkgs
3434

3535
- name: Push to NuGet
3636
run: dotnet nuget push "./nupkgs/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ jobs:
3030
dotnet-version: 8.0.x
3131

3232
- name: Restore
33-
run: dotnet restore tests/Revit.Extensions.Tests.csproj -p:Configuration=R${{ matrix.revit }}
33+
run: dotnet restore Revit.Extensions.Tests/Revit.Extensions.Tests.csproj -p:Configuration=R${{ matrix.revit }}
3434

3535
- name: Build
36-
run: dotnet build tests/Revit.Extensions.Tests.csproj -p:Configuration=R${{ matrix.revit }} --no-restore
36+
run: dotnet build Revit.Extensions.Tests/Revit.Extensions.Tests.csproj -p:Configuration=R${{ matrix.revit }} --no-restore
3737

3838
- name: Run tests
3939
run: >
40-
dotnet test "tests/bin/R${{ matrix.revit }}/Revit.Extensions.Tests.dll"
40+
dotnet test "Revit.Extensions.Tests/bin/R${{ matrix.revit }}/Revit.Extensions.Tests.dll"
4141
--logger "trx;LogFileName=results.trx"
4242
--results-directory "${{ github.workspace }}/TestResults/${{ matrix.revit }}"
4343

CLAUDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Revit.Extensions/
1212
├── .github/workflows/
1313
│ ├── ci.yml ← Build + test on every push / PR
1414
│ └── cd.yml ← Pack + publish NuGet on tag v*.*.*
15-
├── source/
15+
├── Revit.Extensions/
1616
│ ├── Revit.Extensions.csproj
1717
│ └── Extensions/
1818
│ ├── ElementExtensions.cs
1919
│ ├── GeometryExtensions.cs
2020
│ ├── PointExtensions.cs
2121
│ ├── DocumentExtensions.cs
2222
│ └── AsyncTasksExecutor.cs
23-
├── tests/
23+
├── Revit.Extensions.Tests/
2424
│ ├── Revit.Extensions.Tests.csproj
2525
│ └── Extensions/
2626
│ ├── GeometryExtensionsTests.cs
@@ -85,10 +85,10 @@ Example in `PointExtensions.cs`:
8585

8686
## Adding new extensions
8787

88-
1. Create `source/Extensions/MyExtensions.cs`
88+
1. Create `Revit.Extensions/Extensions/MyExtensions.cs`
8989
2. Use `namespace Revit.Extensions;`
9090
3. Mark class `public static`
91-
4. Add unit tests in `tests/Extensions/MyExtensionsTests.cs`
91+
4. Add unit tests in `Revit.Extensions.Tests/Extensions/MyExtensionsTests.cs`
9292

9393
## Notes
9494

README.md

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,140 @@
11
# Revit.Extensions
2-
The unofficial Extensions for Revit API
2+
3+
[![CI](https://github.com/apibim/Revit.Extensions/actions/workflows/ci.yml/badge.svg)](https://github.com/apibim/Revit.Extensions/actions/workflows/ci.yml)
4+
[![NuGet](https://img.shields.io/nuget/v/Revit.Extensions?color=blue)](https://www.nuget.org/packages/Revit.Extensions)
5+
[![NuGet Downloads](https://img.shields.io/nuget/dt/Revit.Extensions)](https://www.nuget.org/packages/Revit.Extensions)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7+
8+
A collection of extension methods for the **Autodesk Revit API**, designed to reduce boilerplate and make Revit add-in development more expressive. Supports **Revit 2020 – 2027**.
9+
10+
---
11+
12+
## Installation
13+
14+
```
15+
dotnet add package Revit.Extensions
16+
```
17+
18+
Or search for **`Revit.Extensions`** in the NuGet Package Manager inside Visual Studio.
19+
20+
---
21+
22+
## Revit version support
23+
24+
| Revit | Target framework | NuGet version |
25+
| ----- | ---------------- | ------------- |
26+
| 2020 | net47 | 2020.0.\* |
27+
| 2021 | net48 | 2021.0.\* |
28+
| 2022 | net48 | 2022.0.\* |
29+
| 2023 | net48 | 2023.0.\* |
30+
| 2024 | net48 | 2024.0.\* |
31+
| 2025 | net8.0-windows | 2025.0.\* |
32+
| 2026 | net8.0-windows | 2026.0.\* |
33+
| 2027 | net8.0-windows | 2027.0.\* |
34+
35+
The package automatically targets the correct framework — no manual configuration needed.
36+
37+
---
38+
39+
## API reference
40+
41+
### `GeometryExtensions`
42+
43+
Helpers for working with Revit geometry types (`XYZ`, `Outline`, `BoundingBoxXYZ`).
44+
45+
```csharp
46+
using Revit.Extensions;
47+
48+
// Convert XYZ ↔ value tuple
49+
XYZ point = new XYZ(1.0, 2.0, 3.0);
50+
(double X, double Y, double Z) vec = point.ToVector(); // (1.0, 2.0, 3.0)
51+
XYZ restored = vec.ToXYZ(); // XYZ(1.0, 2.0, 3.0)
52+
53+
// Expand an Outline uniformly (default: 10 ft)
54+
Outline outline = new Outline(new XYZ(0, 0, 0), new XYZ(5, 5, 5));
55+
Outline expanded = outline.Extend(size: 2); // min −2, max +2 in every axis
56+
57+
// Transform a BoundingBoxXYZ from local to world space
58+
BoundingBoxXYZ bbox = element.get_BoundingBox(view);
59+
BoundingBoxXYZ? worldBbox = bbox.TransformBoundingBox();
60+
```
61+
62+
---
63+
64+
### `PointExtensions`
65+
66+
Unit conversion for `XYZ` coordinates using Revit's `UnitUtils`.
67+
68+
```csharp
69+
using Autodesk.Revit.DB;
70+
using Revit.Extensions;
71+
72+
// Revit stores coordinates in feet internally.
73+
// Convert a point to meters (Revit 2021+):
74+
XYZ pointInFeet = new XYZ(3.28084, 0, 0);
75+
XYZ pointInMeters = pointInFeet.Recalculate(UnitTypeId.Meters);
76+
// → XYZ(1.0, 0, 0)
77+
```
78+
79+
> **Revit 2020** uses the legacy `DisplayUnitType` enum — the overload is selected automatically via conditional compilation.
80+
81+
---
82+
83+
### `ElementExtensions`
84+
85+
Helpers for collecting elements and grids from the active document.
86+
87+
```csharp
88+
using Revit.Extensions;
89+
90+
// Collect selected elements, or fall back to all FamilyInstances + HostObjects in the active view
91+
IList<Element> elements = ElementExtensions.GetAllElementOrSelected(uiDocument);
92+
93+
// Get all grids from the level closest to elevation 0
94+
IList<Grid> grids = ElementExtensions.GetAllGridFromFirstLevel(document, out string? levelName);
95+
if (levelName is not null)
96+
TaskDialog.Show("Grids", $"Found {grids.Count} grids on level '{levelName}'.");
97+
```
98+
99+
---
100+
101+
### `AsyncTasksExecutor`
102+
103+
Run async code synchronously inside the Revit event loop, where `async/await` on the main thread is unsupported.
104+
105+
```csharp
106+
using Revit.Extensions;
107+
108+
// Execute a Task<T> synchronously
109+
string result = AsyncTasksExecutor.Execute(async () =>
110+
{
111+
await Task.Delay(100);
112+
return "done";
113+
});
114+
115+
// Execute a ValueTask<T> synchronously
116+
int value = AsyncTasksExecutor.Execute(async () =>
117+
{
118+
await Task.Yield();
119+
return 42;
120+
});
121+
```
122+
123+
---
124+
125+
## Contributing
126+
127+
Contributions are welcome! Please open an issue or submit a pull request.
128+
129+
1. Fork the repository
130+
2. Create a feature branch: `git checkout -b feature/my-extension`
131+
3. Add your extension in `Revit.Extensions/Extensions/` with a corresponding test in `tests/Extensions/`
132+
4. Open a pull request against `main`
133+
134+
See [CLAUDE.md](CLAUDE.md) for build commands and project conventions.
135+
136+
---
137+
138+
## License
139+
140+
MIT © [Apibim SpA](https://apibim.com)
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/Revit.Extensions.Tests.csproj renamed to Revit.Extensions.Tests/Revit.Extensions.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<ProjectReference Include="..\source\Revit.Extensions.csproj" />
15+
<ProjectReference Include="..\Revit.Extensions\Revit.Extensions.csproj" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

Revit.Extensions.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "source", "source", "{B8EFCA5F-814F-285C-A8CB-F00F14650265}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Revit.Extensions", "source\Revit.Extensions.csproj", "{C5E9459C-38FB-4F95-98BD-FFBB9B075D7A}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Revit.Extensions", "Revit.Extensions\Revit.Extensions.csproj", "{C5E9459C-38FB-4F95-98BD-FFBB9B075D7A}"
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Revit.Extensions.Tests", "tests\Revit.Extensions.Tests.csproj", "{18101238-64C3-4441-9B9B-04590F5286DE}"
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Revit.Extensions.Tests", "Revit.Extensions.Tests\Revit.Extensions.Tests.csproj", "{18101238-64C3-4441-9B9B-04590F5286DE}"
1313
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
File renamed without changes.

0 commit comments

Comments
 (0)