Skip to content

Commit 96b98df

Browse files
authored
Merge pull request #2 from Apibim-com/feature/new_api
New Extension Methods. First version of the package
2 parents 813817b + 22db4c6 commit 96b98df

32 files changed

Lines changed: 3737 additions & 56 deletions

.github/workflows/cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: CD
22

33
on:
44
push:
5-
tags:
6-
- "v*.*.*"
5+
branches:
6+
- main
77

88
jobs:
99
pack-and-publish:

CLAUDE.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,76 @@ Example in `PointExtensions.cs`:
9696
- `PointExtensions` tests require a live Revit process — marked `[Fact(Skip = ...)]`.
9797
- `ElementExtensions` tests require `Document`/`UIDocument` — use Moq or test inside Revit.
9898
- Revit API package: `Revit_All_Main_Versions_API_x64` from nuget.org, versioned by `$(RevitVersion).*`.
99+
100+
## DrawSession — transient geometry via DirectContext3D
101+
102+
`DrawSession` renders geometry directly into the Revit graphics pipeline without creating model elements and without requiring a `Transaction`.
103+
104+
### Registration (critical)
105+
106+
Registration **must** happen in `IExternalApplication.OnStartup` using `RegisterDrawSession()`:
107+
108+
```csharp
109+
// App.cs
110+
public static DrawSession? ActiveDrawSession { get; private set; }
111+
112+
public Result OnStartup(UIControlledApplication application)
113+
{
114+
ActiveDrawSession = application.RegisterDrawSession(); // one line
115+
// ...
116+
}
117+
118+
public Result OnShutdown(UIControlledApplication application)
119+
{
120+
ActiveDrawSession?.Dispose();
121+
ActiveDrawSession = null;
122+
return Result.Succeeded;
123+
}
124+
```
125+
126+
`RegisterDrawSession()` is an extension on `UIControlledApplication` in `UIControlledApplicationExtensions.cs`. Internally it:
127+
1. Calls `service.AddServer(session)` first
128+
2. Calls `service.GetActiveServerIds()` **after** AddServer (per Revit API docs)
129+
3. Checks `Contains` before adding to avoid duplicates
130+
131+
`DrawSession` does **NOT** auto-register in its constructor — registration must be explicit.
132+
133+
### UIApplication for view refresh
134+
135+
`DrawSession` needs `UIApplication` to call `RefreshActiveView()` after drawing. Supply it via `SetUIApplication()` from the first command:
136+
137+
```csharp
138+
App.ActiveDrawSession?.SetUIApplication(commandData.Application);
139+
```
140+
141+
### Fluent drawing API
142+
143+
```csharp
144+
session
145+
.DrawLine(from, to, DrawExtensions.Blue)
146+
.DrawCross(center, radius: 0.5, DrawExtensions.Red)
147+
.DrawPoint(center, radius: 0.3, DrawExtensions.Green)
148+
.DrawPolygon(new[] { p0, p1, p2 }, DrawExtensions.Orange)
149+
.DrawBoundingBox(bbox, DrawExtensions.Cyan);
150+
151+
session.Clear(); // remove all geometry (session stays registered)
152+
session.Dispose(); // unregister and release GPU buffers
153+
```
154+
155+
### Known bugs fixed
156+
157+
- `VertexBuffer.Map(0)` and `IndexBuffer.Map(0)``Map()` takes **size in floats/shorts**, not an offset. Passing 0 maps nothing → no vertices written → geometry invisible. Fixed to pass actual buffer sizes.
158+
- Auto-registration in constructor caused double-registration when App.cs also registered manually. Removed auto-registration; use `RegisterDrawSession()` instead.
159+
160+
### CanExecute conditions
161+
162+
`DrawSession.CanExecute(view)` returns `true` only when:
163+
- Session is not disposed
164+
- At least one line has been added (`_lines.Count > 0`)
165+
- The view is a `View3D`
166+
167+
### Threading
168+
169+
- `_lines` list and `Invalidate()` → main/UI thread only
170+
- `GetBoundingBox()` → may be called from render thread → reads `_cachedOutline` (volatile)
171+
- `RenderScene()` → render thread → calls `RebuildBuffers()` when `_isDirty`

0 commit comments

Comments
 (0)