Are there any issues relying on getting scenePaths by name

I’m curious if there’s a reason the ShapeDiver API doesn’t include a function to retrieve scenePaths by name? Maybe relying on this is risky for some reason?

Following Hide/Show objects - #4 by edsahergom, I’m using the fuction below to retrieve scenePaths for use in ShapeDiver API functions:

function getScenePathByName(name, viewer = "api", type = "material", runtimeId = "CommPlugin_1") {
  if (name && type && viewer && runtimeId) {
    let nameScenePaths = [];
    const getScenePaths = (name) => {
      let typeScenePaths = [];
      const typeData = viewer.scene.get({name: name}, runtimeId).data.filter(d => d[type]);
      typeData.forEach((td) => typeScenePaths = [...typeScenePaths, td.scenePath]);
      return (typeScenePaths.length > 1) ? typeScenePaths : typeScenePaths[0];
    if (Array.isArray(name)) {
      name.forEach((n) => {
        nameScenePaths = [...nameScenePaths, getScenePaths(n)];
    } else {
      nameScenePaths = getScenePaths(name);
    return (nameScenePaths.length > 1) ? nameScenePaths : nameScenePaths[0];

I want to be sure I’m not creating a problem. Thanks

The names of assets are not unique, the Grasshopper definition can contain multiple assets with the same name and type. So yes, you could say it is risky unless you make sure that unique names are respected in the definition.

Thanks Mathieu.

If api.scene.get({name:“Some Name”}, “CommPlugin_1”) is called where “Some Name” is linked to several assets, what’s returned (array, error…)?

It will return an array with all the assets bearing that name.