pi-revit 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +394 -351
- package/README.md +438 -25
- package/bin/pi-revit.js +3 -5
- package/extensions/pi-revit/index.ts +151 -92
- package/extensions/pi-revit/instance-router.ts +86 -0
- package/extensions/pi-revit/script-library.ts +146 -0
- package/extensions/pi-revit/tool-catalog.ts +67 -0
- package/package.json +58 -57
- package/scripts/build.ps1 +9 -3
- package/scripts/check-sdk.ps1 +66 -0
- package/scripts/deploy.ps1 +16 -4
- package/skills/pi-revit/SKILL.md +181 -17
- package/skills/pi-revit/references/model-audit-export.md +29 -0
- package/skills/pi-revit/references/room-documentation.md +28 -0
- package/src/Revit/BridgeServer.cs +79 -29
- package/src/Revit/OperationStore.cs +178 -0
- package/src/Revit/ToolRegistry.cs +26 -4
- package/src/Revit/Tools/CaptureView.cs +2 -1
- package/src/Revit/Tools/ChangeElementTypes.cs +60 -0
- package/src/Revit/Tools/CreateTags.cs +95 -0
- package/src/Revit/Tools/DeleteElements.cs +44 -0
- package/src/Revit/Tools/DocumentGuard.cs +2 -2
- package/src/Revit/Tools/ElementQueryScope.cs +27 -0
- package/src/Revit/Tools/ExecuteCsharp.cs +23 -13
- package/src/Revit/Tools/ExportDocuments.cs +2 -1
- package/src/Revit/Tools/GetElementDetails.cs +32 -2
- package/src/Revit/Tools/GetElementRelationships.cs +76 -0
- package/src/Revit/Tools/GetElements.cs +21 -7
- package/src/Revit/Tools/GetLinkedElements.cs +82 -0
- package/src/Revit/Tools/GetLinkedModels.cs +66 -0
- package/src/Revit/Tools/GetModelCoordinates.cs +49 -0
- package/src/Revit/Tools/GetScheduleFields.cs +37 -0
- package/src/Revit/Tools/GetSchedules.cs +89 -0
- package/src/Revit/Tools/ManageElementSets.cs +106 -0
- package/src/Revit/Tools/ManageSchedules.cs +164 -0
- package/src/Revit/Tools/ManageSelection.cs +2 -1
- package/src/Revit/Tools/ManageSheetPlacements.cs +97 -0
- package/src/Revit/Tools/ManageSheets.cs +63 -0
- package/src/Revit/Tools/ManageViews.cs +100 -0
- package/src/Revit/Tools/MeasureGeometry.cs +54 -0
- package/src/Revit/Tools/ModelEditBatch.cs +102 -0
- package/src/Revit/Tools/ModelEditInputs.cs +49 -0
- package/src/Revit/Tools/OpenView.cs +2 -1
- package/src/Revit/Tools/QuerySpatialElements.cs +63 -0
- package/src/Revit/Tools/SetParameters.cs +43 -93
- package/src/Revit/Tools/SpatialBounds.cs +30 -0
- package/src/Revit/Tools/SummarizeElements.cs +87 -0
- package/src/Revit/Tools/TransformElements.cs +58 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
using System.Text.Json.Nodes;
|
|
3
|
+
|
|
4
|
+
namespace RevitBridge.Tools;
|
|
5
|
+
|
|
6
|
+
internal sealed class SummarizeElements : ITool
|
|
7
|
+
{
|
|
8
|
+
private const int MaxElements = 10000;
|
|
9
|
+
public string Name => "summarize_elements";
|
|
10
|
+
public string Label => "Summarize Elements";
|
|
11
|
+
public string Tier => "advanced";
|
|
12
|
+
public string Description => "Count matching host-model elements grouped by category, type, level or one parameter value. Accepts get_elements category/class/level/type/filter scopes. At most 10,000 matches; narrow larger queries. Parameter grouping uses exact raw values, with a distinct missing-value group. Ambiguous display-name parameters are rejected. Counts cover the entire matching scope, not just the returned groups page.";
|
|
13
|
+
public object ParametersSchema
|
|
14
|
+
{
|
|
15
|
+
get
|
|
16
|
+
{
|
|
17
|
+
var query = ElementQueryScope.Schema();
|
|
18
|
+
return new
|
|
19
|
+
{
|
|
20
|
+
type = "object",
|
|
21
|
+
properties = new
|
|
22
|
+
{
|
|
23
|
+
query,
|
|
24
|
+
group_by = new { type = "string", @enum = new[] { "category", "typeName", "levelId", "parameter" } },
|
|
25
|
+
parameter = new { type = "string", description = "Required for group_by=parameter. Name, built-in identity or guid:<GUID>." },
|
|
26
|
+
type_parameter = new { type = "boolean", description = "Group by the parameter on the element type instead of the instance." },
|
|
27
|
+
offset = new { type = "integer", minimum = 0 },
|
|
28
|
+
limit = new { type = "integer", minimum = 1, maximum = 500 },
|
|
29
|
+
},
|
|
30
|
+
required = new[] { "group_by" },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public object Execute(JsonElement args, ToolContext context)
|
|
36
|
+
{
|
|
37
|
+
string groupBy = JsonArgs.GetString(args, "group_by") ?? "";
|
|
38
|
+
if (groupBy is not ("category" or "typeName" or "levelId" or "parameter")) throw new ArgumentException("Unknown group_by value.");
|
|
39
|
+
string? parameter = JsonArgs.GetString(args, "parameter");
|
|
40
|
+
if (groupBy == "parameter" && string.IsNullOrWhiteSpace(parameter)) throw new ArgumentException("parameter is required for parameter grouping.");
|
|
41
|
+
bool typeParameter = JsonArgs.GetBool(args, "type_parameter", false);
|
|
42
|
+
var query = ElementQueryScope.Parse(args);
|
|
43
|
+
JsonElement RunQuery() => JsonSerializer.SerializeToElement(((ToolOutput)new GetElements().Execute(JsonSerializer.SerializeToElement(query), context)!).Payload);
|
|
44
|
+
query["count_only"] = true;
|
|
45
|
+
var countResult = RunQuery();
|
|
46
|
+
int total = countResult.GetProperty("total_count").GetInt32();
|
|
47
|
+
object? warnings = countResult.TryGetProperty("warnings", out var queryWarnings) ? queryWarnings.Clone() : null;
|
|
48
|
+
if (total > MaxElements) throw new ArgumentException($"Query matches {total} elements; narrow the scope to at most {MaxElements}.");
|
|
49
|
+
query["count_only"] = false;
|
|
50
|
+
query["limit"] = 1000;
|
|
51
|
+
if (groupBy == "parameter")
|
|
52
|
+
{
|
|
53
|
+
query["parameter_names"] = new JsonArray(parameter);
|
|
54
|
+
query["include_type_parameters"] = typeParameter;
|
|
55
|
+
}
|
|
56
|
+
var counts = new Dictionary<string, (object? Value, bool Missing, int Count)>();
|
|
57
|
+
for (int position = 0; position < total; position += 1000)
|
|
58
|
+
{
|
|
59
|
+
query["offset"] = position;
|
|
60
|
+
foreach (var row in RunQuery().GetProperty("elements").EnumerateArray())
|
|
61
|
+
{
|
|
62
|
+
object? value = null;
|
|
63
|
+
bool missing = false;
|
|
64
|
+
if (groupBy == "parameter")
|
|
65
|
+
{
|
|
66
|
+
var projection = row.GetProperty("parameters").EnumerateArray().FirstOrDefault(p => p.GetProperty("isType").GetBoolean() == typeParameter);
|
|
67
|
+
missing = projection.ValueKind == JsonValueKind.Undefined || !projection.GetProperty("found").GetBoolean();
|
|
68
|
+
if (!missing)
|
|
69
|
+
{
|
|
70
|
+
if (projection.GetProperty("ambiguous").GetBoolean()) throw new ArgumentException($"Parameter '{parameter}' is ambiguous on element {row.GetProperty("id")}; use a built-in identity or shared GUID.");
|
|
71
|
+
value = projection.GetProperty("matches")[0].GetProperty("value").Clone();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (row.TryGetProperty(groupBy, out var field)) value = field.Clone();
|
|
75
|
+
string key = (missing ? "missing:" : "value:") + JsonSerializer.Serialize(value);
|
|
76
|
+
counts[key] = counts.TryGetValue(key, out var previous) ? (value, missing, previous.Count + 1) : (value, missing, 1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
int offset = Math.Max(0, JsonArgs.GetInt(args, "offset", 0));
|
|
80
|
+
int limit = Math.Clamp(JsonArgs.GetInt(args, "limit", 100), 1, 500);
|
|
81
|
+
var groups = counts.OrderByDescending(pair => pair.Value.Count).ThenBy(pair => pair.Key, StringComparer.Ordinal).Skip(offset).Take(limit)
|
|
82
|
+
.Select(pair => new { value = pair.Value.Value, missing = pair.Value.Missing, count = pair.Value.Count }).ToArray();
|
|
83
|
+
return new { total_elements = total, total_groups = counts.Count, group_by = groupBy, parameter, type_parameter = typeParameter,
|
|
84
|
+
numeric_values = "Revit internal units", warnings, offset, returned_count = groups.Length,
|
|
85
|
+
next_offset = offset + groups.Length < counts.Count ? (int?)(offset + groups.Length) : null, groups };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
using System.Text.Json;
|
|
2
|
+
using Autodesk.Revit.DB;
|
|
3
|
+
|
|
4
|
+
namespace RevitBridge.Tools;
|
|
5
|
+
|
|
6
|
+
internal sealed class TransformElements : ITool
|
|
7
|
+
{
|
|
8
|
+
public string Name => "transform_elements";
|
|
9
|
+
public string Label => "Transform Elements";
|
|
10
|
+
public string Tier => "advanced";
|
|
11
|
+
public bool Write => true;
|
|
12
|
+
public string Description => "Move, copy or rotate 1–200 elements together in the active document. Coordinates use the document internal origin and axes; unit is required. Rotation uses a right-handed axis and angle_degrees. The whole selection succeeds or rolls back as one step; pinned elements are never automatically unpinned. Revit may move constrained/hosted dependents too. preview=true validates commit then rolls back; any created IDs in a preview are temporary and must not be reused. Snapshots describe requested elements, not a complete dependent-change audit.";
|
|
13
|
+
public object ParametersSchema => new
|
|
14
|
+
{
|
|
15
|
+
type = "object", properties = new
|
|
16
|
+
{
|
|
17
|
+
action = new { type = "string", @enum = new[] { "move", "copy", "rotate" } },
|
|
18
|
+
element_ids = ModelEditInputs.IdsSchema,
|
|
19
|
+
unit = ModelEditInputs.LengthUnitSchema,
|
|
20
|
+
translation = ModelEditInputs.VectorSchema("Move/copy displacement [x,y,z] in unit."),
|
|
21
|
+
axis_origin = ModelEditInputs.VectorSchema("Rotation axis origin [x,y,z] in unit, relative to internal origin."),
|
|
22
|
+
axis_direction = ModelEditInputs.VectorSchema("Nonzero rotation axis direction [x,y,z], dimensionless."),
|
|
23
|
+
angle_degrees = new { type = "number", description = "Signed right-hand rotation angle in degrees." },
|
|
24
|
+
preview = ModelEditInputs.PreviewSchema,
|
|
25
|
+
}, required = new[] { "action", "element_ids", "unit" },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
public object Execute(JsonElement args, ToolContext context)
|
|
29
|
+
{
|
|
30
|
+
var doc = context.Document ?? throw new NoActiveDocumentException();
|
|
31
|
+
var ids = ModelEditInputs.Ids(args);
|
|
32
|
+
string action = JsonArgs.GetString(args, "action") ?? "";
|
|
33
|
+
if (action is not ("move" or "copy" or "rotate")) throw new ArgumentException("action must be move, copy or rotate.");
|
|
34
|
+
double scale = ModelEditInputs.LengthScale(args);
|
|
35
|
+
XYZ? translation = action != "rotate" ? ModelEditInputs.Vector(args, "translation").Multiply(scale) : null;
|
|
36
|
+
XYZ? origin = action == "rotate" ? ModelEditInputs.Vector(args, "axis_origin").Multiply(scale) : null;
|
|
37
|
+
XYZ? direction = action == "rotate" ? ModelEditInputs.Vector(args, "axis_direction") : null;
|
|
38
|
+
double angle = action == "rotate" ? ModelEditInputs.Number(args, "angle_degrees") * Math.PI / 180 : 0;
|
|
39
|
+
if (direction != null && direction.GetLength() < 1e-12) throw new ArgumentException("axis_direction must be nonzero.");
|
|
40
|
+
var result = ModelEditBatch.Run(doc, Name, args, new[] { new ModelEditBatch.Step(
|
|
41
|
+
new() { ["action"] = action, ["element_ids"] = ids.Select(x => x.Value).ToArray() }, () =>
|
|
42
|
+
{
|
|
43
|
+
var elements = ids.Select(id => doc.GetElement(id) ?? throw new ArgumentException($"Element {id.Value} not found.")).ToArray();
|
|
44
|
+
if (action != "copy" && elements.Any(e => e.Pinned)) throw new ArgumentException("Selection contains pinned elements; no elements were unpinned.");
|
|
45
|
+
var before = elements.Select(ModelEditInputs.Snapshot).ToArray();
|
|
46
|
+
ICollection<ElementId> outputIds = ids;
|
|
47
|
+
if (action == "move") ElementTransformUtils.MoveElements(doc, ids, translation!);
|
|
48
|
+
else if (action == "copy") outputIds = ElementTransformUtils.CopyElements(doc, ids, translation!);
|
|
49
|
+
else ElementTransformUtils.RotateElements(doc, ids, Line.CreateUnbound(origin!, direction!.Normalize()), angle);
|
|
50
|
+
doc.Regenerate();
|
|
51
|
+
return new() { ["before"] = before, ["after"] = outputIds.Select(doc.GetElement).Where(e => e != null).Select(ModelEditInputs.Snapshot).ToArray(),
|
|
52
|
+
["created_ids"] = action == "copy" ? outputIds.Select(id => id.Value).ToArray() : Array.Empty<long>(),
|
|
53
|
+
["coordinate_system"] = "document_internal", ["snapshot_unit"] = "feet",
|
|
54
|
+
["created_ids_are_temporary"] = action == "copy" && JsonArgs.GetBool(args, "preview", false) };
|
|
55
|
+
}) });
|
|
56
|
+
return result.Payload;
|
|
57
|
+
}
|
|
58
|
+
}
|