@snaptrude/plugin-core 0.0.0-dev-20260827135706 → 0.0.0-dev-20260827194031

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snaptrude/plugin-core",
3
- "version": "0.0.0-dev-20260827135706",
3
+ "version": "0.0.0-dev-20260827194031",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -1,5 +1,6 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
+ import { ComponentHandle, Vec3Components } from "../../handles"
3
4
 
4
5
  /**
5
6
  * `snaptrude.design.family.*` — author NATIVE parametric families from a JSON spec.
@@ -142,23 +143,96 @@ export abstract class PluginDesignFamilyApi {
142
143
  public abstract list(): PluginApiReturn<PluginFamilySummary[]>
143
144
 
144
145
  /**
145
- * Arm placement with the prepared family.
146
+ * Put a family into the model — either the prepared draft or any family from
147
+ * {@linkcode PluginDesignFamilyApi.list}.
146
148
  *
147
- * This does **not** create geometry. It puts the editor into placement mode
148
- * with a ghost on the cursor; the user clicks in the canvas to drop it, the
149
- * same as for any other family. Tell the user to click.
149
+ * Two modes, chosen by whether you pass `position`:
150
150
  *
151
- * @returns Which family was armed
151
+ * **With `position`** the component is created there and then, undoably. Use
152
+ * this when you know where it goes — you were given coordinates, or you are
153
+ * copying an existing instance. The returned `component` handle works with
154
+ * `design.transform.move` / `.rotate` and with
155
+ * {@linkcode PluginDesignFamilyApi.setParameters}.
156
+ *
157
+ * **Without `position`** it arms placement mode with a ghost on the cursor
158
+ * and returns immediately — no geometry yet. The USER clicks to drop it, so
159
+ * tell them to. Prefer this when the location is a judgement call.
160
+ *
161
+ * To COPY a placed component, place its family again at the new position with
162
+ * the same `values` — there is no separate copy call.
163
+ *
164
+ * @param args Which family, where, and at what parameter values
165
+ * @returns What was placed; `component` is present only in positioned mode
152
166
  *
153
167
  * @examplePrompt Place it in the model
154
- * @examplePrompt Let me put this on the facade
168
+ * @examplePrompt Put a louvre screen at the origin
169
+ * @examplePrompt Copy that table two metres to the right
155
170
  *
156
171
  * # Example
157
172
  * ```ts
173
+ * // positioned — geometry exists when this resolves
174
+ * const { component } = await snaptrude.design.family.place({
175
+ * id: "revit:gypsum-stud-partition~90ad72",
176
+ * position: { x: 0, y: 0, z: 0 },
177
+ * rotation: 90,
178
+ * })
179
+ * await snaptrude.design.transform.move([component], { x: 2, y: 0, z: 0 })
180
+ *
181
+ * // interactive — the user clicks
158
182
  * await snaptrude.design.family.place()
159
183
  * ```
160
184
  */
161
- public abstract place(): PluginApiReturn<PluginFamilyPlaceResult>
185
+ public abstract place(
186
+ args?: PluginDesignFamilyPlaceArgs,
187
+ ): PluginApiReturn<PluginFamilyPlaceResult>
188
+
189
+ /**
190
+ * Read a placed component's current parameter values and its sheet.
191
+ *
192
+ * Use before {@linkcode PluginDesignFamilyApi.setParameters} so you change
193
+ * what is actually there: parameter KEYS are the family's own, not the
194
+ * label the user says, and a Revit-imported family carries parameters that
195
+ * do not drive geometry at all.
196
+ *
197
+ * @param args The component to read
198
+ * @returns Its definition, current values, and the parameter sheet
199
+ *
200
+ * @examplePrompt What size is that table?
201
+ * @examplePrompt Show me the parameters on this partition
202
+ *
203
+ * # Example
204
+ * ```ts
205
+ * const { values, parameters } = await snaptrude.design.family.getParameters({ component })
206
+ * ```
207
+ */
208
+ public abstract getParameters(
209
+ args: PluginDesignFamilyGetParametersArgs,
210
+ ): PluginApiReturn<PluginFamilyInstanceParameters | null>
211
+
212
+ /**
213
+ * Change a placed component's parameters and rebuild its geometry in place.
214
+ *
215
+ * Partial: pass only what changes. The component keeps its position,
216
+ * rotation and identity — this is an edit, not a replace, and it is undoable.
217
+ *
218
+ * Only parameters with `drivesGeometry` actually move the mesh. Setting one
219
+ * that does not is accepted and stored (it round-trips to Revit) but nothing
220
+ * visible happens — say so rather than claiming a change the user cannot see.
221
+ *
222
+ * @param args The component and the values to change
223
+ * @returns The values now in effect
224
+ *
225
+ * @examplePrompt Make that table seat 8
226
+ * @examplePrompt Change the stud spacing to 400
227
+ *
228
+ * # Example
229
+ * ```ts
230
+ * await snaptrude.design.family.setParameters({ component, values: { seats: 8 } })
231
+ * ```
232
+ */
233
+ public abstract setParameters(
234
+ args: PluginDesignFamilySetParametersArgs,
235
+ ): PluginApiReturn<PluginFamilyInstanceParameters>
162
236
 
