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

Deleting Channels

Guide ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

Again another question on best methods/practices using JavaScript. In AppleScript I can do this (my filter again):

delete (every channel whose kind is not component channel)

In JavaScript would I be best served by checking the mode (know how many channels I should have) and remove the rest? Loop through all using if else on ChannelType.SELECTEDAREA etc. Also Im thinking all the channels will be at the end so is a reversed loop possible? What I have been tinkering with so far is this:

var docRef = app.activeDocument;

var docMode = docRef.mode;

var docChannels = docRef.channels;

var chanCount = docRef.channels.length;

if (chanCount > 3) {

alert(chanCount);

for ( var i = 0; i < chanCount; i++ ) {

    if( docChannels.kind == ChannelType.MASKEDAREA ){

        alert("MA channel");

        // I will remove this

        }

    if( docChannels.kind == ChannelType.SELECTEDAREA ){

        alert("SA channel");

        // I will remove this

        }

    if( docChannels.kind == ChannelType.SPOTCOLOR ){

        alert("SC channel");

        // I will merge this

     }

     }

     }

can I use something like this ( var i = chanCount; i = 0; i-- ) or have I overlooked something completely?

TOPICS
Actions and scripting

Views

1.4K

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

Advisor , Apr 28, 2009 Apr 28, 2009

for ( var i = docChannels.length-1; i >= 0; i-- ) {

var channel = docChannels+;

//...

}

Votes

Translate

Translate
Adobe
Guide ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

OK, I tried this and it looks like I can reverse loop with this:

var chanCount = 6

for ( var i = chanCount; i > 0; i-- ) {

        alert(i);

     }

But Im sure I need to fix using somethings.length so the zero based thing works Im I correct?

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
Advisor ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

for ( var i = docChannels.length-1; i >= 0; i-- ) {

var channel = docChannels+;

//...

}

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
Guide ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

I had tried using "=" and using ">" not the ">=" operator…

Can I also take it that I can also change the "--" or "++" shorthands to say "+ 3" and jump?

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
Advisor ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

Can I also take it that I can also change the "--" or "++"

i++;

is the same as

i += 1;

is the same as

i = i + 1;

shorthands to say "+ 3" and jump?

You've lost me here.

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
Guru ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

If by jump you mean step

i += 3

or

i = i + 3

would step 3

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
Guide ,
Apr 28, 2009 Apr 28, 2009

Copy link to clipboard

Copied

LATEST

Yep thats what I meant but did not explain very clearly…

What I managed to work out was the last one in both yours & x's posts

var chanCount = 15

for ( var i = chanCount; i >= 0; i = i - 3 ) {

        alert(i);

     }

so cool

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