Copy link to clipboard
Copied
Hello,
I've been searching in this community for a while to to what I described in the title, I have a library full of icons which i gave a proper name. It would be great if I can export a batch with one click of a button.
I found the following script (at the bottom of this post) which I turned into a command.
Found in this topic: https://community.adobe.com/t5/animate-discussions/exporting-graphics-from-the-library/m-p/10870471
I select my library items --> then click the command --> select a specific folder --> save.
Then I get the message 0 image(s) exported.
Is this because the jsfl was made for an older version? Or is there something wrong with the code?
Thanks for reading!
Erik
-----
Here is the revised code. Since there is no method for exporting selected library items, we have to temporarily place them on the stage, export them, and then delete them.
function exportLibraryImagesToFiles() {
if( parseInt( fl.version.split(" ")[1].split(",")[0] ) < 12 ){
alert( "This command works with Flash CS6 and above." )
return;
}
var doc = fl.getDocumentDOM();
if ( !doc ) return;
var selectedItems = doc.library.getSelectedItems();
if ( !selectedItems.length ) return;
v
...
Copy link to clipboard
Copied
From what I can see, this code only exports library items of type "bitmap". Perhaps your icons are symbols?
Copy link to clipboard
Copied
Hi Vladin,
Thank you for the reply!
It's true, the library is filled with symbols (graphics consisting of 1 frame). I'm not trained in reading the code, so I appreciate you taking a look. Meanwhile, I've manually exported the items (right-click -> export PNG-sequence). This results in a PNG with the correct name (the same name as the one given to the graphic in the library). That's actually what I want, but for 100 symbols at once. Could this still be achieved by tweaking the jsfl file a bit?
Copy link to clipboard
Copied
there's no jsfl for that.
Copy link to clipboard
Copied
Here is the revised code. Since there is no method for exporting selected library items, we have to temporarily place them on the stage, export them, and then delete them.
function exportLibraryImagesToFiles() {
if( parseInt( fl.version.split(" ")[1].split(",")[0] ) < 12 ){
alert( "This command works with Flash CS6 and above." )
return;
}
var doc = fl.getDocumentDOM();
if ( !doc ) return;
var selectedItems = doc.library.getSelectedItems();
if ( !selectedItems.length ) return;
var folder = fl.browseForFolderURL( "Choose an output directory." );
if ( !folder ) return;
var i, t, sym, bmpName, xPath, count = 0;
for( i = 0; i < selectedItems.length; i++ ){
sym = selectedItems[ i ];
if ( sym.itemType === "bitmap" ) {
bmpName = sym.name.split("/").pop();
// strip original extension
t = bmpName.lastIndexOf(".");
if (t != -1 && ["jpg", "jpeg", "png", "gif", "bmp", "psd"].indexOf(bmpName.substr(t + 1).toLowerCase()) != -1) {
bmpName = bmpName.substr(0, t);
}
// do the thing
sym.exportToFile( folder + "/" + bmpName + "." + ( sym.compressionType == "photo" ? "jpg" : "png" ) );
count++;
}else{
if( sym.itemType === "graphic" || sym.itemType === "movie clip" ){
doc.library.addItemToDocument( {x:0, y:0}, sym.name );
xPath = folder + "/" + sym.name.split( "/" ).pop() + ".png";
doc.exportInstanceToPNGSequence( xPath, 0, sym.timeline.frameCount );
doc.deleteSelection();
count += sym.timeline.frameCount;
}
}
}
alert( count + " image(s) exported." );
}
exportLibraryImagesToFiles();
Copy link to clipboard
Copied
Excellent! I will try this out as soon as I'm in Animate again.
Thanks so much for taking the time.
Copy link to clipboard
Copied
Hi Vlad,
Your code works beautifully. Thank you very much. I have a final question for this one. When the code places the symbol on stage, is it possible to place it twice as big (or 3.56 times or anything).
(...Or do you export the image from inside the symbol? Which would mean ((among other things) strokes etc will stay at the same strokewidth when scaling...)
Copy link to clipboard
Copied
Hi,
In order to scale your symbols before export, you need to add just two lines of code:
1. After the line
if ( !folder ) return;
put this line:
var sf = parseFloat( prompt( "Scale Factor: " ) ) || 1;
2. And after the line
doc.library.addItemToDocument( {x:0, y:0}, sym.name );
put this line:
doc.scaleSelection( sf, sf );
That should do the trick.
Copy link to clipboard
Copied
Thank you very much!