【问题标题】:How to Show/View or Read .dwg files on browser如何在浏览器上显示/查看或读取 .dwg 文件
【发布时间】:2017-09-02 15:11:48
【问题描述】:

如何在不使用任何软件的情况下在浏览器上显示或读取 .dwg 文件意味着使用 PHP、jQuery、Javascript 或任何其他编程语言。 为此,我浏览了https://developer.autodesk.com 并创建了一个带有客户端 ID 和客户端密码的应用程序,还创建了 index.html 文件。但在那之后,我陷入了寻找下一个动作以获得所需的“模型衍生 API”。所以请指导我。感谢您给予宝贵的答复。

<!-- The Viewer CSS -->
<link rel="stylesheet" href="https://developer.api.autodesk.com/viewingservice/v1/viewers/style.min.css" type="text/css">

<!-- Developer CSS -->
<style>
    body {
        margin: 0;
    }
    #MyViewerDiv {
        width: 100%;
        height: 100%;
        margin: 0;
        background-color: #F0F8FF;
    }
</style>

<!-- The Viewer will be instantiated here -->
<div id="MyViewerDiv"></div>

<!-- The Viewer JS -->
<script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/three.min.js"></script>
<script src="https://developer.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>

<!-- Developer JS -->
<script>
    var viewer;
    var options = {
        env: 'AutodeskProduction',
        accessToken: '<YOUR_APPLICATION_TOKEN>'
    };
    var documentId = 'urn:<YOUR_URN_ID>';
    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()
        };

        var viewerDiv = document.getElementById('MyViewerDiv');
        viewer = new Autodesk.Viewing.Private.GuiViewer3D(viewerDiv);
        viewer.start(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
    }

    /**
     * Autodesk.Viewing.Document.load() failuire callback.
     */
    function onDocumentLoadFailure(viewerErrorCode) {
        console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
    }

    /**
     * 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);
    }

</script>

【问题讨论】:

    标签: autocad autodesk-forge autodesk-viewer dwg autodesk-model-derivative


    【解决方案1】:

    您可以通过 A360 Viewer 轻松在线测试。

    您指出的代码只是页面,请注意它缺少 TOKEN 和 URN。事实上,按照Viewer tutorial,您会注意到Prepare your file for viewing 教程。

    无论如何,您都需要一个上传和发布翻译作业的后端,我们的github account 有一些示例。

    更新

    无需编程即可展示模型:您可以轻松地在您的网站上分享您的 A360 模型,步骤如下:

    1. 转到A360 并登录(或注册)
    2. 使用现有项目或创建新项目。
    3. 在项目中,单击上传并选择您机器上的文件。翻译过程将自动开始。或者,您可以使用项目中的现有文件。
    4. 在右上角的图标上,单击“共享”选项。
    5. 在弹出窗口中,转到嵌入选项卡,然后选择尺寸。复制 HTML 并粘贴到您的网站上。

    【讨论】:

    • 感谢@Augusto 的回复。但我需要在我的网站上显示 dwg 文件。为此,您能否提供具有正确指南的确切链接,例如,我需要使用哪种类型的扩展创建多少页面以及这些页面如何相互链接以显示 DWG 文件。我在github.com/autodesk-forge 上浏览了 viewer-javascript-extract.spreadsheet/samples/rac_advanced_sample_project.rvt 并没有显示任何内容,所以请给您进一步的回复。
    • 非常感谢@Augusto 的逐步指导。在这里,我可以在我的网站上显示我的 DWG 文件(上传到 myhub.autodesk360.com 并按照共享和获取嵌入代码的步骤)。所有这些都是静态的。但我需要显示动态运行时文件,这意味着我的网站上有多少文件链接,我可以随时打开这些链接。请回复相同的内容。
    • 您可以更改您网站上 IFRAME 标记的 SRC 属性,但这需要一些基本的 HTML/JavaScript 编码...
    • 因为在 autodesk360.com 上上传 dwg 文件后得到 src="myhub.autodesk360.com/ue2b9a926/shares/public/…" 一个字母数字代码,并且仅使用此 src,我可以在我的网站上显示文件视图,但我需要它,如果我会在我的网站上上传任何文件并为该上传的文件创建一个链接,然后单击该文件的链接我可以显示其视图,为此,我是否有必要在 autodesk360.com 上上传所有 dwg 文件或任何在我的网站上查看 dwg 文件而不在 autodesk360.com 上上传或使 src 动态的其他解决方案?请帮助我
    • 嗨@Augusto,我已经在我的本地主机上离线实现了github.com/Autodesk-Forge/forge-boilers.nodejs(由你提供的github.com/autodesk-forge给出)。那么我可以使用 forge-boilers.nodejs-master.zip 代码文件离线显示我自己的 dwg 文件吗?感谢您的回复
    猜你喜欢
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2013-09-16
    • 2023-02-08
    • 2015-04-13
    • 1970-01-01
    相关资源
    最近更新 更多