Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

304
Vistas
Autodesk Forge: Viewer Extension cant use .getExternalIdMapping()
class IBSProgressExtension extends Autodesk.Viewing.Extension{
    constructor(viewer, options) {
        super(viewer, options);
    }
    load() {
        //For proof of concept project, I will simply store the externalIds here in a variable.
        const allExternalIds = [
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-0006879a',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-000688ee',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068961',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068963',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a78',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a0d',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a0f',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a11',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a13',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068c2f',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068c31',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068c33',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b2e',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b30',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b32',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b34',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b3e',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b36',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b38',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b3a',
            '8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b3c'
        ];

        this.viewer.model.getExternalIdMapping(data => onSuccessMapping(data));

        function onSuccessMapping(data) {
            const resArray = [];
            allExternalIds.forEach(externalId => {
                if (data[externalId]) resArray.push(data[externalId], externalId);
            });
            console.log(resArray);
        };

        console.log('IBSProgressExtension is loaded.');
        return true;
    }
};


Autodesk.Viewing.theExtensionManager.registerExtension("IBSProgressExtension", IBSProgressExtension);

Please have a look at my extension and please help me figure out why is this happening. Every time i run it, the devtools logs: ViewerExtension.js:31 Uncaught TypeError: Cannot read properties of undefined (reading 'getExternalIdMapping').

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The extensions get loaded before the model so the getExternalIdMapping() method does not have the model properties yet. To handle this scenario, we usually recommend using the viewer events such as Autodesk.Viewing.GEOMETRY_LOADED_EVENT to “catch” the moment when the model is available. It’s better to wait for the event. This will be fired when the model/drawing finishes loading.

Instead of:

this.viewer.model.getExternalIdMapping(data => onSuccessMapping(data));

Try this:

        this.viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, (x) => {
            this.viewer.model.getExternalIdMapping(data => onSuccessMapping(data));
        });

about 4 years ago · Juan Pablo Isaza Denunciar

0

Please test this and see if it's helpful. I tried to incorporate items from your comments to help you structure it out.

class IBSProgressExtension extends Autodesk.Viewing.Extension {
  constructor(viewer, options) {
    super(viewer, options);
    this._externalIds = null;
    //Eventually will want to pass in your external IDs to this function, I assume:
    //this._externalIds = options.externalIds
  
    this._doStuff = () => {
      this.startDoingStuff();
    };
  }
  load() {
    console.log("loading extension");
    //For now, hard coded like your example.
    this._externalIds = [
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-0006879a",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-000688ee",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068961",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068963",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a78",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a0d",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a0f",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a11",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068a13",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068c2f",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068c31",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068c33",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b2e",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b30",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b32",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b34",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b3e",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b36",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b38",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b3a",
      "8a00f4c7-0709-4749-88b6-abb0ddccf965-00068b3c",
    ];
    //Not sure if this is truly the right event, but it worked when I tested on mine.
    this.viewer.addEventListener(Autodesk.Viewing.MODEL_LAYERS_LOADED_EVENT, this._doStuff);
  }
  startDoingStuff() {
    console.log("startDoingStuff executing");
    this.getDbIds(this._externalIds).then((CombinedArray) => {
      this.setCustomColors(CombinedArray);
    });
  }
  setCustomColors(arrayOfIDs) {
    console.log("setCustomColors executing");
    var somecolor = "#7D5B51";
    var threecolor = new THREE.Color(somecolor);
    var vectcolor = new THREE.Vector4(threecolor.r, threecolor.g, threecolor.b, 1);

    arrayOfIDs.forEach((e) => {
      this.viewer.setThemingColor(e[0], vectcolor, this.viewer.getVisibleModels()[0]);
    });
  }
  getDbIds(externalIds) {
    console.log("getDbIds executing");
    return new Promise((resolve) => {
      this.viewer.model.getExternalIdMapping((d) => {
        //console.log("getDbIdFromExternalId Executed");
        let responseArr = [];
        externalIds.forEach((externalId) => {
          if (d[externalId]) responseArr.push([d[externalId], externalId]);
        });
        console.log("resolving", responseArr);
        resolve(responseArr);
      });
    });
  }
}

Autodesk.Viewing.theExtensionManager.registerExtension("IBSProgressExtension", IBSProgressExtension);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Regarding this, I was trying to achieve 3 things at this stage.

  1. Get the externalIds from Mongodb.
  2. Compare the externalIds with the ones gotten from getExternalIdMapping().
  3. Get DbIds of those that matched.

Solved these by realising 2 and 3 can be put inside a.then() after .loadDocumentNode().

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda