Hi Paul,
I think I found one more bug in your code.
If the layer in the layer set is not found, instead of returning true...
- Code: Select all
function getLayerItemIndexByLayerID(id) {
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
try{
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}catch(e){return true;}
};
...I think you want to return false:
- Code: Select all
function getLayerItemIndexByLayerID(id) {
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putIdentifier( charIDToTypeID( "Lyr " ), id );
try{
return executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ));
}catch(e){return false;}
};
This way, the selLayer method that calls the method above will display the 'Layer does not exist' message:
- Code: Select all
function selLayer(layerID,add) {
var result = getLayerItemIndexByLayerID(layerID);
if (result > 0) {
try{
activeDocument.backgroundLayer;
var bkGround = 1;
} catch(e) {var bkGround = 0;}
selectLayerByIndex(result - bkGround ,add);
} else {
alert("Layer does not exist");
}
};