How to get the keys and values of "attribute user text" in a 3dm file using rhino3dm.js?

It seems only mesh type of geometry in 3dm file can be read by the rhino3dm.js library, using code like the following, though a bit cumbersome…

But, how do we read the keys and values stored in attribute user text assigned to the geometries in the original 3dm file, using methods in rhino3dm.js?

var rhino_file_path = "../3dm/b01_mesh.3dm";

let fetchPromise = fetch(rhino_file_path);

rhino3dm().then(async (m) => {
        console.log("Loaded rhino3dm.");
        let rhino = m;
        let res = await fetchPromise;
        let buffer = await res.arrayBuffer();
        let arr = new Uint8Array(buffer);
        let doc = rhino.File3dm.fromByteArray(arr);

        THREE.Object3D.DefaultUp = new THREE.Vector3(0, 0, 1);
       
        init();

        let material = new THREE.MeshNormalMaterial();

        let objects = doc.objects();

        for (let i = 0; i < objects.count; i++) {
          let mesh = objects.get(i).geometry();
          if (mesh instanceof rhino.Mesh) {
            // convert all meshes in 3dm model into threejs objects
            let threeMesh = meshToThreejs(mesh, material);
            scene.add(threeMesh);
          }
      }
  });

@fraguada - is this something you can help with?

You can do something like this for any Rhino object:

//load 3dm ...
let objects = doc.objects();

for ( let i = 0; i < objects.count; i++ ) {

  const rhinoObject = objects.get( i );

  // attribute user strings
  if ( rhinoObject.attributes().userStringCount > 0 ) {
    const a_userStrings = rhinoObject.attributes().getUserStrings()
    console.log( a_userStrings )
  }

  // geometry user strings
  if ( rhinoObject.geometry().userStringCount > 0 ) {
    const g_userStrings = rhinoObject.geometry().getUserStrings()
    console.log( g_userStrings )
  }

// ...

}
1 Like

Thanks, @dale, for forwarding my question to @fraguada .

Thank you, @fraguada, for your kind help. I’ll try out accordingly.