• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

exporting selected objects to dxf

New Here ,
Mar 16, 2018 Mar 16, 2018

Copy link to clipboard

Copied

I have tried everything to write a script and I cant.  I am not experienced but I copied and pasted with no luck.  can anyone help.  all I need is to quickly export selected objects with one click to a temp folder

here is what I have

try {
if (app.documents.length > 0 ) {


  var destFolder = null;
  destFolder = Folder.selectDialog( 'Select folder for dxf files.', '~' );
  
  if (destFolder != null) {
   var options, i, sourceDoc, targetFile; 

   options = this.getOptions();
       
      for ( i = 0; i < app.documents.length; i++ ) {
       sourceDoc = app.documents; // returns the document object
        
 
    targetFile = this.getTargetFile(sourceDoc.name, '.dxf', destFolder);
  
    sourceDoc.exportFile(targetFile, ExportType.dxf, options);
   }
   alert( 'Documents exported as dxf' );
  }
}
else{
  throw new Error('There are no document open!');
}
}
catch(e) {
alert( e.message, "Script Alert", true);
}

var exportOptions = new ExportOptionsAUTOCAD(); {
var type = ExportType.DXF; 
var file = new File(folder.fsName+"/"+layer.name+".DXF");
                    document.exportFile(file, ExportType.DXF, options);
   exportAutoCADOptions.exportFileFormat = AutoCADExportFileFormat.DXF;  // AutoCADExportFileFormat.DWG   DXF 
  exportAutoCADOptions.exportOption = AutoCADExportOption.PreserveAppearance;  //PreserveAppearance MaximumEditability 
   exportAutoCADOptions.version = AutoCADCompatibility.AutoCADRelease14; 
   exportAutoCADOptions.exportSelectedArtOnly = false; 
   exportAutoCADOptions.convertTextToOutlines = false; 
   exportAutoCADOptions.unit = AutoCADUnit.Millimeters; 
        app.activeDocument.exportFile( fileSpec, type, exportOptions ); 
     return options;
}

/** Returns the file to save or export into.
@Param docName the name of the document to be saved or exported
@Param ext the extension the file extension to be applied
@Param destFolder the output folder
@Return File object
*/
function getTargetFile(docName, ext, destFolder) {
var newName = "";


if (docName.indexOf('.') < 0) {
  newName = docName + ext;
} else {
  var dot = docName.lastIndexOf('.');
  newName += docName.substring(0, dot);

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 17, 2018 Mar 17, 2018

Bonjour,

Gaz factory

Un peu d'ordre ne fait pas de mal !

// JavaScript Document for Illustrator

// elleere Sat, 17 March 2018 20:39:43 GMT

var doc = app.activeDocument;

if ( app.documents.length > 0 ) {

    var destFolder = null;

        destFolder = Folder.selectDialog( 'Sélectionner le dossier des fichiers DXF.', '~' );

    if (destFolder != null) {

      var options = getOptions();

      var type = ExportType.AUTOCAD;

      var fileSpec = new File(destFolder+"/"+doc.name+".dxf"); //  "~/essai.dxf"

      d

...

Votes

Translate

Translate
Adobe
Advocate ,
Mar 17, 2018 Mar 17, 2018

Copy link to clipboard

Copied

Bonjour,

Gaz factory

Un peu d'ordre ne fait pas de mal !

// JavaScript Document for Illustrator

// elleere Sat, 17 March 2018 20:39:43 GMT

var doc = app.activeDocument;

if ( app.documents.length > 0 ) {

    var destFolder = null;

        destFolder = Folder.selectDialog( 'Sélectionner le dossier des fichiers DXF.', '~' );

    if (destFolder != null) {

      var options = getOptions();

      var type = ExportType.AUTOCAD;

      var fileSpec = new File(destFolder+"/"+doc.name+".dxf"); //  "~/essai.dxf"

      doc.exportFile( fileSpec, type, options );

    }

}

//--------

function getOptions() {

  var exportOptions = new ExportOptionsAutoCAD();

      exportOptions.exportFileFormat = AutoCADExportFileFormat.DXF;//DWG  DXF

      exportOptions.exportOption = AutoCADExportOption.PreserveAppearance;

      exportOptions.version = AutoCADCompatibility.AutoCADRelease14;

      exportOptions.exportSelectedArtOnly = true; //export selected objects true

      exportOptions.convertTextToOutlines = false;

      exportOptions.generateThumbnails = true

      exportOptions.unit = AutoCADUnit.Millimeters;

    return exportOptions;

}

de elleere

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 05, 2023 Sep 05, 2023

Copy link to clipboard

Copied

operation not supported on this object

 

Ahmad5C11_0-1693976863836.png

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

If possible, please send the full script code for the community to review. At first glance, there are no problems in these lines and the export will work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Here is the working script

var newDoc = app.documents.add(DocumentColorSpace.RGB);

            // Copy the selected objects one by one to the temporary document
            for (var i = 0; i < doc.selection.length; i++) {
                var selectedObject = doc.selection[i];
                var copiedObject = selectedObject.duplicate(newDoc, ElementPlacement.PLACEATEND);
            }

            // Define the export options for DXF format (as AutoCAD DWG)
            var exportOptions = new ExportOptionsAutoCAD();
            exportOptions.version = AutoCADCompatibility.AutoCADRelease14; // Change the version as needed

            // Define the export file path and name with .dwg extension
            var exportFile = new File("~/Desktop/hello.dwg"); // Change the file path and name as needed
           

            // Export the temporary document as AutoCAD DWG
            newDoc.exportFile(exportFile, ExportType.AUTOCAD, exportOptions);

            // Close the temporary document without saving changes
            newDoc.close(SaveOptions.DONOTSAVECHANGES);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

is it possible to export without creating a new document also when I export again it will override with new content. i'm facing so many issues in debugging

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

In my ExportToDXF script, I am not creating a new document to export selected objects https://github.com/creold/illustrator-scripts/blob/master/md/Export.md#exporttodxf

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

I tried your script dear but, it is not working

Please, check the attached file 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

Result: undefined is correct because it returns nothing in the code. By the way, isn't this document created in Large Canvas mode? I've found that this breaks the PNG export function in ExtendScript.

UPD: I think you have a large canvas. The exportFile method does not work on it. It's ExtendScript bug. I forgot to add a warning about a large canvas to the ExportToDXF script. My article about PNG and large canvas also applies to DXF: https://medium.com/@aiscripts/export-large-canvas-to-png-2b05d4354b66

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 07, 2023 Sep 07, 2023

Copy link to clipboard

Copied

LATEST

yes, I'm working on a large canvas, thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines