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

Change left or right indent via script

Engaged ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

So this is a bit puzzling:

app.activeDocument.activeLayer.textItem.leftIndent = new UnitValue(10, 'pt');

Doesn't appear to do anything. Whereas something similar 

app.activeDocument.activeLayer.textItem.contents = "spoon";

changes the text layer's contents to "spoon".

 

So...how do you change the indent size with code??

TOPICS
Actions and scripting

Views

479

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 1 Correct answer

Community Expert , Jul 31, 2023 Jul 31, 2023

I have now had time to test and get the same results.

 

The only success I had was to use AM code.

 

set(10);

function set(startIndent) {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("property"), s2t("paragraphStyle"));
    reference.putEnumerated(s2t("textLayer"), s2t("ordinal"), s2t("targetEnum"));
    descri
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

Where did you get .leftIndent from?

 

Edit: I found it - https://theiviaxx.github.io/photoshop-docs/Photoshop/TextItem/leftIndent.html#textitem-leftindent

 

Sometimes it's just better to enter the value without a unit of measure, then wrap the entire code or block in a unit of measure.

 

https://gist.github.com/MarshySwamp/898ae3237305787d0683125166aeb480

 

But I haven't had time to try...

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 ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

I've already tried

var srcDoc = app.activeDocument;
var theLayer = srcDoc.activeLayer;
var left = new UnitValue(10, 'pt');
theLayer.textItem.leftIndent = left; // Does nothing
theLayer.textItem.contents = "spoon"; // Changes text

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 ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

What shows

alert(activeDocument.activeLayer.textItem.leftIndent)

after operation?

I have everything working

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 ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

0 pt by alert and on the paragraph tab.

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 ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

Strange. Something broke.
Or leftIndent or UnitValue.
What does alert(new UnitValue(10, 'pt')) show?
Doesn't work on all fonts and layers, or just your specific layer and file?
 

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 ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

I have now had time to test and get the same results.

 

The only success I had was to use AM code.

 

set(10);

function set(startIndent) {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putProperty(s2t("property"), s2t("paragraphStyle"));
    reference.putEnumerated(s2t("textLayer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor2.putInteger(s2t("textOverrideFeatureName"), 808464435);
    descriptor2.putUnitDouble(s2t("startIndent"), s2t("pixelsUnit"), startIndent);
    descriptor.putObject(s2t("to"), s2t("paragraphStyle"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
}

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 ,
Aug 01, 2023 Aug 01, 2023

Copy link to clipboard

Copied

Stephen,

Thank you, that works!

However, the bigger question remains: why doesn't the original code work. 

 

So mysterious...

 

 

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 ,
Aug 01, 2023 Aug 01, 2023

Copy link to clipboard

Copied

LATEST

It must have worked at one time, who knows how long it's been broken?

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