How to Show/View or Read .dwg files on browser?

29 views Asked by At
<!-- Load Autodesk Forge Viewer scripts from Autodesk's servers -->


<style>
    #viewer {
        width: 100%;
        height: 500px;
    }
</style>



View DWG


<script>
    const viewerDiv = document.getElementById("viewer");
    const viewButton = document.getElementById("viewDWG");

    const options = {
        env: 'MD20Prod',
        getAccessToken: function(onTokenReady) {
            // You should implement your own authentication to get an access token
            // See Autodesk Forge documentation for details
            const accessToken = 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjY0RE9XMnJoOE9tbjNpdk1NU0xlNGQ2VHEwUSIsInBpLmF0bSI6ImFzc2MifQ.eyJzY29wZSI6WyJkYXRhOnJlYWQiXSwiY2xpZW50X2lkIjoidTdIelhxRzVJNWJYanBTcTRMTnpNYmR5V3FwZUE0aUsiLCJpc3MiOiJodHRwczovL2RldmVsb3Blci5hcGkuYXV0b2Rlc2suY29tIiwiYXVkIjoiaHR0cHM6Ly9hdXRvZGVzay5jb20iLCJqdGkiOiJKTXR4alNIRDlkblp4U3FhWGV5V2VNclEyZXhHVmpBUnJaNzZkTll4dUpsN0VPanRnczd0SUVKZ211NTcxaGlSIiwiZXhwIjoxNjk4MDc4NjE2fQ.mV_43bJ9wOlhxmSiMG0L3mbvA7ooQY_lxqZ8XEjk2Efo0grHCJi7tdm0_JGz6o7RFMxFwkB5pGT8WdTHIsYFd-2pWZJwKVYsSou_yheR4G_zpaIW8WguwZVNQ84ofgqCWnGHw91aRBLiNNxqyp52QjSxd9NA2Lv-uyebzULHgsmOgyai89Ler0doALOhX4aE5PLPXpnRpV1vohSbGYlyKZI6zxXNyD8ygx4smINQVSdYR3A_sMBmyfQIEgAa9BK8DyCDyGlYIOuf2J_BdXN042OOssBhFdfX6dr7int6Nb-VjdT9x-JV7A2EtGFxEOpe_vDSzpEgAEPWDd83junLSQ';
            onTokenReady(accessToken, expireTime);
        }
    };

    const viewer = new Autodesk.Viewing.GuiViewer3D(viewerDiv);

    viewButton.addEventListener("click", function () {
        const documentId = 'http://download.autodesk.com/us/samplefiles/acad/title_block-ansi.dwg'; // Replace with your DWG file's document ID

        Autodesk.Viewing.Initializer(options, function () {
            viewer.start();
            Autodesk.Viewing.Document.load('urn:' + documentId, function (doc) {
                const defaultModel = doc.getRoot().getDefaultGeometry();
                viewer.loadDocumentNode(doc, defaultModel);
            });
        });
    });
</script>

I am trying to display dwg file on browser but its not working please help me someone. I have used Postman to accessToken. I have try all thing but its not working so someone can provide me better version.

0

There are 0 answers