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

Looping through channels is really slow in CC

New Here ,
Aug 31, 2013 Aug 31, 2013

I've been working on .Net application and ran into a little performance snag. I have a simple method that loops through the channel layers by index, grabs the indexed channel name, and if it matches a predetermined variable then it simple deletes that channel. It works as written but is painfully SLOW. Being fairly new at programming I figured it was just me and opened up ExtendScript to run a few test.

 

var docChannels = app.activeDocument.channels;

 

for (i = 0; i < docChannels.length; i++ ){

        alert(docChannels.name);

}

To run this script in a document containing only the RGB channels plus 3 other alpha channels takes approximately 30 to 40 seconds. Running the same script modified to cycle through about 20 document layers only takes about 5 seconds.

I don't know if this is a bug in Photoshop CC or not. I don't have any earlier versions to test on. I've can accomplish the programing method by using a Try Catch statement and directly trying to delete the layer by name. This seems to run a little bit faster but not by much and is not really a proper use of a Try Catch statement.

Any insight into this problem or a better way to impliment my programing method would be most appreciated.

TOPICS
Actions and scripting
844
Translate
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

Guru , Aug 31, 2013 Aug 31, 2013

I am not sure about .Net apps but I think the reason the javascript Object Model can be slow when working with layers and channels it every time you create a layer or channel object all the properties of that object created. I think building the histogram property is the biggest reason for the slow down. Especially is the document has a large canvas.

Action Manger can be much faster because you can get only the property you need and avoid creating a DOM object and building the histogram. Try this

...
Translate
Adobe
Guru ,
Aug 31, 2013 Aug 31, 2013

I am not sure about .Net apps but I think the reason the javascript Object Model can be slow when working with layers and channels it every time you create a layer or channel object all the properties of that object created. I think building the histogram property is the biggest reason for the slow down. Especially is the document has a large canvas.

Action Manger can be much faster because you can get only the property you need and avoid creating a DOM object and building the histogram. Try this to see if faster getting the channel names.

function getProperty( psClass, psKey, index ){// integer:Class, integer:key

    var ref = new ActionReference();

    if( psKey != undefined ) ref.putProperty( charIDToTypeID( "Prpr" ), psKey );

    if(index != undefined ){

        ref.putIndex( psClass, index );

    }else{

        ref.putEnumerated( psClass , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

    }

    try{

        var desc = executeActionGet(ref);

    }catch(e){ return; }// return on error

    if(desc.count == 0) return;// return undefined if property doesn't exists

    var dataType = desc.getType(psKey);

    switch(dataType){// not all types supported - returns undefined if not supported

        case DescValueType.INTEGERTYPE:

            return desc.getInteger(psKey);

            break;

        case DescValueType.ALIASTYPE:

            return desc.getPath(psKey);

            break;

        case DescValueType.BOOLEANTYPE:

            return desc.getBoolean(psKey);

            break;

        case DescValueType.BOOLEANTYPE:

            return desc.getBoolean(psKey);

            break;

        case DescValueType.UNITDOUBLE:

            return desc.getUnitDoubleValue(psKey);

            break;

        case DescValueType.STRINGTYPE:

            return desc.getString(psKey);

            break;

        case  DescValueType.OBJECTTYPE:

            return desc.getObjectValue(psKey);

            break;

        case  DescValueType.LISTTYPE:

            return desc.getList(psKey);

            break;

        case  DescValueType.ENUMERATEDTYPE:

            return desc.getEnumerationValue(psKey);

            break;

    }

};

var channelCount = app.activeDocument.channels.length;

var channelNames = [];

for(var channelIndex=1;channelIndex<=channelCount;channelIndex++){

    channelNames.push(getProperty(charIDToTypeID("Chnl"),charIDToTypeID("ChnN"),channelIndex));

}

alert(channelNames);

Translate
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 ,
Aug 31, 2013 Aug 31, 2013
LATEST

Thanks for your Help Michael. I have things running much faster now.

Translate
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