pi-revit 0.2.15 → 0.2.17

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 CHANGED
@@ -7,6 +7,39 @@ Format follows [Keep a Changelog](https://keepachangelog.com/); version headers
7
7
  Every published version gets an entry with **Added** / **Changed** / **Fixed** sections
8
8
  describing what the user will notice — not internal refactors.
9
9
 
10
+ ## [0.2.17] - 2026-08-21
11
+
12
+ ### Fixed
13
+ - The bridge's no-document check no longer counts linked documents. With only links
14
+ loaded, Revit does not pump the bridge's work queue, so a call could wait out its full
15
+ timeout instead of failing immediately with the clean "no active document" answer.
16
+
17
+ ### Changed
18
+ - Docs and tool descriptions describe localized parameter names generically instead of
19
+ quoting specific languages.
20
+ - The full search_api_docs benchmark (641 live queries against RevitAPI.xml ground truth)
21
+ was re-run on Revit 2025 at 0.2.16: 100% recall, 98.75% top-1 on exact names, 100%
22
+ spacing-variant agreement, 0 false positives across 99 adversarial mutations, 50/50
23
+ parameter docs, p50 10 ms -- no regression across the 0.2.13-0.2.16 search changes.
24
+
25
+ Requires redeploying the Revit add-in (`scripts\deploy.ps1` with Revit closed, then
26
+ restart Revit).
27
+
28
+ ## [0.2.16] - 2026-08-21
29
+
30
+ ### Fixed
31
+ - `search_api_docs`: an accessor-spelling query combined with `kind: "method"` — e.g.
32
+ `Element.get_Parameter(BuiltInParameter)` filtered to methods — returned "no matches",
33
+ because the accessor rewrite found the documented member but the kind filter rejected it:
34
+ a C# `get_X`/`set_X` accessor is a method to the caller, while the XML documents the
35
+ underlying member as a property or indexer. For accessor-rewritten candidates the
36
+ `method` filter now also admits properties, and the result note says so. Found by an
37
+ agent under a stress test that filtered its doc query to methods. Two benchmark probes
38
+ added (the widening plus a real-method control).
39
+
40
+ Requires redeploying the Revit add-in (`scripts\deploy.ps1` with Revit closed, then
41
+ restart Revit).
42
+
10
43
  ## [0.2.15] - 2026-08-21
11
44
 
12
45
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-revit",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "description": "Native Pi connector for Autodesk Revit. Run npx.cmd -y pi-revit for the full Windows install.",
5
5
  "author": "Ahmad Altahlawi",
6
6
  "license": "MIT",
@@ -26,7 +26,8 @@
26
26
  "scripts": {
27
27
  "deploy": "powershell -ExecutionPolicy Bypass -File scripts/deploy.ps1",
28
28
  "setup": "powershell -ExecutionPolicy Bypass -File scripts/setup-workspace.ps1",
29
- "uninstall:revit": "powershell -ExecutionPolicy Bypass -File scripts/uninstall.ps1"
29
+ "uninstall:revit": "powershell -ExecutionPolicy Bypass -File scripts/uninstall.ps1",
30
+ "test:search": "dotnet run --project tests/search-engine"
30
31
  },
31
32
  "files": [
32
33
  "bin/",
@@ -31,8 +31,10 @@ else:
31
31
  XML_PATH = candidates[-1]
32
32
 
33
33
  LAT = []
34
- def search(query, max_results=10):
35
- body = json.dumps({"query": query, "max_results": max_results}).encode("utf-8")
34
+ def search(query, max_results=10, kind=None):
35
+ args = {"query": query, "max_results": max_results}
36
+ if kind: args["kind"] = kind
37
+ body = json.dumps(args).encode("utf-8")
36
38
  url = f"{BASE}/tools/search_api_docs/execute?token={TOKEN}&timeout_ms=60000"
37
39
  req = urllib.request.Request(url, data=body, headers={"content-type": "application/json"}, method="POST")
38
40
  t0 = time.perf_counter()
@@ -180,8 +182,8 @@ R["B signature+spacing"] = B
180
182
 
181
183
  # --------------------------------------------------------- C: complex syntax shapes
182
184
  C = {"cases": []}
183
- def probe(label, q, expect_nonzero=True):
184
- try: matches, total = search(q)
185
+ def probe(label, q, expect_nonzero=True, kind=None):
186
+ try: matches, total = search(q, kind=kind)
185
187
  except Exception as e:
186
188
  C["cases"].append((label, q, f"ERROR {e}")); return
187
189
  ok = (total > 0) if expect_nonzero else (total == 0)
@@ -213,6 +215,9 @@ probe("factory honesty control", "Document.Create.Banana", expect_nonzero=False)
213
215
  probe("accessor indexer", "Element.get_Parameter(BuiltInParameter")
214
216
  probe("accessor property", "Element.get_BoundingBox(View")
215
217
  probe("literal get_ member", "LocationCurve.get_ElementsAtJoin")
218
+ # 0.2.16: kind=method on an accessor query admits the documented property
219
+ probe("accessor with kind=method", "Element.get_Parameter(BuiltInParameter", kind="method")
220
+ probe("kind=method control (real method)", "Wall.Create(Document, Curve", kind="method")
216
221
  print("C done", flush=True)
217
222
  R["C complex-syntax"] = C
218
223
 
@@ -31,7 +31,7 @@ Workflow guidance:
31
31
  - `get_elements` is the listing/counting primitive (`count_only: true` for bare counts). It returns identity fields only (id, name, category, typeName, levelId); read parameter values with `get_element_details`. Prefer a `category` or `of_class` scope when filtering by a parameter's display name.
32
32
  - The selection pipeline is `get_elements` -> ids -> `manage_selection` (action `set`); there is no inline filter on selection.
33
33
  - `set_parameters` is the home for bulk parameter writes AND renames (the `Name` parameter covers levels, views, sheets, types). One transaction per batch; per-element failures are reported. Pass `expected_document` (the model title) when several models are open or the session is long — it makes the write fail cleanly instead of landing in a different active document.
34
- - Parameter display names are LOCALIZED: in a non-English Revit UI, `Mark` is `Kennzeichen` (German), `マーク` (Japanese), etc. When a display-name lookup or `parameter_names` filter finds nothing, or the document may be non-English, use the language-independent `BuiltInParameter` enum name instead (e.g. `ALL_MODEL_MARK` for Mark, `ALL_MODEL_INSTANCE_COMMENTS` for Comments) — `set_parameters`, `get_element_details.parameter_names`, and `get_elements` filter rules all accept them, and `get_element_details` reports each parameter's `builtInParameter` name for discovery.
34
+ - Parameter display names are LOCALIZED: in a non-English Revit UI, `Mark`, `Comments`, and every other display name appear under their translated names. When a display-name lookup or `parameter_names` filter finds nothing, or the document may be non-English, use the language-independent `BuiltInParameter` enum name instead (e.g. `ALL_MODEL_MARK` for Mark, `ALL_MODEL_INSTANCE_COMMENTS` for Comments) — `set_parameters`, `get_element_details.parameter_names`, and `get_elements` filter rules all accept them, and `get_element_details` reports each parameter's `builtInParameter` name for discovery.
35
35
  - Before writing `execute_csharp` code, verify unfamiliar classes/members with `search_api_docs` (works with no document open; first query builds the index and takes a few seconds). The top match carries its remarks, parameter docs, and returns inline, and every public API enum value is searchable — trust the result over guessing or web search; narrow the query to promote a different match into the top slot.
36
36
  - `export_documents` files its output under `Documents\pi-revit\Models\<model title>\exports` automatically when `output_dir` is omitted — keyed to the exported document, so it lands right even across many models. Pass `output_dir` only when the user names a different target.
37
37
 
@@ -1,3 +1,4 @@
1
+ using Autodesk.Revit.DB;
1
2
  using Autodesk.Revit.UI;
2
3
  using RevitApplication = Autodesk.Revit.ApplicationServices.Application;
3
4
 
@@ -67,7 +68,32 @@ namespace RevitBridge
67
68
  {
68
69
  if (sender is RevitApplication app)
69
70
  _application = app;
70
- _hasOpenDocument = (_application?.Documents?.Size ?? 0) > 0;
71
+ try
72
+ {
73
+ // Linked documents count in Documents but are never the active UI
74
+ // document -- with only links loaded, ExternalEvents still are not
75
+ // pumped, so counting them would let a queued call hang for its full
76
+ // timeout instead of failing fast with the 409.
77
+ bool any = false;
78
+ var documents = _application?.Documents;
79
+ if (documents != null)
80
+ {
81
+ foreach (Document document in documents)
82
+ {
83
+ if (!document.IsLinked)
84
+ {
85
+ any = true;
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ _hasOpenDocument = any;
91
+ }
92
+ catch
93
+ {
94
+ // Transitional states (mid-close) can make the iteration throw; keep
95
+ // the last known value -- the in-queue backstop still catches a miss.
96
+ }
71
97
  }
72
98
 
73
99
  private static string StartupErrorPath() =>
@@ -27,7 +27,7 @@ namespace RevitBridge.Tools
27
27
  {
28
28
  type = "array",
29
29
  items = new { type = "string" },
30
- description = "Only return these parameters. Matches the display name OR the BuiltInParameter enum name (case-insensitive exact). Display names are localized (e.g. 'Mark' is 'Kennzeichen' in a German UI) — prefer enum names like ALL_MODEL_MARK for language-independent filtering. Default: all.",
30
+ description = "Only return these parameters. Matches the display name OR the BuiltInParameter enum name (case-insensitive exact). Display names are localized in non-English Revit UIs — prefer enum names like ALL_MODEL_MARK for language-independent filtering. Default: all.",
31
31
  },
32
32
  include = new
33
33
  {
@@ -142,17 +142,17 @@ namespace RevitBridge.Tools
142
142
  // member, before giving up. Deterministic rewrites of an exact idiom — never
143
143
  // applied unless the literal 'document.create.' / 'application.create.' prefix
144
144
  // is present, so ordinary names like Wall.Create are untouched.
145
- var candidates = new List<(string Query, string? Note)> { (q, null) };
145
+ var candidates = new List<(string Query, string? Note, bool AccessorRewrite)> { (q, null, false) };
146
146
  foreach (string factory in new[] { "document.create.", "application.create." })
147
147
  {
148
148
  if (!q.StartsWith(factory, StringComparison.Ordinal))
149
149
  continue;
150
150
  string owner = factory[..(factory.IndexOf('.') + 1)]; // "document."
151
151
  string rest = q[factory.Length..];
152
- candidates.Add((owner + rest, $"'{owner}Create.*' is the Creation factory — matched as '{owner}{rest}'."));
152
+ candidates.Add((owner + rest, $"'{owner}Create.*' is the Creation factory — matched as '{owner}{rest}'.", false));
153
153
  string bareMember = rest.Split('(')[0];
154
154
  if (bareMember.Length > 0)
155
- candidates.Add((bareMember, $"'{owner}Create.{bareMember}' is a Creation-factory call; its docs live on the factory class (e.g. ItemFactoryBase) — matched by member name '{bareMember}'."));
155
+ candidates.Add((bareMember, $"'{owner}Create.{bareMember}' is a Creation-factory call; its docs live on the factory class (e.g. ItemFactoryBase) — matched by member name '{bareMember}'.", false));
156
156
  }
157
157
 
158
158
  // C# spells property and indexer accessors 'get_X'/'set_X' (element.get_Parameter(...),
@@ -166,26 +166,33 @@ namespace RevitBridge.Tools
166
166
  if (accessor.StartsWith("get_", StringComparison.Ordinal) || accessor.StartsWith("set_", StringComparison.Ordinal))
167
167
  accessor = accessor["get_".Length..];
168
168
  if (accessor != q)
169
- candidates.Add((accessor, "'get_X' / 'set_X' is the C# accessor spelling of property or indexer 'X'; matched without the prefix."));
169
+ candidates.Add((accessor, "'get_X' / 'set_X' is the C# accessor spelling of property or indexer 'X'; matched without the prefix.", true));
170
170
  }
171
171
 
172
- foreach (var (candidate, note) in candidates)
172
+ foreach (var (candidate, note, accessorRewrite) in candidates)
173
173
  {
174
- var (top, total) = RunScoring(index, candidate, kindFilter, maxResults);
174
+ // A C# accessor IS a method to the caller ('element.get_Parameter(...)'), but
175
+ // the XML documents the underlying member as a property/indexer — so an
176
+ // accessor-rewritten candidate lets kind=method admit properties too.
177
+ bool widenKind = accessorRewrite && kindFilter == 'M';
178
+ var (top, total) = RunScoring(index, candidate, kindFilter, maxResults, widenKind);
175
179
  if (total > 0)
176
- return (top, total, note);
180
+ return (top, total, widenKind
181
+ ? note + " The 'method' kind filter also admitted properties here: accessors are documented as properties/indexers."
182
+ : note);
177
183
  }
178
184
  return (new List<ApiMember>(), 0, null);
179
185
  }
180
186
 
181
- private static (List<ApiMember> Top, int Total) RunScoring(DocIndex index, string q, char? kindFilter, int maxResults)
187
+ private static (List<ApiMember> Top, int Total) RunScoring(DocIndex index, string q, char? kindFilter, int maxResults, bool methodKindAdmitsProperties = false)
182
188
  {
183
189
  string[] words = q.Split(WordSeparators, StringSplitOptions.RemoveEmptyEntries);
184
190
 
185
191
  var scored = new List<(ApiMember Member, int Score)>();
186
192
  foreach (var member in index.Members)
187
193
  {
188
- if (kindFilter is { } kind && member.Kind != kind)
194
+ if (kindFilter is { } kind && member.Kind != kind
195
+ && !(methodKindAdmitsProperties && kind == 'M' && member.Kind == 'P'))
189
196
  continue;
190
197
  int score = Score(member, q, words);
191
198
  if (score > 0)