Copy link to clipboard
Copied
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
}
//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');
Copy link to clipboard
Copied
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. 😃
Copy link to clipboard
Copied
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?!?
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
Aha, I did not even know about it until now, but it's been in since 2018 and the types for Adobe reflects the omv from 2015! https://community.adobe.com/t5/illustrator/what-s-new-in-illustrator-scripting-cc2018/td-p/9422236
Other than the ESTK OMV, you can try to use the VSCode ESTK-debugger extension and examine the variables panel content to see if it displays any useful information.