Skip to main content

Read the scene and the catalog

Build a parts panel for a modular sofa. Use window.mimeeqApp.observers.modular.catalog to inspect the configured range, sceneItems to number placed items and instancePrices to show each item's price. Use window.mimeeqApp.actions.getGroupedSceneItems() to build a bill of materials.

Complete example​

Paste this into an HTML page with one embed. Replace the shortcode and template with values from a full modular embed configured to render inline. Add, move or configure items in the configurator and watch the parts panel update.

<mmq-embed short-code="YOUR_SHORT_CODE" template="YOUR_TEMPLATE" render-at-mount></mmq-embed>

<section aria-label="Modular parts">
<p id="scene-status" role="status">Opening the configurator…</p>
<h2>Components</h2>
<p id="starter"></p>
<ul id="catalog-items"></ul>
<h2>Placed items</h2>
<ol id="placed-items"></ol>
<h2>Bill of materials by configuration</h2>
<ul id="parts-list"></ul>
</section>

<script>
document.addEventListener(
'mimeeq-app-loaded',
() => {
const { observers, actions } = window.mimeeqApp;
const { catalog, components, sceneItems, instancePrices } = observers.modular;
const { firstRender, settled } = observers.status;
const message = document.getElementById('scene-status');
const starter = document.getElementById('starter');
const catalogList = document.getElementById('catalog-items');
const placedList = document.getElementById('placed-items');
const partsList = document.getElementById('parts-list');
if (!message || !starter || !catalogList || !placedList || !partsList) return;
let renderVersion = 0;

function listItem(label) {
const item = document.createElement('li');
item.textContent = label;
return item;
}

const render = async () => {
const version = ++renderVersion;
const range = catalog.getValue();
const picker = new Map((components.getValue() ?? []).map((item) => [item.productId, item]));
starter.textContent = range?.settings.starterConfig
? `Starter configuration: ${range.settings.starterConfig}`
: range
? 'No starter configuration is set.'
: '';
catalogList.replaceChildren(
...(range?.products ?? [])
.filter(({ productId }) => picker.has(productId))
.map(({ productId, name, settings }) => {
const entry = picker.get(productId);
const descriptions = [];
if (settings.general.canBePrimary) descriptions.push('can start a layout');
if (settings.hierarchy.parent) descriptions.push('parent');
if (settings.hierarchy.child) descriptions.push('child');
if (settings.general.freeMove) descriptions.push('free placement');
if (entry?.isQuantityLimitReached) descriptions.push('quantity limit reached');
else if (entry?.isDisabled) descriptions.push('unavailable in this layout');
return listItem([name, ...descriptions].join(' · '));
}),
);

if (!firstRender.getValue() || !settled.getValue()) {
message.textContent = 'Waiting for the scene…';
placedList.replaceChildren();
partsList.replaceChildren();
return;
}

const items = Object.values(sceneItems.getValue() ?? {}).sort(
(a, b) => a.positionOrder - b.positionOrder,
);
const prices = instancePrices.getValue() ?? {};
const totals = new Map();
const positions = new Map();
for (const { productId } of items) {
totals.set(productId, (totals.get(productId) ?? 0) + 1);
}

message.textContent = items.length ? '' : 'No items placed.';
placedList.replaceChildren(
...items.map(({ instanceId, productId, productName, productCode }) => {
const position = (positions.get(productId) ?? 0) + 1;
positions.set(productId, position);
const price = prices[instanceId];
const amount = price ? `${price.currency} ${price.price}` : 'Price unavailable';
return listItem(
`${productName || productCode || productId} ${position} of ${totals.get(productId)} from the left — ${amount}`,
);
}),
);

try {
const groups = await actions.getGroupedSceneItems('configurationCode');
if (version !== renderVersion) return;
partsList.replaceChildren(
...Object.entries(groups).map(([code, itemsInGroup]) => {
const [first] = itemsInGroup;
return listItem(
`${itemsInGroup.length} × ${first.productName || first.productCode || first.productId}${code ? ` (${code})` : ''}`,
);
}),
);
} catch (error) {
if (version !== renderVersion) return;
partsList.replaceChildren(listItem('The bill of materials could not be read.'));
console.error(error);
}
};

const refresh = () => void render();
const subscriptions = [
...[firstRender, settled].map((observer) => observer.subscribe(refresh)),
catalog.subscribe(refresh),
components.subscribe(refresh),
sceneItems.subscribe(refresh),
instancePrices.subscribe(refresh),
];
window.addEventListener('pagehide', (event) => {
if (!event.persisted) subscriptions.forEach((subscription) => subscription.unsubscribe());
});
},
{ once: true },
);
</script>
<script src="https://cdn.mimeeq.com/read_models/embed/app-embed.js" async></script>

