Search code examples
autodesk-forgeautodesk-viewer

Get guid ID of highlighted component in 3d model using autodesk360


This is my first post on stackoverflow. I am using autodesk360, uploaded rvt file and got the iframe and display 3d model in my web page. I want to know when i click on any component within the iframe on 3d model, i want to get the guid id of that component. How can i get that? Here is the iframe i am using in my web page. Screen shot is here


Solution

  • The right way to embed "something like Autodesk 360" on your own web page is by using the Autodesk Forge platform, and more specifically, the Forge Viewer JavaScript library. And this way you'll also avoid the need to use <iframe> which can be tricky to work with.

    (Btw. Autodesk 360 is a product that's built using the Forge platform as well.)

    Look at https://learnforge.autodesk.io if you're interested in some starting pointers in Forge development. There's a tutorial called View BIM360 & Fusion models that takes you through the development of a web app that can access and view your designs in BIM360, Fusion Team, or Autodesk 360.

    With your Forge app up and running, getting properties of the currently selected component is straightforward. You can simply handle an event when "selection changes", and retrieve the properties of the selected object using the Viewer APIs:

    viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, function () {
      const selectedIds = viewer.getSelection();
      if (selectedIds.length === 1) {
        viewer.getProperties(
          selectedIds[0],
          function onSuccess(props) {
            console.log(props.externalId); // see if the "external ID" extracted by Forge contains the GUID you're looking for
            console.log(props.props); // or if the GUID is included somewhere in the properties
          },
          function onError(err) {
            console.error(err);
          }
        );
      }
    });