How convert DWG to DXF with AutoDesk API?

46 Views Asked by At

It's been a while since I've been trying to find something to convert DWG to DXF. I'm using the ODA File Converter, but I don't think it's the best route. I'm also trying to use the Autodesk API.

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

1

There are 1 best solutions below

0
Naveen Kumar T On

Apologies for the inconvenience. As I am unable to provide a comment, I am submitting my suggestion in the form of an answer.

It seems you are utilizing the Model Derivative API for converting your DWG file into DXF format. However, please note that the Model Derivative API currently supports conversion of DWG files exclusively to SVF, SVF2, and Thumbnail formats. Regrettably, converting DWG files to DXF format through the Model Derivative API is not presently feasible.

Please take a look at this below link

https://aps.autodesk.com/en/docs/model-derivative/v2/developers_guide/supported-translations/

I suggest considering the AutoCAD Design Automation API or the Inventor Design Automation API for achieving the conversion from DWG to DXF.