Copy link to clipboard
Copied
Hello,
This topic is a bit complex, but I will try to explain my problem as well as I can.
I'm trying to export selected assets as .png images with extendscript but some of my art pieces have locked/hidden layers/pageitems which prompts me this message:
Some notes on this:
This is a part from the code which exports the selected asset as an image:
for (var i=0, len=selected_art.length; i < len ; i++) {
var item = selected_art[i]
item.selected = true
doc.fitArtboardToSelectedArt(doc.artboards.length-1)
if(os == WINDOWS){
file_path = OsSpecificFolderPath(immage_trimmer_path + "/" + item.name + ".png")
}
else{
file_path = immage_trimmer_path + "/" + item.name + ".png"
}
var file = new File(file_path);
doc.exportFile(file, ExportType.PNG24, options);
item.selected = false
};
The line that prompts this error is the
which is slightly surprising. I would expect item.selected = true to be the culprit..
In the end all I want is the same functionality as File -> Export selected... without the prompt, is there any way to work around this?
Thanks in advance
I don't understand your code. What is selected_art? Is it the "selection" collection, i.e. the items selected manually? But then locked and invisible items cannot be selected manually. Is is the collection of the members of a selected group? But then the length of such collections is undefined if members are locked or invisible and a loop never begins. So, I'm unble to replicate the error you get.
Anyway, it seems to me that your problem is that you're trying to select items specifically to us
...Copy link to clipboard
Copied
I don't understand your code. What is selected_art? Is it the "selection" collection, i.e. the items selected manually? But then locked and invisible items cannot be selected manually. Is is the collection of the members of a selected group? But then the length of such collections is undefined if members are locked or invisible and a loop never begins. So, I'm unble to replicate the error you get.
Anyway, it seems to me that your problem is that you're trying to select items specifically to use fitArtboardToSelectedArt(). Why not fit the artboards to the items without selecting them? For example:
var items = app.activeDocument.pageItems;
var AB = app.activeDocument.artboards[0];
for (var i = 0; i < items.length; i++) {
AB.artboardRect = items[i].controlBounds;
};
Copy link to clipboard
Copied
Hello Femkeblanco,
Thank you so much for your reply! To clarify; Selected art is indeed the array of manually selected art.
var selected_art = doc.selection;
The locked or hidden art is not on the topmost object, so the user is able to select it, but once I try to fit the artboard too the selected art it notices the hidden/locked child objects of the group.
I never thought about fitting the artboard manually with the bounds! This might be a good solution.
Thanks!