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

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

Community Beginner ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

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!

TOPICS
ActionScript , Exchange extensions , How to , Performance , Timeline

Views

213

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 ,
Oct 03, 2021 Oct 03, 2021

Copy link to clipboard

Copied

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

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 Beginner ,
Oct 03, 2021 Oct 03, 2021

Copy link to clipboard

Copied

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

}
}

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 ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

LATEST
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';
    }
}

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