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

Getting a value instead of setting a value

Explorer ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

I'm still trying to learn my way through AM code in Photoshop, and to be honest it's still 99% guessing

So with the script listener it's pretty easy to create most of the stuff I want, that goes for everything that involves setting values. I was wondering if anyone could please explain how you go about getting values?

The example-code below will disable "Hyphenate" on the selected text layer

var desc1 = new ActionDescriptor();

var actionRef = new ActionReference();

actionRef.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("paragraphStyle"));

actionRef.putEnumerated(charIDToTypeID("TxLr"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

desc1.putReference(charIDToTypeID("null"), actionRef);

var desc2 = new ActionDescriptor();

desc2.putBoolean(stringIDToTypeID("hyphenate"), false);

desc1.putObject(charIDToTypeID("T   "), stringIDToTypeID("paragraphStyle"), desc2);

executeAction(charIDToTypeID("setd"), desc1, DialogModes.NO);

How would you go about changing this code so that it retrieves the "Hyphenate" value of the selected text layer instead?

TOPICS
Actions and scripting

Views

908

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
Adobe
Community Expert ,
Feb 02, 2017 Feb 02, 2017

Copy link to clipboard

Copied

for an example

function getBrushFeatures (){

  //A Brush tool must be the current tool

    if (!app.toolSupportsBrushes(app.currentTool)) selectBrush();  //CC 2014

    var ref = new ActionReference(); 

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

    var appDesc = executeActionGet(ref); 

    var toolDesc = appDesc.getObjectValue(stringIDToTypeID('currentToolOptions')); 

    var brushDesc = toolDesc.getObjectValue(stringIDToTypeID('brush'));

    var currDiameter = brushDesc.getDouble(stringIDToTypeID('diameter')); 

    var currHardness = brushDesc.getDouble(stringIDToTypeID('hardness')); 

    var currAngle = brushDesc.getDouble(stringIDToTypeID('angle')); 

    var currRoundness = brushDesc.getDouble(stringIDToTypeID('roundness')); 

    var currSpacing = brushDesc.getDouble(stringIDToTypeID('spacing')); 

    var currFlipy = brushDesc.getBoolean(stringIDToTypeID('flipY')); 

    var currFlipx = brushDesc.getBoolean(stringIDToTypeID('flipX'));

    var currentFeatures = new Array( currDiameter, currHardness, currAngle, currRoundness, currSpacing, currFlipy, currFlipx );

    return currentFeatures

}

JJMack

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
Explorer ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

Thank you JJMack, but in my case it says that the requestet property does not exist when I try to get the "hyphenate" value

var actionRef = new ActionReference();

actionRef.putEnumerated(charIDToTypeID("TxLr"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

var actionDes = executeActionGet(actionRef);

actionDes.getBoolean(stringIDToTypeID("hyphenate"));

When getting the keys contained in the descriptor I only get these:

name,color,visible,mode,opacity,layerID,itemIndex,count,preserveTransparency,layerFXVisible,globalAngle,background,textKey,layerSection,layerLocking,group,targetChannels,visibleChannels,channelRestrictions,fillOpacity,hasUserMask,hasVectorMask,proportionalScaling,layerKind,hasFilterMask,userMaskDensity,userMaskFeather,vectorMaskDensity,vectorMaskFeather,bounds,boundsNoEffects,useAlignedRendering,generatorSettings,keyOriginType,fillEnabled,animationProtection,artboard,artboardEnabled

Se neither "paragraphStyle" or "hyphenate" seems to be available from my ActionDescriptor?

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
Community Expert ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

simene49649793

the following is only „DOM-Code“ and not AM-Code.

But perhaps it helps a little.

var doc = activeDocument;

if (doc.activeLayer.kind  == LayerKind.TEXT) {

    var myText = doc.activeLayer.textItem;

    alert(myText.contents)

    alert(myText.hyphenation)

}

Have fun

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
Explorer ,
Feb 03, 2017 Feb 03, 2017

Copy link to clipboard

Copied

pixxxel schubse: Thank you, that's the way I have been doing it until now. The reason I am asking about AM-code is that DOM-code is so slow compared, so I'm trying to figure out how to understand AM-code 

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
Explorer ,
Feb 04, 2017 Feb 04, 2017

Copy link to clipboard

Copied

I gotta ask though, does anybody actually understand AM-code? Like in the way that you can write AM-code in a logical sense without having to clip out parts from example-codes? Even though I'm comfortable with Java and Python, I just can't seem to wrap my mind around AM-code Even with the example provided by JJMack I don't get it, I really do try, but I feel like I'm hitting the wall on every single approach I take

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
LEGEND ,
Feb 05, 2017 Feb 05, 2017

Copy link to clipboard

Copied

simene49649793 How did you get keys continaed in descriptor (blue font) ?

I tried this but is there any way to set a length of  my loop (I had to set infinite and then to catch error when it's ending)

function cTT(v) {return charIDToTypeID(v)}; function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated(sTT('textLayer'), sTT('ordinal'), sTT('targetEnum'))

dsc = executeActionGet(ref); for(i = 0;; i++) try{alert(typeIDToStringID(dsc.getKey(i)))} catch(errEnd) {}

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
Explorer ,
Feb 05, 2017 Feb 05, 2017

Copy link to clipboard

Copied

Kukuryku: I did it like this:

var actionRef = new ActionReference();

actionRef.putEnumerated(charIDToTypeID("TxLr"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

var actionDes = executeActionGet(actionRef);

// Create a variable to store keys contained in the descriptor

containedKeys = new Array;

// For each key in the Action Descriptor

for(itmIndex = 0; itmIndex < actionDes.count; itmIndex++)

{

  // Get the current key, and store it as a StringID

  containedKeys.push(typeIDToStringID(actionDes.getKey(itmIndex))));

}

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
LEGEND ,
Feb 05, 2017 Feb 05, 2017

Copy link to clipboard

Copied

LATEST

Thank You, I also changed last version of my script, and did new one in DOM:

$.level = 0, function cTT(v) {return charIDToTypeID(v)}; function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated(sTT('textLayer'), sTT('ordinal'), sTT('targetEnum'))

for(dsc = executeActionGet(ref), txt = '', i = 0; i < dsc.count; i++) txt += typeIDToStringID(dsc.getKey(i)) + '\n'

alert(txt)

txt = ''; for(i in activeDocument.activeLayer.textItem) txt += i + '\n'; alert(txt)

As you see there are twice more positions 😕

so if DOM is based on ActionManager I guess, why aren't they available from AM too (just only 30)?

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