-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>
謝謝@Augusto的回覆。但我需要在我的網站上顯示dwg文件。爲此,請您提供具有適當指導方針的確切鏈接,例如需要使用哪種類型的附加信息創建多少頁面,以及如何將這些頁面鏈接到彼此以顯示DWG文件。我瀏覽過https://github.com/autodesk-forge/上的viewer-javascript-extract.spreadsheet/samples/rac_advanced_sample_project.rvt,它沒有顯示任何內容,所以請給出進一步的回覆。 – Chandana
非常感謝你@Augusto一步一步的指導。在這裏,我可以在我的網站上顯示我的DWG文件(上傳到https://myhub.autodesk360.com,並遵循共享和獲取嵌入代碼的步驟)。所有這些都是靜態的。但是我需要顯示動態運行時間文件,意味着我的網站上有多少文件鏈接,這些都是我可以隨時打開的。請回復相同的。 – Chandana
您可以在您的網站上更改IFRAME標記的SRC屬性,但這需要一些基本的HTML/JavaScript編碼...... –