Skip to main content
ADrobkov
Known Participant
January 17, 2021
解決済み

How do I find out the value passed to Action in jsx?

  • January 17, 2021
  • 返信数 1.
  • 916 ビュー

There is a simple Action that adds noise to the image, where the noise settings are selected when the script is executed (toggle dialog on). In the script, the line: 

 

app.doAction ("Noise", "Command")

 

I want to send this value to the layer name.
Please tell me how to find out the value passed to the action?
I'm not good at JS. I will be grateful for any help!

このトピックへの返信は締め切られました。
解決に役立った回答 c.pfaffenbichler

I see no reason not to use Smart Filters for Frequency Separation … 

 

Once can get the values of an applied Filter, but involving Actions would make things unnecessarily complicated in my opinion. 

function addNoise () {
    try {
    var desc16 = new ActionDescriptor();
    var theRes = executeAction(charIDToTypeID( "AdNs" ), desc16, DialogModes.ALL );
    return theRes
    } catch (e) {return false}
    };
var theRes = addNoise();
checkDesc2 (theRes);
////////////////////////////////////
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
    var c = theDesc.count;
    var str = '';
    for(var i=0;i<c;i++){ //enumerate descriptor's keys
        str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
        };
    alert("desc\n\n"+str);
    return str
    };
////// check //////
function getValues (theDesc, theNumber) {
    switch (theDesc.getType(theDesc.getKey(theNumber))) {
    case DescValueType.ALIASTYPE:
    return theDesc.getPath(theDesc.getKey(theNumber));
    break;
    case DescValueType.BOOLEANTYPE:
    return theDesc.getBoolean(theDesc.getKey(theNumber));
    break;
    case DescValueType.CLASSTYPE:
    return theDesc.getClass(theDesc.getKey(theNumber));
    break;
    case DescValueType.DOUBLETYPE:
    return theDesc.getDouble(theDesc.getKey(theNumber));
    break;
    case DescValueType.ENUMERATEDTYPE:
    return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
    break;
    case DescValueType.INTEGERTYPE:
    return theDesc.getInteger(theDesc.getKey(theNumber));
    break;
    case DescValueType.LISTTYPE:
    return theDesc.getList(theDesc.getKey(theNumber));
    break;
    case DescValueType.OBJECTTYPE:
    return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
    break;
    case DescValueType.RAWTYPE:
    return theDesc.getReference(theDesc.getData(theNumber));
    break;
    case DescValueType.REFERENCETYPE:
    return theDesc.getReference(theDesc.getKey(theNumber));
    break;
    case DescValueType.STRINGTYPE:
    return theDesc.getString(theDesc.getKey(theNumber));
    break;
    case DescValueType.UNITDOUBLE:
    return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
    break;
    default: 
    break;
    };
    };

 

返信数 1

c.pfaffenbichler
Community Expert
Community Expert
January 17, 2021

Why don’t you just apply the Filter as a Smart Filter, that way there is no need to store the values as text? 

ADrobkov
ADrobkov作成者
Known Participant
January 17, 2021

A good option, but this is just an example. Thanks! Similarly, I want to do for frequency decomposition, and there smart filters will not be convenient to use.

c.pfaffenbichler
Community Expert
Community Expert
January 17, 2021

I see no reason not to use Smart Filters for Frequency Separation … 

 

Once can get the values of an applied Filter, but involving Actions would make things unnecessarily complicated in my opinion. 

function addNoise () {
    try {
    var desc16 = new ActionDescriptor();
    var theRes = executeAction(charIDToTypeID( "AdNs" ), desc16, DialogModes.ALL );
    return theRes
    } catch (e) {return false}
    };
var theRes = addNoise();
checkDesc2 (theRes);
////////////////////////////////////
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
    var c = theDesc.count;
    var str = '';
    for(var i=0;i<c;i++){ //enumerate descriptor's keys
        str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
        };
    alert("desc\n\n"+str);
    return str
    };
////// check //////
function getValues (theDesc, theNumber) {
    switch (theDesc.getType(theDesc.getKey(theNumber))) {
    case DescValueType.ALIASTYPE:
    return theDesc.getPath(theDesc.getKey(theNumber));
    break;
    case DescValueType.BOOLEANTYPE:
    return theDesc.getBoolean(theDesc.getKey(theNumber));
    break;
    case DescValueType.CLASSTYPE:
    return theDesc.getClass(theDesc.getKey(theNumber));
    break;
    case DescValueType.DOUBLETYPE:
    return theDesc.getDouble(theDesc.getKey(theNumber));
    break;
    case DescValueType.ENUMERATEDTYPE:
    return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
    break;
    case DescValueType.INTEGERTYPE:
    return theDesc.getInteger(theDesc.getKey(theNumber));
    break;
    case DescValueType.LISTTYPE:
    return theDesc.getList(theDesc.getKey(theNumber));
    break;
    case DescValueType.OBJECTTYPE:
    return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
    break;
    case DescValueType.RAWTYPE:
    return theDesc.getReference(theDesc.getData(theNumber));
    break;
    case DescValueType.REFERENCETYPE:
    return theDesc.getReference(theDesc.getKey(theNumber));
    break;
    case DescValueType.STRINGTYPE:
    return theDesc.getString(theDesc.getKey(theNumber));
    break;
    case DescValueType.UNITDOUBLE:
    return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
    break;
    default: 
    break;
    };
    };