Use asset name instead of asset id with part reference attribute

Hello!

Is it possible to use asset name instead of asset id with part reference attribute (with a tag)?
When opening scene as a catalog item part references are selectable in “readable” format, but it looks like you have to pass asset ID if you want to select an attribute from outside the player (via API).

Since we’re having a big number of configurable parts that can be used in a few different scenes, part references seemed like an obvious choice from maintenance perspective.

If not, what is the best way to convert one to another?

That is correct, you need to pass an ID to set your attributes via API. You will either need to get the ID of the asset or call the Catalog REST API. If I can help further please let me know.

@Phil wrote up this little snippet that may be useful. This will give you a map so you can access the attributes like nameToAssetId['attribute name']

let nameToAssetId = window.configurator
  .getAttributes()
  ?.filter((attr) => attr.type === "Asset")
  .flatMap((attr) =>
    attr.values.map(({ assetId }) => {
      const name = player.scene.get({ id: assetId, property: "name" });
      return { [name]: assetId };
    })
  )
  .reduce((acc, cur) => ({ ...acc, ...cur }), {});

@Will @Phil Thank you very much for your help!!!

1 Like