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).
105 lines (104 loc) • 4.14 kB
JavaScript
/**
* Enable design tools supplied by the host app.
*
* @remarks
* Available via {@link index.EmbeddedViewSdk.designTool | EmbeddedViewSdk.designTool}.
*/
export class DesignToolApi {
#iframeMessenger;
/** @hidden */
constructor(iframeMessenger) {
this.#iframeMessenger = iframeMessenger;
}
/**
* Activate tool for creating a point by clicking in the 3D scene.
*
* Does not return until the user has selected a point or cancelled the operation (by clicking ESC).
*
* @returns The selected point, or `undefined` if the user cancelled the operation.
*
* @example
* const point = await Forma.designTool.getPoint();
*/
async getPoint() {
return await this.#iframeMessenger.sendRequest("design-tool/get-point");
}
/**
* Activate tools for creating a polygon.
*
* There are several available tools for creating polygons:
* 1. "free-form": Click repeatedly in the 3D scene to create a polygon with any number of vertices.
* 2. "rectangle": Click two points to define the first side of a rectangle, and then a third point along a 90 degree angle to define the second side.
* 3. "circle": Click a centre and then a point on the circumference to create a circle.
* 4. "pick": Select an existing shape in the 3D scene and use it as the basis for a new polygon.
*
* Does not return until the user has created a polygon or cancelled the operation (by clicking ESC).
*
* @returns The created polygon, or `undefined` if the user cancelled the operation.
*
* @example
* const polygon = await Forma.designTool.getPolygon();
*/
async getPolygon() {
return await this.#iframeMessenger.sendRequest("design-tool/get-polygon");
}
/**
* Activate tool for creating an extruded polygon.
*
* See {@link getPolygon} for available tools for creating polygons.
* Once a polygon has been created, choose the height of the extrusion by clicking a final time.
*
* Does not return until the user has created an extruded polygon or cancelled the operation (by clicking ESC).
*
* @returns The created extruded polygon, or `undefined` if the user cancelled the operation.
*
* @example
* const extrudedPolygon = await Forma.designTool.getExtrudedPolygon();
*/
async getExtrudedPolygon() {
return await this.#iframeMessenger.sendRequest("design-tool/get-extruded-polygon");
}
/**
* Activate tool for creating a line.
*
* Click repeatedly in the 3D scene to create a line with any number of vertices.
*
* Does not return until the user has created a line or cancelled the operation (by clicking ESC).
*
* @returns The created Line, or `undefined` if the user cancelled the operation.
*
* @example
* const line = await Forma.designTool.getLine();
*/
async getLine() {
return await this.#iframeMessenger.sendRequest("design-tool/get-line");
}
/**
* Subscribe to the 'start' event for edits with the drawing tools.
*
* @example
* const { unsubscribe } = await Forma.designTool.onEditStart(() => {
* console.log('start event')
* });
*
* @param callback event handler to be called when editing starts
* @returns { unsubscribe: () => void } object with an `unsubscribe` method to stop listening
*/
async onEditStart(callback) {
return this.#iframeMessenger.createSubscription("scene/design-events/on-edit-start", callback);
}
/**
* Subscribe to the 'end' event for edits with the drawing tools.
*
* @example
* const { unsubscribe } = await Forma.designTool.onEditEnd(() => {
* console.log('end event')
* });
*
* @param callback event handler to be called when editing ends
* @returns { unsubscribe: () => void } object with an `unsubscribe` method to stop listening
*/
async onEditEnd(callback) {
return this.#iframeMessenger.createSubscription("scene/design-events/on-edit-end", callback);
}
}