Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: Looping through channels is really slow in CC

$
0
0

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

Viewing all articles
Browse latest Browse all 27456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>