Skip to main content
24styx
Participating Frequently
Oct 3, 2021 12:45 AM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

Jon DevoS
Participant
Jul 11, 2022 9:14 AM UTC
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';
    }
}
Translate
kglad
Community Expert
Community Expert
Oct 3, 2021 3:24 PM UTC

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

Translate
24styx
24styxAuthor
Participating Frequently
Oct 3, 2021 9:31 PM UTC

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

}
}

Translate