-1

如何在不使用任何软件的情况下在浏览器上显示或读取.dwg文件意味着使用PHP,jQuery,Javascript或任何其他编程语言。 为此,我已经通过https://developer.autodesk.com并创建了一个具有客户端ID和客户端密码的应用程序,并创建了index.html文件。但之后,我陷入了寻找下一个需要“模型衍生API”的运动。所以请引导我一样。感谢您的宝贵回应。如何在浏览器上显示/查看或读取.dwg文件

<!-- 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> 

回答

0

您可以轻松地在网上A360 Viewer测试它。

您指出的代码只是页面,请注意它是如何遗漏TOKEN和URN的。事实上,在Viewer tutorial之后,您会注意到一个Prepare your file for viewing教程。

在任何情况下,您都需要后端上传和翻译作业,我们在github account上有一些样品。

更新

显示模式,无需编程:您可以轻松地在网站上分享您的A360机型,这里的步骤:

  1. 转到A360和登录(或注册)
  2. 使用现有项目或创建一个新项目。
  3. 在项目中,点击上传并选择您的机器上的文件。翻译过程将自动开始。或者你可以在你的项目中使用现有的文件。
  4. 在右上角的图标上点击“分享”选项。 Share icon
  5. 在弹出框中,转到嵌入选项卡,然后选择大小。复制HTML并粘贴到您的网站上。 Embed HTML code
+0

谢谢@Augusto的回复。但我需要在我的网站上显示dwg文件。为此,请您提供具有适当指导方针的确切链接,例如需要使用哪种类型的附加信息创建多少页面,以及如何将这些页面链接到彼此以显示DWG文件。我浏览过https://github.com/autodesk-forge/上的viewer-javascript-extract.spreadsheet/samples/rac_advanced_sample_project.rvt,它没有显示任何内容,所以请给出进一步的回复。 – Chandana

+0

非常感谢你@Augusto一步一步的指导。在这里,我可以在我的网站上显示我的DWG文件(上传到https://myhub.autodesk360.com,并遵循共享和获取嵌入代码的步骤)。所有这些都是静态的。但是我需要显示动态运行时间文件,意味着我的网站上有多少文件链接,这些都是我可以随时打开的。请回复相同的。 – Chandana

+0

您可以在您的网站上更改IFRAME标记的SRC属性,但这需要一些基本的HTML/JavaScript编码...... –