Skip to main content

Simpler ways to do common tasks

Use these Web API patterns to simplify a host script or Custom UI. The earlier patterns use the public API available in older embeds. The newer patterns give you a direct way to read state, configure controls, or create a share link.

Connect before reading state​

Check for window.mimeeqApp or listen for mimeeq-api-installed on document before attaching observers. The first subscription callback receives { newValue } with the current value. Subsequent emissions include oldValue. Use getValue() for a synchronous snapshot and treat observer values as read-only.

Earlier pattern

A script registered before the embed loaded could wait for mimeeq-3d-product-initialized to detect the first rendered 3D product. The event is sent on initial 3D setup for a standard product or when a saved modular design is loaded before the scene has any configured variants. An empty modular start and a 2D-only view can leave that listener waiting.

document.addEventListener(
'mimeeq-3d-product-initialized',
() => {
console.log('3D product initialized');
},
{ once: true },
);

Current pattern

Subscribe to window.mimeeqApp.observers.status.firstRender and status.settled to handle scripts that start after the first render.

function watchScene() {
const label = document.createElement('output');
document.body.append(label);

const { firstRender, settled } = window.mimeeqApp.observers.status;
const update = () => {
const ready = firstRender.getValue() && settled.getValue();
label.textContent = ready ? 'Scene ready' : 'Waiting for the scene';
};
const subscriptions = [firstRender, settled].map((observer) => observer.subscribe(update));
window.addEventListener('pagehide', () => {
subscriptions.forEach((subscription) => subscription.unsubscribe());
}, { once: true });
}

if (window.mimeeqApp) watchScene();
else document.addEventListener('mimeeq-api-installed', watchScene, { once: true });

See lifecycle events and the status observer reference.

Read a value once​

Earlier pattern

Subscribe to an observer and unsubscribe immediately when you only need its current value.

function logQuantity() {
window.mimeeqApp.observers.pricing.quantity
.subscribe(({ newValue }) => {
console.log('Quantity', newValue ?? 'Unavailable');
})
.unsubscribe();
}

if (window.mimeeqApp) logQuantity();
else document.addEventListener('mimeeq-api-installed', logQuantity, { once: true });

Current pattern

Use getValue() to read the same value synchronously. The quantity is a number when available. A missing value means there is no quantity to show yet.

function logQuantity() {
const quantity = window.mimeeqApp.observers.pricing.quantity.getValue();
console.log('Quantity', quantity ?? 'Unavailable');
}

if (window.mimeeqApp) logQuantity();
else document.addEventListener('mimeeq-api-installed', logQuantity, { once: true });

Read the selection for a named block​

Earlier pattern

For a standard product, find the block ID in window.mimeeqApp.observers.optionSets.blocks and match it to the selected options. Configure a block with the code Finish or replace it with your own block code.

function watchFinish() {
const { blocks, selectedOptions } = window.mimeeqApp.observers.optionSets;
function logSelection() {
blocks
.subscribe(({ newValue }) => {
const block = newValue?.find(({ blockName }) => blockName === 'Finish');
if (!block) return;

selectedOptions
.subscribe(({ newValue: selections }) => {
const options =
selections?.SINGLE_PRODUCT_ID?.filter(({ blockId }) => blockId === block.id) ?? [];
console.log(options.map(({ name }) => name));
})
.unsubscribe();
})
.unsubscribe();
}
const subscriptions = [blocks.subscribe(logSelection), selectedOptions.subscribe(logSelection)];
window.addEventListener(
'pagehide',
() => {
subscriptions.forEach((subscription) => subscription.unsubscribe());
},
{ once: true },
);
}

if (window.mimeeqApp) watchFinish();
else document.addEventListener('mimeeq-api-installed', watchFinish, { once: true });

Current pattern

Read window.mimeeqApp.observers.optionSets.selectedOptionsByBlockCode. An absent key means no option is selected for that block. Some blocks allow more than one selection.

function watchFinish() {
const selection = window.mimeeqApp.observers.optionSets.selectedOptionsByBlockCode;
const subscription = selection.subscribe(({ newValue }) => {
console.log((newValue?.Finish ?? []).map(({ name }) => name));
});
window.addEventListener('pagehide', () => subscription.unsubscribe(), { once: true });
}

if (window.mimeeqApp) watchFinish();
else document.addEventListener('mimeeq-api-installed', watchFinish, { once: true });

See option-set observers for selection scope and per-item access.

Update other controls​

The linked examples include the complete setup and the values to expect before a product or scene is ready. In the table, observer and action paths start at window.mimeeqApp.

TaskEarlier public patternCurrent public pattern
Enable Undo and RedoCompare the one-based observers.history.currentElement with the length of observers.history.stack.Subscribe to observers.history.canUndo and observers.history.canRedo for the current availability. See Undo and redo.
Track main product loadingRead observers.product.isLoading.Read observers.status.loading. It exposes the same value.
Track price or product-list loadingRead observers.pricing.isPriceLoading or observers.productList.isLoading.Read observers.status.priceLoading or observers.status.productListLoading, respectively.
Capture a configured viewPass the positional arguments to utils.takeScreenshot.Pass an options object for named capture settings, orthographic projection, or the projection matrix.
Position a toolbar above a placed itemCall actions.getBoundingBoxPosition2d(instanceId) when an item is selected.Call actions.getInstanceScreenRect(instanceId) and redraw on camera and scene updates. The result is in canvas-relative CSS pixels, or null when projection is unavailable. For a specific visible mesh, use actions.getMeshPosition. See Item toolbar and labels.
Build a modular parts listRead observers.modular.modularSceneElements and group the elements by product or configuration.Read observers.modular.sceneItems for one row per placed item. Use actions.getGroupedSceneItems('productId') or actions.getGroupedSceneItems('configurationCode') for grouped rows. See Scene and catalog.
Match a price to a placed itemRead a placed item's product and configuration from observers.modular.modularSceneElements, then use the productId|configurationCode key in observers.pricing.modularPrices.Read observers.modular.instancePrices by instance ID. A present key with null means there is no matching price. See Modular observers.
Show open ends and connectionsRead connections from observers.modular.modularSceneElements and look up the available connection points in observers.modular.freeSnapPoints.Read observers.modular.snapStatuses for each placed item's joints. Use snapPlacementControls to decide where a chosen component fits. See Snap-aware add flow.
Inspect a placed item's option blocksSelect the item with actions.selectElement(instanceId), then read its prepared blocks from observers.optionSets.blocks.Read observers.modular.instanceBlocks by instance ID without changing selection. See Options per item.
Zoom while idle rotation is enabledCall actions.increaseZoom() or actions.decreaseZoom(). Rotation can continue during zoom.Pass undefined for the step and { pauseAutoRotate: true } as the second argument to restart the idle wait. See Camera controls.
Share a standard configurationCopy the host URL with the variantCode query parameter from an embed with URL navigation enabled.Call actions.getShareUrl() and copy the complete returned URL. It works without enabling URL navigation. A null result means there is no standard configuration to share. See Copy a standard product share link.
Show updates from a custom pricing calculationKeep track of the values your script passes to utils.setPrice() and update your own price display after each successful call.Subscribe to observers.pricing.priceSource. Use source: 'custom' to recognize an applied custom price and source: 'engine' for a built-in price. See Custom pricing integration.