163
237
  /**
164
238
  * Commit the prepared bundle to the project's parametric-definition library,
@@ -301,7 +375,7 @@ export interface PluginFamilyFlexResult {
301
375
  error?: string
302
376
  }
303
377
 
304
- /** One registered parametric family. */
378
+ /** One family available to place — from the session registry or the catalog. */
305
379
  export interface PluginFamilySummary {
306
380
  id: string
307
381
  version: number
@@ -309,6 +383,18 @@ export interface PluginFamilySummary {
309
383
  category?: string
310
384
  /** Number of rows on the family's parameter sheet. */
311
385
  parameters: number
386
+ /**
387
+ * Where the family came from, which decides how far you can edit it.
388
+ *
389
+ * `"native"` — authored from a JSON spec through this API. Its recipe is
390
+ * data, so every parameter genuinely re-runs the geometry.
391
+ *
392
+ * `"revit"` — imported from a Revit family. Parameters exist and are
393
+ * editable, but only those the importer could bind to geometry actually
394
+ * change the mesh; the rest are carried for round-tripping. Check
395
+ * `drivesGeometry` on the parameter before promising the user a change.
396
+ */
397
+ kind: "native" | "revit"
312
398
  }
313
399
 
314
400
  /** What `place` reports. */
@@ -316,9 +402,27 @@ export interface PluginFamilyPlaceResult {
316
402
  ok: boolean
317
403
  familyId?: string
318
404
  version?: number
405
+ /**
406
+ * The created component — present ONLY when `position` was given. In
407
+ * interactive mode nothing exists yet, so there is nothing to hand back;
408
+ * the user has not clicked.
409
+ */
410
+ component?: ComponentHandle
319
411
  error?: string
320
412
  }
321
413
 
414
+ /** A placed component's parameter state, from `getParameters` / `setParameters`. */
415
+ export interface PluginFamilyInstanceParameters {
416
+ /** The definition this instance is pinned to. */
417
+ familyId: string
418
+ version: number
419
+ label: string
420
+ /** Current values, keyed by parameter key. */
421
+ values: Record<string, number | string>
422
+ /** The sheet: what each key means, its bounds, and whether it moves geometry. */
423
+ parameters: PluginFamilyParameter[]
424
+ }
425
+
322
426
  /** What `create` reports. */
323
427
  export interface PluginFamilyCreateResult {
324
428
  ok: boolean
@@ -386,3 +490,55 @@ export const PluginDesignFamilyCreateArgs = z.object({
386
490
  teamId: z.string().optional(),
387
491
  })
388
492
  export type PluginDesignFamilyCreateArgs = z.infer<typeof PluginDesignFamilyCreateArgs>
493
+
494
+ /**
495
+ * Arguments for {@linkcode PluginDesignFamilyApi.place}.
496
+ *
497
+ * | Property | Type | Description |
498
+ * |---|---|---|
499
+ * | `id` | `string` | Family to place, from {@linkcode PluginDesignFamilyApi.list}. Omit to place the prepared draft |
500
+ * | `version` | `number` | Exact version; defaults to the newest known |
501
+ * | `position` | `{ x, y, z }` | Place HERE, without user interaction. Omit to arm the cursor instead |
502
+ * | `rotation` | `number` | Yaw in degrees about +Y. Only with `position` |
503
+ * | `values` | `Record<string, number \| string>` | Parameter values for THIS instance |
504
+ * | `storey` | `number` | Storey to place on; defaults to the active one |
505
+ */
506
+ export const PluginDesignFamilyPlaceArgs = z.object({
507
+ id: z.string().optional(),
508
+ version: z.number().int().positive().optional(),
509
+ position: Vec3Components.optional(),
510
+ rotation: z.number().optional(),
511
+ values: z.record(z.string(), z.union([z.number(), z.string()])).optional(),
512
+ storey: z.number().int().optional(),
513
+ })
514
+ export type PluginDesignFamilyPlaceArgs = z.infer<typeof PluginDesignFamilyPlaceArgs>
515
+
516
+ /**
517
+ * Arguments for {@linkcode PluginDesignFamilyApi.getParameters}.
518
+ *
519
+ * | Property | Type | Description |
520
+ * |---|---|---|
521
+ * | `component` | {@linkcode ComponentHandle} | A placed parametric component |
522
+ */
523
+ export const PluginDesignFamilyGetParametersArgs = z.object({
524
+ component: ComponentHandle,
525
+ })
526
+ export type PluginDesignFamilyGetParametersArgs = z.infer<
527
+ typeof PluginDesignFamilyGetParametersArgs
528
+ >
529
+
530
+ /**
531
+ * Arguments for {@linkcode PluginDesignFamilyApi.setParameters}.
532
+ *
533
+ * | Property | Type | Description |
534
+ * |---|---|---|
535
+ * | `component` | {@linkcode ComponentHandle} | A placed parametric component |
536
+ * | `values` | `Record<string, number \| string>` | Values to change (partial) |
537
+ */
538
+ export const PluginDesignFamilySetParametersArgs = z.object({
539
+ component: ComponentHandle,
540
+ values: z.record(z.string(), z.union([z.number(), z.string()])),
541
+ })
542
+ export type PluginDesignFamilySetParametersArgs = z.infer<
543
+ typeof PluginDesignFamilySetParametersArgs
544
+ >
@@ -41,6 +41,7 @@ import { PluginDesignQueryReferenceLinesApi } from "./referenceLines"
41
41
  * | `"curtainWall"` | Parametric curtain wall |
42
42
  * | `"mullion"` | Curtain-wall mullion |
43
43
  * | `"panel"` | Curtain-wall panel |
44
+ * | `"parametricComponent"` | A placed parametric family instance (native or Revit-imported). Its geometry is rebuilt from `design.family` parameters, so read and drive it through `design.family.getParameters` / `setParameters` rather than editing its meshes. |
44
45
  */
45
46
  export const PluginEntityType = z.enum([
46
47
  "wall",
@@ -60,6 +61,7 @@ export const PluginEntityType = z.enum([
60
61
  "curtainWall",
61
62
  "mullion",
62
63
  "panel",
64
+ "parametricComponent",
63
65
  ])
64
66
  export type PluginEntityType = z.infer<typeof PluginEntityType>
65
67