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

Determine if text is point or paragraph

Engaged ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

I'm trying to determine via script, if a text layer is either using paragraph text or point (normal) text.

 I think the property is textShape

theLayer.textKey.textShape[0] //  DescValueType.LISTTYPE

 

However, that doesn't work and my deep dive into Action Manager code gets stuck at the last part - mainly because I don't know how to iterate over a listtype

var srcDoc = app.activeDocument;


// PART 1 
// TOP LEVEL
var str = "Descriptor:\n";
var q = " - ";
r = new ActionReference();
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d = executeActionGet(r);

for (var i = 0; i < d.count; i++) 
{
  str += typeIDToStringID(d.getKey(i)) + q + d.getType(d.getKey(i)) + "\n";
}


// PART 2 
str = "Layer properties\n";
var item = "layer";
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID(item), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r);
for (var i = 0; i < d.count; i++) 
{
  str += typeIDToStringID(d.getKey(i)) + q + d.getType(d.getKey(i)) + "\n";
}


// Part 3
var prop = "textKey"; 
item = "layer";
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID(item), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r).getObjectValue(stringIDToTypeID(prop));

str = prop + " properties\n";
for (var i = 0; i < d.count; i++) 
{
  str += typeIDToStringID(d.getKey(i)) + q + d.getType(d.getKey(i)) + "\n";
}

// Part 4
// Sub property
var subProp = "textShape"; // textShape - DescValueType.LISTTYPE
item = "layer";
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID(item), stringIDToTypeID("list"), stringIDToTypeID("targetEnum"));
var d = executeActionGet(r).getObjectValue(stringIDToTypeID(prop)).getObjectValue(stringIDToTypeID(subProp))
str = subProp + " sub properties\n";
for (var i = 0; i < d.count; i++) 
{
  str += typeIDToStringID(d.getKey(i)) + q + d.getType(d.getKey(i)) + "\n";
}
alert(str); //FAILS


// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL

 

Any ideas?

 

 

TOPICS
Actions and scripting , Windows

Views

906

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

correct answers 2 Correct answers

Community Expert , Mar 07, 2023 Mar 07, 2023

This should get you »paint« and »box« respectively, the Layer is addressed by its Index in the function.  

alert (someTextProperties(2).join("\n"));
////// check something //////
function someTextProperties (theIndex) {
    try {
        var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID( "property" ), stringIDToTypeID('textKey'));
        ref.putIndex ( charIDToTypeID("Lyr "), theIndex);
        var layerDesc = executeActionGet(ref);
        var textDesc = layerDesc.getOb
...

Votes

Translate

Translate
People's Champ , Mar 07, 2023 Mar 07, 2023
quote

Any ideas?

By @Ghoul Fool

 

theLayer.textItem.kind

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

This should get you »paint« and »box« respectively, the Layer is addressed by its Index in the function.  

alert (someTextProperties(2).join("\n"));
////// check something //////
function someTextProperties (theIndex) {
    try {
        var ref = new ActionReference();
        ref.putProperty(stringIDToTypeID( "property" ), stringIDToTypeID('textKey'));
        ref.putIndex ( charIDToTypeID("Lyr "), theIndex);
        var layerDesc = executeActionGet(ref);
        var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
        var theText = textDesc.getString(stringIDToTypeID('textKey'));
        var textShape = textDesc.getList(stringIDToTypeID('textShape'));
        var paragraph = typeIDToStringID(textShape.getObjectValue(0).getEnumerationValue(stringIDToTypeID('char')));
        return [paragraph, theText]
    } catch (e) {return false}
};

 

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
People's Champ ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

quote

Any ideas?

By @Ghoul Fool

 

theLayer.textItem.kind

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
Engaged ,
Mar 08, 2023 Mar 08, 2023

Copy link to clipboard

Copied

if (theLayer.kind == LayerKind.TEXT)

Determines whether the layer is text or not. That's not what I was after. c.pfaffenbichler knows what I was after 🙂

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 ,
Mar 08, 2023 Mar 08, 2023

Copy link to clipboard

Copied

@Ghoul Fool 

 

But that isn't what @r-bin wrote or intended... Perhaps more explanation should have been given as apparently this wasn't as obvious as intended.

 

Here is my take and why I marked the reply from @r-bin as correct.

 

Let's make the code from @r-bin a little more generic by removing the variable and putting it in an alert so that we can examine the properties of the active text layer:

 

alert(activeDocument.activeLayer.textItem.kind);

 

This alert will return either:

 

TextType.POINTTEXT

 

or

 

TextType.PARAGRAPHTEXT

 

Depending on the text layer construction...

 

So the correct conditional check would be something like:

 

if (activeDocument.activeLayer.textItem.kind === TextType.POINTTEXT) {
    alert(activeDocument.activeLayer.textItem.kind + "\r" + "It's point text, not paragraph!");
} else {
    alert(activeDocument.activeLayer.textItem.kind + "\r" + "It's paragraph text, not point!");
}

 

Hope this helps!

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
Engaged ,
Mar 08, 2023 Mar 08, 2023

Copy link to clipboard

Copied

LATEST

That make more sense! 🙂

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