skip to Main Content

I am attempting to insert markups data into a cloud database by utilizing Autodesk.Viewing.TOOL_CHANGE_EVENT. However, it appears that this event is triggered before the markups data is extracted via `markupsExtension.generateData()

//Make sure the extentions loaded
 viewer?.current?.loadModel(path.urlPath, {}, function onSuccess() {
 viewer?.current?.loadExtension("Autodesk.Viewing.MarkupsCore");
viewer?.current?.loadExtension("Autodesk.Viewing.MarkupsGui");
}); 

 React.useEffect(() => {
    viewer?.current?.addEventListener(
      Autodesk.Viewing.TOOL_CHANGE_EVENT,
      (x) => {
        if (x.active && x.toolName === "markups.core") {
          getAllMarkupsFromDatabase(viewer.current);
        } else if (!x.active && x.toolName === "markups.core") {
        //here the event close before getting the data
          saveMarkupsToDatabase(viewer.current);
        }
      }
    );
  }, [isGeometryLoaded]);
  
//Save the markups data.
async function saveMarkupsToDatabase(viewer: any) {
  const markupsExtension = await viewer.loadExtension(
    "Autodesk.Viewing.MarkupsCore"
  );

  const markupsData = await markupsExtension.generateData();
  console.log({ markupsData });

  //Save to database

   localStorage.setItem("markups", markupsStringData);
 

}

I am uncertain if there is a way to obtain the data prior to closing the markups extension.

2

Answers


  1. Chosen as BEST ANSWER

    Solved,

    //I used:
      viewer?.current?.loadExtension("Autodesk.Viewing.MarkupsCore").then((ext) =>
        //@ts-ignore
        ext.addEventListener(
          //@ts-ignore
          Autodesk.Viewing.Extensions.Markups.Core.EVENT_EDITMODE_LEAVE,
          console.log
        )
      );
      
    //insted of:
    viewer?.current?.addEventListener(
          Autodesk.Viewing.TOOL_CHANGE_EVENT,
          async (x) => {
            const extension = await viewer?.current?.loadExtension(
              "Autodesk.Viewing.MarkupsCore"
            ))
           if (!x.active && x.toolName === "markups.core" && markupsData?.id) {})


  2. I think Adam and I solved this with you, during the Copenhagen Accelerator, right ?

    Let me know if it’s all solved.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search