gpt4 book ai didi

javascript - 如何使用纯 Javascript 在查看器中离线显示 2d (.dwg) 文件 Autodesk

转载 作者:行者123 更新时间:2023-12-03 01:41:44 26 4
gpt4 key购买 nike

我正在尝试使用纯 Javascript 在离线模式下在查看器中显示 2d 文件。我已经使用 https://extract.autodesk.io/ 上传并提取了 dwg 。解压后的文件包含许多 json.gz 文件和一个文件夹。在此文件夹中,它包含 list 、元数据(json.gz 文件)和一个 .f2d 文件

我已将此文件位置指定给我的查看器选项

var docs = [{ "path": "./{foldername}/primaryGraphics.f2d", "name": "2D view" }];
var options = { 'docid': docs[0].path, env: 'Local' };

我的查看器初始化是

viewer = new Autodesk.Viewing.Private.GuiViewer3D(document.getElementById('MyViewerDiv'), {}); 
Autodesk.Viewing.Initializer(options, function () {
viewer.initialize();
viewer.loadModel(options.docid);
});

它在查看器中向我显示错误消息,显示“我们无法显示您正在查找的项目。它可能尚未处理......”并给我错误代码 5(指定类型无效)。

请帮忙。

最佳答案

请确保您已完全下载 DWG 中所有提取的可见气泡,并且要加载的模型的路径正确,因为错误代码 5 代表 NETWORK_FILE_NOT_FOUND

我刚刚测试了这个blocks_and_tables_-_metric.dwg来自AutoCAD Sample Files使用下面的代码片段,它工作得很好。

var options = {
env: 'Local',
};

var doc = { 'rootFolder': 'Model', 'path': '29c9e407-f76f-a1c0-0972-dcb5b496fff9_f2d/primaryGraphics.f2d', 'name': '2D view' };

var viewerDiv = document.getElementById( 'MyViewerDiv' );
var viewer = new Autodesk.Viewing.Private.GuiViewer3D( viewerDiv );


Autodesk.Viewing.Initializer(options, function() {
if( viewer.initialize() != 0 ) return console.error( 'Failed to initialize viewer' );

var basePath = getCurrentBaseURL();
var modelFolderPath = basePath + doc.rootFolder + '/';
var modelFilePath = modelFolderPath + doc.path;
var modelOptions = {
sharedPropertyDbPath: modelFolderPath
};

viewer.loadModel( modelFilePath, modelOptions, onLoadModelSuccess, onLoadModelError );
});

function getCurrentBaseURL() {
var basePath = '';
var lastSlash = document.location.href.lastIndexOf( '/' );

if( lastSlash != -1 )
basePath = document.location.href.substr( 0, lastSlash + 1 );

return basePath;
}

/**
* viewer.loadModel() success callback.
* Invoked after the model's SVF has been initially loaded.
* It may trigger before any geometry has been downloaded and displayed on-screen.
*/
function onLoadModelSuccess( model ) {
console.log( 'onLoadModelSuccess()!' );
console.log( 'Validate model loaded: ' + ( viewer.model === model ) );
console.log( model );
}

/**
* viewer.loadModel() failure callback.
* Invoked when there's an error fetching the SVF file.
*/
function onLoadModelError( viewerErrorCode ) {
console.error( 'onLoadModelError() - errorCode:' + viewerErrorCode );
}

blocks_and_tables_-_metric.dwg提取模型的文件结构如下图所示: enter image description here

我使用的2D模型的文件结构是: enter image description here

关于javascript - 如何使用纯 Javascript 在查看器中离线显示 2d (.dwg) 文件 Autodesk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50815746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com