Can't restore viewer'state while loading markups - autodesk-forge

I am using Autodesk.Viewing.MarkupCore extension to create markups then I store viewer'state and the svg string in my database. When I try to show the markups on a layer, the restoreState function doesn't seem to work . It just displays the markups with the current state of the viewer.
Here is the three lines of code:
markup.show();
markup.viewer.restoreState(viewerStatePersist);
markup.loadMarkups(markupsPersist, "layerName");
When I comment the first line (markup.show() ) I have the desired state without the markups.

Related

Autodesk Forge how to save and show Markups

response data for svg markups
markups in model
I want to save all svg Markups on model and show them.
I try to save Markups with this code
```markupsPersist = markup.generateData();
viewerStatePersist = markup.viewer.getState();
markup.viewer.restoreState(viewerStatePersist);```
and try to get it with this
markup.viewer.restoreState(viewerStatePersist);
markup.show();
markup.loadMarkups(markupsPersist, "markups-svg");
but Markups dont appear.
You should also call showMarkups after loading them using loadMarkups.

Autodesk forge Markups Core

I have a markup extension in Autodesk Forge Viewer for 3D models. I have problems removing only one markup. I want to know if it is possible to show annotations in edit mode or delete markups in show mode. When I try to show markups in editing mode, I see a warning that "markups cant be showed in editing mode."
Does anyone know how to solve this problem?
Edit
And to remove a specific markup from a layer after they are loaded try:
markExt.svgLayersMap['layerId'].markups[index].destroy()
Leave the editmode before showing markups - (in response to user input) you can programmatically re-enter editmode once the markups are shown:
ext.leaveEditMode()
ext.loadMarkups(asb,'233') //or ext.showMarkups(layerID)
ext.enterEditMode()
And to remove markups try:
ext.markups[0].destroy()
show annotations in edit mode
Not exactly sure what you are trying to achieve here? But you can create text markup programmatically - say for exp:
const styleObject = Autodesk.Viewing.Extensions.Markups.Core.Utils.createStyle(['font-size'], window.ext);
styleObject['font-size'] = 100;
(new Autodesk.Viewing.Extensions.Markups.Core.CreateText(window.ext, 2333, {x:20,y:20}, {x:100,y:100},'233', styleObject)).execute()
or delete markups in show mode.
And in show mode if the markups are loaded you will need to hide on their layer level and wouldn't be able to hide a specific markup - you may fine tune this by separating them to different layers

Auto desk - Forge Viewer - Markup - am not able to get markups array in markup extension while loading markups

While loading markups, I am not able to get markups array from markup extension as referneced in below code, actually I need client position coordinates of the loaded markup. In below code am getting markups array empty. But while drawing a new markup, we always have markup array filled.
Please advise
markup.viewer.restoreState(viewState);
markup.loadMarkups(svgTxt, "layerName")
var pos = markup.markups[0].getClientPosition()
Since you're not editing the layer you specified, the markupExt.markups will not contain anything. Please use this instead:
const activeLayerMarkup = markupExt.svgLayersMap[markupExt.activeLayer]
activeLayerMarkup.markups[0].getClientPosition()
Or try to edit the layer
markupExt.loadMarkups(svgTxt, 'layerName')
markupExt.enterEditMode('layerName')
markup.markups[0].getClientPosition()

BIM Viewer Markup - Can we edit saved markups or is it only supports view?

Can we edit saved markups which we draw on a viewer?
Does it only support view using restoreState and loadMarkups functions?
Or is there anyway I can update the created and saved markups as my functionality requires reviewer User should be able to update this markups.
var markupsPersist = markup.generateData()
// current view state (zoom, direction, sections)
var viewerStatePersist = markup.viewer.getState()
// finish edit of markup
markup.leaveEditMode()
// hide markups (and restore Viewer tools)
markup.hide()
// restore the view to the state where the markups were created
markup.viewer.restoreState(viewerStatePersist)
// show markups
markup.show();
// show the markups on a layer
markup.loadMarkups(markupsPersist, "layerName")
Of course you can access the markups via markupExt.markups and for example you can edit the text markup with below:
const textMarkup = markupExtension.markups[0]; //access the existing markups via markupExtensionObject.markups
textMarkup.setText('new text');
markupExtension.leaveEditMode();
markupExtension.enterEditMode() //be sure to re-enter edit mode for the changes to take effect
I ran into this this scenario too and you can edit a saved markup. You may need to store your markup state to your own database to be accessed and restored later by the Reviewer. Here is a sample that shows this functionality.
https://forge-rcdb.autodesk.io/configurator?id=598d7ec14cabf2c1f4dec948
Here is blog post discussing this as well.
https://forge.autodesk.com/blog/high-performance-3d-markups-pointcloud-forge-viewer

