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

How can I write a script for set left indent?

Explorer ,
Jun 10, 2014 Jun 10, 2014

In three cases as below:

2044.jpg

for example:

left indent:8mm; first indent:0mm

left indent:0mm; first indent:8mm

left indent:8mm; first indent:-8mm


How can I write a script to tell Indesign, wherever the text indent is, each time when I run the script once, the text can put just a step rightward, and “one step = 8mm”.

Please!

TOPICS
Scripting
2.1K
Translate
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

Explorer , Jun 12, 2014 Jun 12, 2014

Yes, it is exactly what i want, thank you Trevor, thank so much!

Translate
Guru ,
Jun 10, 2014 Jun 10, 2014

Hi Harvey

I misread the  question, not clear on what you mean so I removed the snippet I posted before.

But its'hard to understand why not to use paragraphStyles setting the left indent.

Regards

Trevor


Translate
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
Guru ,
Jun 10, 2014 Jun 10, 2014

Edited previous post

Translate
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 ,
Jun 11, 2014 Jun 11, 2014

Hi, Trevor

Thank for your response,

I am working in financial print field.

I set left indent million times in a year, so I am so tire to remember the style name, and how many mm indent is, I am just lazy, so, I just want to easily run the script, if set indent 8mm, I run the script once, and indent 16mm run twice, and so on.

Can you help me?

Translate
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
Guru ,
Jun 11, 2014 Jun 11, 2014

Doesn't sound a good idea but the if you have the code that I posted in post 1 before I erased it (also from my computer) that will add 8 to the indent of all the paragraphs in the doc.

Very easy to change it to just change the current selected paragraphs.

Just change the line pars = doc.stories.everyItem().paragraphs.everyItem(),

to

pars = app.selection[0].paragraphs.everyItem(),

HTH

Trevor

P.s. maybe you can post these original script that I posted, so that other people can understand what's being talked about.

Translate
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 ,
Jun 11, 2014 Jun 11, 2014

Hi, Trevor

I use change by list as below:

grep {leftIndent:48mm} {leftIndent:56mm}
grep {leftIndent:40mm} {leftIndent:48mm}
grep {leftIndent:32mm} {leftIndent:40mm}
grep {leftIndent:24mm} {leftIndent:32mm}
grep {leftIndent:16mm} {leftIndent:24mm}
grep {leftIndent:8mm} {leftIndent:16mm}

grep {firstLineIndent:8mm, leftIndent:48mm} {firstLineIndent:8mm, leftIndent:56mm}
grep {firstLineIndent:8mm, leftIndent:32mm} {firstLineIndent:8mm, leftIndent:48mm}
grep {firstLineIndent:8mm, leftIndent:24mm} {firstLineIndent:8mm, leftIndent:32mm}
grep {firstLineIndent:8mm, leftIndent:16mm} {firstLineIndent:8mm, leftIndent:24mm}
grep {firstLineIndent:8mm, leftIndent:8mm} {firstLineIndent:8mm, leftIndent:16mm}

grep {firstLineIndent:-8mm, leftIndent:48mm} {firstLineIndent:-8mm, leftIndent:56mm}
grep {firstLineIndent:-8mm, leftIndent:32mm} {firstLineIndent:-8mm, leftIndent:48mm}
grep {firstLineIndent:-8mm, leftIndent:24mm} {firstLineIndent:-8mm, leftIndent:32mm}
grep {firstLineIndent:-8mm, leftIndent:16mm} {firstLineIndent:-8mm, leftIndent:24mm}
grep {firstLineIndent:-8mm, leftIndent:8mm} {firstLineIndent:-8mm, leftIndent:16mm}

but not that perfect,

I want to useing jave "if{}" or "for{}" to write this script, but I don't kown the syntext.

Translate
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
Guru ,
Jun 11, 2014 Jun 11, 2014

Did you try the  the original script I posted? You should have got it in your email

Translate
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 ,
Jun 11, 2014 Jun 11, 2014
Hi Trevor!


Diffident line has diffident left indent, but one step is 8mm, and the left indent change pretty often

And many team members work on the same job, do some alternations

So I don't want to use the paragraph style to change or set left indent

thanks

Translate
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
Guru ,
Jun 12, 2014 Jun 12, 2014

Try this

app.doScript ('indent()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Indent Paragraphs");

function indent() {

    var doc = app.properties.activeDocument,

        myParas = doc && app.selection.length && app.selection[0].hasOwnProperty('paragraphs') && app.selection[0].paragraphs.everyItem ().getElements ().slice(0),

        l = myParas && myParas.length,

        hvs = doc.viewPreferences.horizontalMeasurementUnits;

    if (!l) exit();

    doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;

    while (l--) myParas.leftIndent += 8;

    doc.viewPreferences.horizontalMeasurementUnits = hvs;

}

Translate
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 ,
Jun 12, 2014 Jun 12, 2014

Hi, Trevor

Thank your help, appreciate

app.doScript ('indent()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Indent Paragraphs");

Translate
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 ,
Jun 12, 2014 Jun 12, 2014

but first line error!

app.doScript ('indent()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Indent Paragraphs");

Translate
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 ,
Jun 12, 2014 Jun 12, 2014

and can you change the script to recognized the cursor position, not only the selection can do this script?

I mean, if not slect something, that cursor inserted in text can also ok.

Translate
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
Guru ,
Jun 12, 2014 Jun 12, 2014

It does "recognize" the cursor position.

If the cursor is in a paragraph then that paragraph will be indented if a textbox or several paragraphs are selected then all those paragraphs will get indented

What error message did you get? (maybe you run it from the ESTK and didn't target indesign)

Translate
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 ,
Jun 12, 2014 Jun 12, 2014

Wrong source "UndoModes"

Translate
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 ,
Jun 12, 2014 Jun 12, 2014

Hi Trevor,

yes, what you mean just waht i want.

thanks

Translate
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
Guru ,
Jun 12, 2014 Jun 12, 2014

var doc = app.properties.activeDocument, 

        myParas = doc && app.selection.length && app.selection[0].hasOwnProperty('paragraphs') && app.selection[0].paragraphs.everyItem ().getElements ().slice(0), 

        l = myParas && myParas.length, 

        hvs = doc.viewPreferences.horizontalMeasurementUnits; 

if (!l) exit(); 

doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS; 

while (l--) myParas.leftIndent += 8

doc.viewPreferences.horizontalMeasurementUnits = hvs;

I forgot you have CS3 try UndoModes.ENTIRE_SCRIPT, can't rember if that will help or just use the above

Translate
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 ,
Jun 12, 2014 Jun 12, 2014

Yes, it is exactly what i want, thank you Trevor, thank so much!

Translate
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
Guru ,
Jun 12, 2014 Jun 12, 2014
LATEST

Hey Harvey!

To be honest I think you should mark my answer as correct and not your thanks, (as correct as your thanks is)

Translate
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