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?
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
...
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}
};
Copy link to clipboard
Copied
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 🙂
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
That make more sense! 🙂