Skip to main content
24styx
Participating Frequently
October 3, 2021
Question

JSFL: How to select all library PNGs and set compression type to lossless/no smoothing?

  • October 3, 2021
  • 2 replies
  • 506 views

Hello, I'm currently trying to figure out a way to make a command that selects all the PNGs in the library, and then changes the properties of those to compression lossless/no smoothing. This is what I've cobbled so far, however it selects all items as I'm unsure what the syntax would be to specifically ask for PNGs to be selected only (or wouuld it  be bitmaps?). 

 

var lib = an.getDocumentDOM().library;

fl.getDocumentDOM().library.selectAll(true);

for(i=0;i<lib.items[0];i++)
{
if(selected.indexOf(i)!=-1)continue;
else lib.setItemProperty('allowSmoothing', false);
lib.setItemProperty('compressionType', 'lossless');
}

 

I'm unsure how to address the syntax to be more specific. I've tried 

fl.trace(fl.getDocumentDOM().library.items[0].itemType);

 though I kept getting "folder" appearing in the output instead, haha. 

If someone could lend me a hand figuring this one out, would be grateful. Thanks!

This topic has been closed for replies.

2 replies

Jon DevoS
Participant
July 11, 2022
Hi, maybe too late but maybe someone will be interesting

var
library = fl.getDocumentDOM().library;

for (var i = 0; i< library.items.length; i++) {
    var item = library.items[i];
    if (item.name.indexOf('.png')>-1) {
        item.allowSmoothing = true;
        item.compressionType = 'lossless';
    }
}
kglad
Community Expert
Community Expert
October 3, 2021

for(var i=0;i<fl.getDocumentDOM().library.items.length;i++){
if(fl.getDocumentDOM().library.items[i].itemType=="bitmap"){
// do whatever with bitmaps
}

 

or (assuming you changed no png library names after importing)


if(fl.getDocumentDOM().library.items[i].name.indexOf(".png")>-1){
// do whatever with pngs
}
}

24styx
24styxAuthor
Participating Frequently
October 3, 2021

Hello again, thank you for the two cents. 

Tweaked to match what you have, unfortunately I haven't been able to get the first part that searches for all the PNGs/selects them to work. As it is right now, it will change the properties on a PNG layer I have selected (and yes you're correct, I do not change file names once imported, they all end with .png), which is halfway there! Do you might have an idea what else to try?

 

Here's what I've got at the moment:


for(var i=0;i<fl.getDocumentDOM().library.items.length;i++){
if(fl.getDocumentDOM().library.items[i].name.indexOf(".png")>-1){

var lib = an.getDocumentDOM().library;
lib.setItemProperty('allowSmoothing', false);
lib.setItemProperty('compressionType', 'lossless');

}
}