• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

jsfl for exporting symbols from library to PNG

New Here ,
Feb 22, 2024 Feb 22, 2024

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.

 

Erik29276967ml4o_0-1708598727295.png

 

Is this because the jsfl  was made for an older version? Or is there something wrong with the code? 

Thanks for reading!

 

Erik

 

-----

 

function exportLibraryImagesToFiles() {
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;
var count = 0;
 
for (i = 0; i < selectedItems.length; i++) {
sym = selectedItems[i];
if (sym.itemType != "bitmap") {
continue;
}
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++;
}
alert(count + " image(s) exported.");
}
 
exportLibraryImagesToFiles();

Views

184

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Mar 04, 2024 Mar 04, 2024

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
...

Votes

Translate

Translate
Engaged ,
Feb 22, 2024 Feb 22, 2024

Copy link to clipboard

Copied

From what I can see, this code only exports library items of type "bitmap". Perhaps your icons are symbols?

 

 

- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 04, 2024 Mar 04, 2024

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

there's no jsfl for that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 04, 2024 Mar 04, 2024

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();



- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 04, 2024 Mar 04, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2024 Mar 26, 2024

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...)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 27, 2024 Mar 27, 2024

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.


- Vlad: UX and graphic design, Flash user since 1998
Member of Flanimate Power Tools team - extensions for character animation

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2024 Mar 27, 2024

Copy link to clipboard

Copied

LATEST

Thank you very much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines