Export DXF script not working within KM

Export Javascript not working within KM. Why?

The JavasScript tests the selection before exporting a DXF. If only one item is selected no DXF is exported.

The script works fine when run directly in Adobe Illustrator, but when triggered from KM it correctly "Groups" a multiple selection but does not export the DXF. What am I doing wrong?

Other versions of this script, without the "Test Selection" portion, are working fine within KM.

Keyboard Maestro Actions.kmactions (2.0 KB)

In the Write Text action you use two KM variables to define the save path.
Are they defined in the macro, when the file is written?

Yes, the "Save Path" variables are used in many other scripts without issue. The portion, below, is unique to this script and I suspect it is causing the issue.

if(doc.selection.length == 1){
alert('No BACK DXF was exported');

Run of ESTK (and with an explicit "Save Path") it works as expected.

Then I would create a new macro with just that in the script to test.
Make it as simple as possible -- don't use a file, just embed the script directly in the Execute AppleScript Action.

Modify the script to process both branches of the if:

if(doc.selection.length === 1){
   var selStr = 'Selection Length was 1');
} else {
  var selStr = 'Selection Length was NOT 1');
}
alert(selStr);

Let us know that that goes.

1 Like

Any time you are having issues, probably the “ignore results” should be the first thing to go - change the Execute action to display the results, that way if it is giving an error, you will see what it is.

Also, add a Read File “/tmp/new.jsx” to Clipboard, and then go to Illustrator and try executing the JavaScript manually (I presume there is a way to do this) and see what results or errors you get.

1 Like

I was able to make this script work from KM by re-selecting the target artwork after "Uniting" it. Running from Illustrator the selection was maintained after "Uniting" the artwork. But when run from KM the selection was lost, negating the remaining script. Reselecting the artwork solved the issue.

var doc = app.activeDocument;
var theLayer = doc.layers;
var selLength = doc.selection.length;
if(selLength < 2){
alert ('No BACK.dxf was Exported');
}else{
if ( app.documents.length > 0 ) {  
app.doScript ("Unite", "AI Actions_KM" ); 
theLayer.getByName('BACK TEXT').hasSelectedArtwork=true;
var options = getOptions(); 
     var type = ExportType.AUTOCAD;  
      var fileSpec = new File("%DND_SaveLocal%/%TrayFileName%_BACK.dxf"); 
      doc.exportFile( fileSpec, type, options );  
    }  

function getOptions() {  
  var exportOptions = new ExportOptionsAutoCAD();  
      exportOptions.exportFileFormat = AutoCADExportFileFormat.DXF;
      exportOptions.exportOption = AutoCADExportOption.MaximumEditability;  
      exportOptions.version = AutoCADCompatibility.AutoCADRelease24;  
      exportOptions.exportSelectedArtOnly = true;
      exportOptions.generateThumbnails = false;     
      exportOptions.unit = AutoCADUnit.Millimeters;  
    return exportOptions;  
}  
}
1 Like