Skip to main content
sais49882722
Participant
February 16, 2018
Question

Unable to export last asset as PNG out of a selection!

  • February 16, 2018
  • 1 reply
  • 1079 views

Hi

I had wrote a script to export my selection as PNG through asset export. But the last selection is not exporting as PNG throwing an error. When it comes to SVG in the same script its working fine. Ill paste the sample script here, please correct me if I had committed some mistake.

I reiterate SVG export working fine in below script its only problem with PNG.

var doc = app.activeDocument;

var selectedObjects = doc.selection;

//remove all assets

if (doc.assets.length>0){

doc.assets.removeAll();

}

//Adding selection to assets panel

for (var i=0; i<selectedObjects.length; i++){

     var currentObject = selectedObjects;

     doc.selection = currentObject;

     var currentAsset = doc.assets.addFromSelection ();

     currentAsset.assetName = currentObject.name;

}

//Collecting new assets

var assets = doc.assets;

//Query Asset ID's

var assetArray = [];

for (var z=0; z<assets.length; z++){

    assetArray=assets.assetID;

    }

//Creation of destination folder

var destFolder = Folder("C:/Users/Xxxxx/Desktop/script/export/Icon_01");

if(!destFolder.exists) destFolder.create();

//Defining assets to export

var whatToExport = new ExportForScreensItemToExport();

whatToExport.assets = assetArray;

whatToExport.artboards ="";

//As SVG

var svgParams = new ExportForScreensOptionsWebOptimizedSVG();

doc.exportForScreens(destFolder, ExportForScreensType.SE_SVG, svgParams, whatToExport);

//As PNG

var pngParams = new ExportForScreensOptionsPNG24();

doc.exportForScreens(destFolder, ExportForScreensType.SE_PNG24, pngParams, whatToExport);

alert('done');

This topic has been closed for replies.

1 reply

Disposition_Dev
Legend
February 16, 2018

According to the OMV, the ExportForScreensItemToExport class (the variable whatToExport, in your example above) requires an integer, but you're passing an array.

You may have to loop that array and run the exportForScreens function on each element of the array.

Hope this helps. =)

schroef
Inspiring
May 25, 2021

Do you know where i can find info about exportforscreen regarding scripting. Its now 2021 and the docs still dont contain any info about it. It does have info about clouddocs, a new feature, but nothing for exportforscreens?!?

Disposition_Dev
Legend
May 26, 2021

no, i'm sorry i don't. the only place i did know of was the OMV in ESTK. But ESTK is dead and you can't even get it on modern operating systems at all. Makes me think i should have cataloged that information when i had it.. doh!

 

Hopefully someone else knows where to find that stuff...