UNPKG

forma-embedded-view-sdk

Version:

The Forma Embedded View SDK is a JavaScript library for creating custom extensions in Autodesk Forma Site Design (previously Spacemaker).

44 lines (43 loc) 1.57 kB
/** * Interact with user's selection (i.e. shift-clicked elements in the scene) * * @remarks * Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.selection | selection}. */ export class SelectionApi { #iframeMessenger; /** @hidden */ constructor(iframeMessenger) { this.#iframeMessenger = iframeMessenger; } /** * Get selected elements. * * @returns List of paths to elements currently selected in the scene. * * @example * // Fetch all paths to selected elements in the current proposal. * // Count how many of them are buildings. * const selectedPaths = await Forma.selection.getSelection() * const buildingPaths = await Forma.geometry.getPathsByCategory({ category: "buildings" }) * const selectedBuildingPaths = selectedPaths.filter(path => buildingPaths.includes(path)) * const numberOfSelectedBuildings = selectedBuildingPaths.length */ async getSelection() { return await this.#iframeMessenger.sendRequest("scene/selection/get"); } /** * Subscribe to selection changes. * * @example * const { unsubscribe } = await Forma.selection.subscribe(({ paths }) => { * console.log(paths) * }); * * @param callback event handler for each selection change * @returns { unsubscribe: () => void } object with an `unsubscribe` method to stop listening */ async subscribe(callback) { return await this.#iframeMessenger.createSubscription("scene/selection/on-change", callback); } }