UNPKG

forma-embedded-view-sdk

Version:

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

119 lines (118 loc) 4.46 kB
// eslint-disable-next-line @typescript-eslint/no-unused-vars import { EmbeddedViewSdk } from "./embedded-view.js"; /** * Interact with Forma's native [analysis functionality](https://aps.autodesk.com/en/docs/forma/v1/embedded-views/useful-concepts/analysis/). * * @remarks * Available via {@link auto.Forma | Forma}.{@link index.EmbeddedViewSdk.analysis | analysis}. */ export class AnalysisApi { #iframeMessenger; /** @hidden */ constructor(iframeMessenger) { this.#iframeMessenger = iframeMessenger; } /** * Fetch analysis records connected to the currently open proposal. * * @returns * List of relevant analysis records. * * @example * // Fetch all sun analysis records. * // Filter to only include those in SUCCEEDED state. * const sunAnalyses = await Forma.analysis.list({ analysisTypes: ["sun"] }) * const succeededSunAnalyses = sunAnalyses.filter(analysis => analysis.status === "SUCCEEDED") */ async list(request) { return await this.#iframeMessenger.sendRequest("analysis/list", request); } /** * @beta * Trigger a * [noise analysis](https://aps.autodesk.com/en/docs/forma/v1/embedded-views/useful-concepts/analysis/noise/) * based on the traffic data connected to roads and railways in the proposal. Computes A-weighted decibel levels. * * Requires edit access. See {@link EmbeddedViewSdk.getCanEdit | getCanEdit} for more info. * * @returns Analysis record for the newly triggered analysis. * * @example * // Trigger noise analysis on selected elements * const currentlySelected = await Forma.selection.getSelection() * const sunAnalysis = await Forma.analysis.triggerNoise({ * selectedElementPaths: currentlySelected * }) * @remarks * Noise analysis is a Beta feature of Autodesk Forma. * */ async triggerNoise(request) { return await this.#iframeMessenger.sendRequest("analysis/trigger-noise", request); } /** * Trigger a * [sun analysis](https://aps.autodesk.com/en/docs/forma/v1/embedded-views/useful-concepts/analysis/sun/) * for a specific day of the year. Computes sun exposure in hours. * * Requires edit access. See {@link EmbeddedViewSdk.getCanEdit | getCanEdit} for more info. * * @returns * Analysis record for the newly triggered analysis. * * @example * // Trigger sun analysis on selected elements for the summer solstice * const currentlySelected = await Forma.selection.getSelection() * const sunAnalysis = await Forma.analysis.triggerSun({ * selectedElementPaths: currentlySelected, * month: 6, * date: 21 * }) */ async triggerSun(request) { return await this.#iframeMessenger.sendRequest("analysis/trigger-sun", request); } /** * Fetch a specific sun analysis. * * @returns * Information about the sun analysis. */ async getSunAnalysis(request) { return await this.#iframeMessenger.sendRequest("analysis/get-sun-analysis", request); } /** * Fetch a specific noise analysis. * * @returns * Information about the noise analysis. * * @remarks * Noise analysis is a Beta feature of Autodesk Forma. */ async getNoiseAnalysis(request) { return await this.#iframeMessenger.sendRequest("analysis/get-noise-analysis", request); } /** * Fetch * [ground grid result](https://aps.autodesk.com/en/docs/forma/v1/embedded-views/useful-concepts/analysis/) * for a sun or noise analysis. * * Requires edit access. See {@link EmbeddedViewSdk.getCanEdit | getCanEdit} for more info. * * @returns * Ground grid containing results for the requested analysis. * * @example * // Fetch ground grid for the first listed succeeded sun analysis * const sunAnalyses = await Forma.analysis.list({ analysisTypes: ["sun"] }) * const succeededSunAnalyses = sunAnalyses.filter(analysis => analysis.status === "SUCCEEDED") * const groundGrid = await Forma.analysis.getGroundGrid({ analysis: succeededSunAnalyses[0] }) * * @remarks * Noise analysis is a Beta feature of Autodesk Forma. */ async getGroundGrid(request) { return await this.#iframeMessenger.sendRequest("analysis/get-ground-grid", request); } }