How convert DWG to DXF?

Leonardo_Czuy
Advocate
Advocate

How convert DWG to DXF?

Leonardo_Czuy
Advocate
Advocate

Hello for everyone, 

 

I am trying to convert DWG Files to DXF Files, i am using ODA File Converter, but i wanna use AUTODESK API for this convert, i have this code now but not working.

 

 

/ Função para obter o token de acesso
async function getAccessToken() {
  const response = await axios.post('https://developer.api.autodesk.com/authentication/v1/authenticate', {
    client_id: CLIENT_ID,
    client_secret: CLIENT_SECRET,
    grant_type: 'client_credentials',
    scope: 'data:read data:write data:create bucket:create bucket:read',
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });

  return response.data.access_token;
}

// Função para converter DWG para DXF
async function convertDWGtoDXF(dwgFile) {
  const accessToken = await getAccessToken();

  const response = await axios.post('https://developer.api.autodesk.com/modelderivative/v2/designdata/job', {
    input: {
      urn: dwgFile,
    },
    output: {
      formats: [
        {
          type: 'dxf',
          views: ['2d'],
        },
      ],
    },
  }, {
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json',
    },
  });

  return response.data;
}

 

 

0 Likes
Reply
Accepted solutions (1)
1,377 Views
1 Reply
Reply (1)

norman.yuan
Mentor
Mentor
Accepted solution

When you say you want to use AutoCAD API, do you mean/realize that you need to run AutoCAD? The JavaScript code you post here is irrelevant, because it upload a drawing to a cloud service for the conversion, meaning the app on the user side running your code probably not run inside AutoCAD.

 

If you do want to use AutoCAD API to do the conversion, you need write code as AutoCAD plugin and execute the code INSIDE running AutoCAD session. See this post for the actual code (from @_gile )

 

https://forums.autodesk.com/t5/net/open-dwg-save-as-dxf-with-api-vb-net-or-c/m-p/11495623#M74488 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes