javascriptifc

ifcManager.getAllItemsOfType() ran into error


I am using the ifcLoader.ifcManager.getAllItemsOfType() function from ifc.js I put the function inside the load method, so that after loading a ifc file, it should be print all the slab properties.

const modelID = 0;

  async function logAllSlabs(){
    const slabsID = await ifcLoader.ifcManager.getAllItemsOfType(modelID, IFCSLAB);

    for(let i = 0; i <= slabsID.length; i++) {
        const slabID = slabsID[i];
        const slabProperties = await ifcLoader.ifcManager.getItemProperties(0, slabID);
        console.log(slabProperties);
    }
  }
// IFC loading
  const ifcLoader = new IFCLoader();
  
  const input = document.getElementById('file-input')
  input.addEventListener('change', async () => {
    console.log('file selected')
    const file = input.files[0];
    const url = URL.createObjectURL(file);
    const model = await ifcLoader.loadAsync(url);
    scene.add(model);
    ifcModels.push(model);
    logAllSlabs()
  });

It seems work fine at the beginning, then there's this error. Cannot convert "undefined" to unsigned int

picture


Here is the code. https://github.com/ChenChihYuan/ifcjs_notes/blob/main/02_properties_WIT/app.js

Any suggestions will be thankful.


Solution

  • At a very quick glance, it looks like you're processing one too many items in your for statement:

    You have:
    for(let i = 0; i <= slabsID.length; i++) {

    Since you're starting at zero, you should stop at length-1:
    for(let i = 0; i < slabsID.length; i++) {