Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

fix(revit): guard against null Zone in space send and receive - #3725

Open
MayconAlvesss wants to merge 1 commit into
specklesystems:mainfrom
MayconAlvesss:fix/revit-space-null-zone-3524
Open

MayconAlvesss wants to merge 1 commit into
specklesystems:mainfrom
MayconAlvesss:fix/revit-space-null-zone-3524

Conversation

@MayconAlvesss

Copy link
Copy Markdown

What does this PR do?

Resolves a two-part bug that caused the Revit connector to fail when receiving spaces that have no zone assigned.

Closes #3524

Root cause

Space.Zone returns null from the Revit API when a space is not assigned to any zone. The converter had two unguarded references to this property:

1. On send (SpaceToSpeckle)

// Before: NullReferenceException when Space.Zone is null
speckleSpace.zone = cache.GetOrAdd(revitSpace.Zone.Name, ...);

If revitSpace.Zone is null, accessing .Name throws immediately and the whole send operation fails.

2. On receive (SpaceToNative)
The zone association block ran unconditionally. When the incoming speckleSpace.zone was null (correctly serialized after this fix, or received from another host app without zone data), CreateRevitZoneIfNeeded returned the Revit document's internal default zone object. The connector then attempted AddSpaces on it, which triggered an API error — and in the error recovery path, the existing spaces were deleted instead of updated.

Changes

  • ConvertSpace.cs — SpaceToSpeckle: wrapped the cache/serialize call in a null guard so spaces without a zone serialize with zone = null rather than throwing.
  • ConvertSpace.cs — SpaceToNative: moved the entire zone-association block inside a speckleSpace.zone != null check. When no zone was intended, the connector leaves the space's zone state untouched.

Testing

Manually traced through the execution path with a Space mock where Zone is null. The updated logic skips the zone block cleanly in both directions. No changes to the happy path (spaces with zones) — the logic is structurally identical to before for those cases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revit connector does not import spaces when the zone of space is null

1 participant