我在 Autodesk 中加载了一个 Revit 模型。我想知道在加载视图时如何缩放到模型的特定对象。是否可以使用API?
我已经成功测试了该功能selectItemById
。使用函数获取主对象的 id viewer.bubble.search(av.BubbleNode.MODEL_NODE);
。我不知道如何获取模型中每个元素的 ID,然后放大它。
这是我用来加载模型的代码:
var viewer;
var options = {
env: 'AutodeskProduction',
accessToken: 'aaaaaaaaaaaaaaaaaaa'
};
var documentId = 'urn:bbbbbbbbbbbbbbbbbbbbbbbbbb';
Autodesk.Viewing.Initializer(options, function onInitialized(){
Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});
/**
* Autodesk.Viewing.Document.load() success callback.
* Proceeds with model initialization.
*/
function onDocumentLoadSuccess(doc) {
// A document contains references to 3D and 2D viewables.
var viewables = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), {'type':'geometry'}, true);
if (viewables.length === 0) {
console.error('Document contains no viewables.');
return;
}
// Choose any of the avialble viewables
var initialViewable = viewables[0];
var svfUrl = doc.getViewablePath(initialViewable);
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath()
};
viewer = new Autodesk.Viewing.ViewingApplication('MyViewerDiv');
viewer.registerViewer(viewer.k3D, Autodesk.Viewing.Private.GuiViewer3D);
viewer.loadDocument(documentId, onDocumentLoaded);
var style3D = "height: 60%; width: 65%; overflow: hidden;";
$('.adsk-viewing-viewer').attr('style', style3D);
}
/**
* Autodesk.Viewing.Document.load() failuire callback.
*/
function onDocumentLoadFailure(viewerErrorCode) {
console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
}
function onDocumentLoaded(lmvDoc) {
var modelNodes = viewer.bubble.search(av.BubbleNode.MODEL_NODE); // 3D designs
var sheetNodes = viewer.bubble.search(av.BubbleNode.SHEET_NODE); // 2D designs
var allNodes = modelNodes.concat(sheetNodes);
}