How it works​

  1. Register the listener on document before loading the embed script. When the API is available, subscribe to the observers. Each subscription emits its current value immediately, and getValue() reads the latest snapshot synchronously. Observer callbacks receive { newValue, oldValue }, with no previous value on the initial emission.
  2. Join catalog entries to window.mimeeqApp.observers.modular.components by productId to show entries in the current picker. Read hierarchy and placement settings for their authored roles. A label such as “left armrest” needs a product name or a filter you configured for that purpose. Hierarchy flags describe connection roles.
  3. Wait for firstRender and settled to be true. Sort the items by positionOrder. Count each product separately to display labels such as “Seat 1 of 3 from the left.” Here, “left” means the low-X end of the layout. Camera orbit leaves that convention unchanged.
  4. Join instancePrices to the placed items by instanceId. The same product in another fabric can have a different price. Treat a missing price as unavailable and let later updates refresh the display.
  5. Group by configurationCode to count separately configured parts. Use getGroupedSceneItems('productId') when you want one count per product across all finishes. The async result contains arrays of items in positionOrder. The render counter discards results from superseded renders.

Observer payloads​

window.mimeeqApp.observers.status​

ObserverTypeMeaning
firstRenderbooleanThe mounted scene has drawn its first frame.
settledbooleanThe main product is loaded, the canvas is unblocked, no drag is active, and no 3D tasks are pending.
busybooleanAt least one 3D task is unfinished.

window.mimeeqApp.observers.modular.catalog​

FieldTypeMeaning
Top-level valueModularCatalog | nullnull until a modular product is loaded, and for standard products. A loaded modular product can have an empty scene.
productIdstringParent modular product ID.
productsArrayConfigured component products, including hidden and unplaced components. Empty if no component entries are available.
products[].productId, code, namestringStable product ID, authored product code and display name.
products[].type, mode, statusMetadataType, MetadataMode, StatusAuthored product metadata.
products[].settings.filtersstring[]Configured filters. Empty when absent.
products[].settings.hierarchy{ parent: boolean; child: boolean }Authored parent and child roles. Each defaults to false.
products[].settings.generalObject with optional flags and valuescanBePrimary, freeMove, allowSnapping, hideProduct, excludeFromSummary, disableConfigure, disableSelection and allowMaxQuantity are booleans if set. maxQuantity is a number and maxQuantityMessage is a string if set.
settings.starterConfigstring | undefinedSaved scene shortcode configured as the starter. It can differ from the scene currently open.
settings.dimensionsObjectshowDimensions defaults to true. dimensionSource, localSettings and legacy lengthUnit can be absent. Global template values are resolved separately.

window.mimeeqApp.observers.modular.components​

FieldTypeMeaning
Top-level valueProductListItem[]Active products for the current picker. Empty when no picker entries are available.
productId, labelstringProduct ID and display label.
isDisabled, isQuantityLimitReachedboolean | undefinedWhether the current picker disables the product or its configured quantity limit is reached.

window.mimeeqApp.observers.modular.sceneItems​

FieldTypeMeaning
Top-level valueRecord<string, ModularSceneItem>Map keyed by instance ID. {} means there are no placed modular items.
instanceId, productIdstringThe placed occurrence and its catalog product, respectively.
productCode, productNamestringAuthored product code and display name. Either can be empty if metadata is unavailable.
configurationCodestringCurrent configuration of the item. Can be empty while configuration data is unavailable.
positionOrdernumberOne-based order by increasing world X. Ties keep scene order. Missing or non-finite X values come last.

window.mimeeqApp.observers.modular.instancePrices​

FieldTypeMeaning
Top-level valueRecord<string, PriceData | null>Map keyed by instance ID. {} means there are no placed modular items. A null entry means there is no price for that product and its current configuration.
price, currencynumber, stringThe calculated amount and its currency code. A price of zero is a value.
levelsPriceLevel[]Quantity breaks. Can be empty.
unitPrice, oneTimePrice, comparePrice, unitComparePricenumber | undefinedOptional unit, one-time and comparison amounts.

Edge cases​

  • The item list and grouping include components marked excludeFromSummary. The example is a full parts inventory. Use the catalog settings to filter the list if you want it to match the scope of a customer-facing summary.
  • Grouping an empty scene returns {}. If configuration codes are missing or you want to count across configurations, group by product ID.
  • Per-item prices reflect the current matching price entries. Use the configurator's modular totals for the sale total, which can include pricing rules beyond these rows.

What this replaces​

Custom parts panels have parsed product-code suffixes to infer roles, exported scene share codes and parsed them back into component lists, and matched entries in a shared pricing table. The catalog exposes authored settings, the scene observer and grouping action give you placed items directly, and instancePrices looks up their current prices.

For an interactive picker, see Build your own add and insert flow.