How to restore viewer state directly from MarkupEdit or MarkupView mode?

With reference of https://forge.autodesk.com/cloud_and_mobile/2016/02/playing-with-the-new-view-data-markup-api.html, I am implementing 2D markup feature in forge viewer.
I'm using Autodesk.Viewing.MarkupsCore library to draw annotations over model in forge viewer. For that I'm loading Autodesk.Viewing.MarkupsCore extension as _markupsExtension .
I tried drawing some markup annotation and saved viewer state. When I tried loading these previously drawn annotations, It failed to restore viewer state, but it was loading annotations data properly.
// To draw and save markup
viewer.loadExtension("Autodesk.Viewing.MarkupsCore").then(function(markupExt) {
_markupsExtension = markupExt;
_state = _markupsExtension.viewer.getState();
_markupsExtension.hide();
_markupsExtension.enterEditMode();
//From now on, while in EditMode, the user will be drawing text boxes
_data = _markupsExtension.generateData(); //Annotations data can be generated
_state = _markupsExtension.viewer.getState(); //to store viewer state information
_markupsExtension.leaveEditMode();
viewer.unloadExtension("Autodesk.Viewing.MarkupsCore"); //User can navigate within model
});
// To load previously drawn markup
viewer.loadExtension("Autodesk.Viewing.MarkupsCore").then(function(markupExt) {
_markupsExtension = markupExt;
_markupsExtension.leaveEditMode();
_markupsExtension.show();
_markupsExtension.viewer.restoreState(_state); //it fails to restore state
_markupsExtension.viewer.impl.invalidate(true);
_markupsExtension.loadMarkups(_data, 'aaa'); //loads markup data while keeping viewerstate unchanged.
});
Why does it fail to restore state while being in markup viewing mode?
What is difference between _markupsExtension.viewer.restoreState(_state) and viewer.restoreState(_state)
================================ EDITED =============================
Is there any way where I could stay within editing mode/viewing mode and change viewer's state?
I am saving all markups in a list view in different sessions or file per session (referring https://forge.autodesk.com/cloud_and_mobile/2016/02/playing-with-the-new-view-data-markup-api.html ).
e.g. 1) I moved model to the top and drawn arrow pointing to particular object and I saved it with name "MarkupA.json".
2) I moved model to front and zoomed it out so that it went far from camera. Then I drawn Square markup and stored it with name "MarkupB.json".
3) Then again I kept model to default iso (home) mode and drawn text annotation and saved it with name "MarkupC.json".
All these markups are listed in the UI panel like a tree. So when am clicking on any particular name, that markup and its model viewer state has to get restored without change in any markup mode.
I have checked this similar functionality in bim360. When I stored different markups in BIM360, it stored all markups in its database and small thumbnail screenshot appeared for its relevant markup card. I viewed all markups in markup panel or comment panel.
When I clicked on specific thumbnail, every markup appeared with appropriate stored viewer state.
I am trying to get similar functionality in forge viewer using new Markups core extension and customised its markup code to store states with markups. When I tried to load each markup, it seems like markup is getting loaded but its viewer state is not able to get restored neither in edit mode nor in viewing mode. I understood that restoring state is not possible if we are in markups mode. But what if I want to show the previously stored drawn markup on particular view?
The workaround which I tried to switch between markup is as follow,
On click of another markup -
a) leave viewing mode
b) restore model with stored state
c) enter viewing mode.
d) load its markup svg.
The issue with this is it is taking too much time taking too much time to reload markup with restored state.
Can you please tell me if we have any other workaround or approach to achieve loading and restoring markup and its viewer state synchronously?
Why does it fail to restore state while being in markup viewing mode?
When in markup mode the camera is locked so you will need to drop out of edit mode before restoring Viewer states and then go back.
What is difference between _markupsExtension.viewer.restoreState(_state) and viewer.restoreState(_state)
No difference as _markupsExtension.viewer is just a reference of the plugin to the master Viewer object