Is it possible or there is any way to load Model through URN instead of URL.
we can load the model through URL :
this.viewer.loadModel(url, options) -> Here i know the url of the SVF
Is there any possibility to load the model using the URN, But in my case I know only URN of the svf.
In regular way,
We are loading the document using the URN of the uploaded file, on Document load success then we are loading the viewables.
var documentId = 'urn:dXJuOmFkc2sub2JqZ3Q6cGxuLW1vZGVN0L0NhZGFjR3JvdXBIUSUyMDIwMTkucnZ0';
Autodesk.Viewing.Initializer(options, function onInitialized(){
viewerApp = new Autodesk.Viewing.ViewingApplication('MyViewerDiv');
viewerApp.registerViewer(viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D);
viewerApp.loadDocument(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
function onDocumentLoadSuccess(doc) {
var viewables = viewerApp.bubble.search({type:'geometry', role:'3d',name:'blahblah'});
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
// Choose any of the avialble viewables
console.log(viewables[0].data);
console.log(doc.getViewablePath(viewables[0].data));
viewerApp.selectItem(viewables[0].data, onItemLoadSuccess, onItemLoadFail);
}
From above code, based on the URN of the uploaded OBJ, it is getting the manifest and loading the viewable, But In our scenario, we are doing that part at server side and getting the URN of the SVF.
But in our scenario, We have the URN of the SVF file. Is there any way to load the Model Using SVF URN.
I saw one possiblity is that appending
"https://developer.api.autodesk.com/derivativeservice/v2/derivatives/"
to my urn and calling the
viewer.loadModel(url)
Is loading the Model, But it is again a maintenance work, When there is a change in that URL from forge side we need to update it again.
Is there anyway from javascript to get the path of the model based on the URN?
To load by URN of the SVF simply pass in its, with the rest of your Viewer's environment kept the same as you would for URN of the document:
// get the URN of the SVF from the manifest, e.g. `urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2JzYjIzMzMzL3NiYmJiYmIuZHdn%2Foutput%2F3a65ae5a-804e-b91b-11d1-5bc44f41866f_f2d%2F3d.svf`
Autodesk.Viewing.Initializer({
'env' : 'AutodeskProduction', getAccessToken: onGetAccessToken
}, function onInitialized(){
//...
viewer.start();
viewer.loadModel('https://developer.api.autodesk.com/derivativeservice/v2/derivatives/urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2JzYjIzMzMzL3NiYmJiYmIuZHdn%2Foutput%2F3a65ae5a-804e-b91b-11d1-5bc44f41866f_f2d%2F3d.svf')
});
BTW the viewerApplication API has been deprecated as of v7 so I'd recommend to follow this migration guide here to upgrade to v7 in order to get all those new features and fixes ...
Related
I need to open a PDF file from BIM 360 Docs on the Viewer selecting a specific page. I'm currently opening the PDF on the Viewer but I don't know how to select a page.
Adding on to my comment, you can get a list of all available viewables when using the onDocumentLoadSucces callback. This callback is triggered after initting the viewer and loading the first Urn(model) into the viewer. You can look into more functionality on bubble nodes in the documentation
Example in angular/typescript:
private onDocumentLoadSucces(viewerDocument: Autodesk.Viewing.Document) {
// Default viewable
let defaultModel = viewerDocument.getRoot().getDefaultGeometry();
// list of all viewables in this model
this.viewables = viewerDocument.getRoot().search({'type':'geometry'});
// We load in the default viewable here but we could choose to load any viewable
// in this.viewables
this.viewer.loadDocumentNode(viewerDocument, defaultModel);
console.log('model changed');
}
I assume you are using the PDF extension to directly load and view PDF. If so, you can tell it the page number in the loadModel call. For example:
viewer.loadModel( pdf, {page:2});
Here's the whole function:
function initializeViewer( pdf ) {
var options = {
env: "Local",
useADP: false
}
Autodesk.Viewing.Initializer(options, () => {
viewer = new Autodesk.Viewing.Private.GuiViewer3D(document.getElementById('viewer3D'));
viewer.setTheme("light-theme");
viewer.start();
if (!pdf) return;
viewer.loadExtension('Autodesk.PDF').then( () => {
viewer.loadModel( pdf, {page:2});
});
});
};
The docs mention this here:
https://forge.autodesk.com/en/docs/viewer/v7/reference/Extensions/PDFExtension/
and there is also an example I used to test from a blog post here:
https://forge.autodesk.com/blog/fast-pdf-viewingmarkup-inside-forge-viewer
hope it helps
I want to add new Autodesk Forge Minimap3DExtension to my forge viewer, but i can't get AECModelData with doc.downloadAecModelData().
I try to get data with this code is it right?
var viewables = viewerApp1.bubble.search({'type':'geometry'});
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
//explicitly call downloadAecModelData of viewer document.
doc.downloadAecModelData()
}````
I also try to get data with bubbleNode, but got only errors.
Only RVT files from Revit 2018 and later will produce the AecModelData. Please check your RVT file version. If it is supported, you can use either way below to get AecModelData
// From document
await doc.downloadAecModelData()
// From bubble
await Autodesk.Viewing.Document.getAecModelData(viewer.model.getDocumentNode())
It seems to be possible to view and navigate Revit Drafting View(s) graphics using the Forge API's based on how the BIM 360 Document Management web browser interface does it with our own Revit (.rvt) model having published Drafting Views where it list the 2D Drafting Views (thumbnails) in the left panel and the actual detail of the selected Drafting View in the right viewer. We do have one of the more recent Forge API Viewer examples setup and working, and tried modifying some of its code, but is seems to be designed to only work with Models (.rvt) components in the left panel, and its not obvious where and what code needs to be modify to change it to list 2D sheets/views like the Document Manager does. We are having difficulty locating a Forge API example that shows how to do this using the Forge API's and would like to obtain a working example that illustrates how to do this using the Forge API's?
Tried changing the ViewingApplication.bubble.search to include role 2d type view
function onDocumentLoadSuccess(doc) {
// We could still make use of Document.getSubItemsWithProperties()
// However, when using a ViewingApplication, we have access to the
*bubble** attribute,
// which references the root node of a graph that wraps each object from the Manifest JSON.
//var viewables = viewerApp.bubble.search({ 'type': 'geometry' });
var viewables = viewerApp.bubble.search({ 'role': '2d', 'type': 'view' });
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
The drafting view is kind of 2d role geometry, Therefore you can load it with the same way for the 2D view.
const rootItem = doc.getRoot();
const filter = { type: 'geometry', role: '2d' };
const viewables = rootItem.search( filter );
if( viewables.length === 0 ) {
return onLoadModelError( 'Document contains no viewables.' );
}
// Take the first viewable out as the loading target
const initialViewable = viewables[0];
const loadOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath()
};
viewer.loadDocumentNode(doc, initialViewable.data, modelOptions).then(onItemLoadSuccess).catch(onItemLoadFail);
To show a list of views like the BIM360 Docs, you could load Autodesk.DocumentBrowser extension. It will show viewable items on it, and just click on it to switch. See below snapshot:
I am trying to load a trained keras model into web browser using tensorflowjs.
I was able to convert the keras model to tensorflowjs model but unable to load model in chrome extension.
My background.js code to load model
async function app() {
alert('Loading model..');
model = await loadModel("model.json");
alert('Sucessfully loaded model');
}
chrome.runtime.onInstalled.addListener(function(details) {
alert("extension loaded");
chrome.tabs.executeScript(null,
{file:"https://cdn.jsdelivr.net/npm/#tensorflow/tfjs#1.0.0/dist/tf.min.js"});
app();
});
THe url "https://cdn.jsdelivr.net/npm/#tensorflow/tfjs#1.0.0/dist/tf.min.js" is added in permissions key in manifest file.
When i try to laod the extension it fails givind message loadModel is not defined.
Any suggestions on fixing this issue?
loadModel is not defined.
1 - Make sure that the script is loaded in the background process of the tabs
2 - You need to use tf.loadModel() instead of loadModel()
I upgraded the forge viewer version of my solution to 6.* to utilize the latest released feature "Document browser extension" as it mentions here
This extension doesn't appear for me, please help.
I got it to work after some experimenting.
Here is my workflow in case you still need it.
First, initialize the viewer:
// initialize the viewer
Autodesk.Viewing.Initializer(adOptions, () => {
// when initialized, call loading function
this.loadDocument(encodedUrn);
});
Then, load your document in the function called above:
// load the document from the urn
Autodesk.Viewing.Document.load(
encodedUrn,
this.onDocumentLoadSuccess,
this.onDocumentLoadFailure,
);
In the success callback you can now do the following:
onDocumentLoadSuccess(doc) {
// get the geometries of the document
const geometries = doc.getRoot().search({ type: 'geometry' });
// Choose any of the available geometries
const initGeom = geometries[0];
// and prepare config for the viewer application
const config = {
extensions: ['Autodesk.DocumentBrowser'],
};
// create the viewer application and bind the reference of the viewerContainer to 'this.viewer'
this.viewer = new Autodesk.Viewing.Private.GuiViewer3D(
this.viewerContainer,
config,
);
// start the viewer
this.viewer.start();
// load a node in the fetched document
this.viewer.loadDocumentNode(doc.getRoot().lmvDocument, initGeom);
}
I hope this will make it work for you as well. What helped me was the reference to the loadDocumentNode function in this blog post.