Skip to main content
Inspiring
June 17, 2014
Answered

Please help me to correct my script!

  • June 17, 2014
  • 4 replies
  • 561 views

I want to change my text first indent:

if the first indent = 0mm

I want to change the first indent = 8mm

I copy the script from Trevor, and change a little bit, but not work, so can someone help to correct my script?

var doc = app.properties.activeDocument,   

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

        hvs = doc.viewPreferences.horizontalMeasurementUnits;   

if (app.changeGrepPreferences.firstLineIndent = 0) exit();   

doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;   

    app.changeGrepPreferences.leftIndent  = 8;

    app.changeGrep();

     exit();

doc.viewPreferences.horizontalMeasurementUnits = hvs;

This topic has been closed for replies.
Correct answer Kai Rübsamen

Your description is just as bad as before


Script 1:

// left Indent: whatever, firstLineIndent: 8 mm

var curDoc = app.activeDocument;

if ( !app.selection.length ) {

    var paras = curDoc.stories.everyItem().paragraphs;

}

else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( "baseline" )) {

        var paras = app.selection[0].paragraphs;

}

else {

    alert("Something wrong with your selection!");

    exit();

}

paras.everyItem().firstLineIndent = "8mm";


Script 2:

// left Indent: whatever, firstLineIndent: 0

var curDoc = app.activeDocument;

if ( !app.selection.length ) {

    var paras = curDoc.stories.everyItem().paragraphs;

}

else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( "baseline" )) {

        var paras = app.selection[0].paragraphs;

}

else {

    alert("Something wrong with your selection!");

    exit();

}

paras.everyItem().firstLineIndent = "0mm";


Script 3:

// left Indent: 8 mm, firstLineIndent: -8 mm

var curDoc = app.activeDocument;

if ( !app.selection.length ) {

    var paras = curDoc.stories.everyItem().paragraphs;

}

else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( "baseline" )) {

        var paras = app.selection[0].paragraphs;

}

else {

    alert("Something wrong with your selection!");

    exit();

}

for ( var i = 0; i < paras.length; i ++ ) {

    var curPara = paras;

    if ( curPara.leftIndent == 0 ) {

        curPara.leftIndent = "8mm";

    }

    curPara.firstLineIndent = "-8mm";

}


If nothing is selected, all paragraphs are honored. If some text is selected, the paragraphs in the selection get the indent.


If this is not what you want, give detailed information, e.g. "Script 1 does not work, because … , also screenshot before, screenshot expected result" and "Script 2 … "


4 replies

HarveyLiuAuthor
Inspiring
June 18, 2014
  • for ( var i = 0; i < paras.length; i ++ ) { 
  •     var curPara = paras
  •     if ( curPara.leftIndent == 0 ) { 
  • //may be I need to add a curly brace "}" in this line, anyway,, thank you very much!
  •         curPara.leftIndent = "8mm"; 
  •     } 
  •     curPara.firstLineIndent = "-8mm"; 
  • }
HarveyLiuAuthor
Inspiring
June 18, 2014

Thank you Kai Rübsamen, thank you for your help,

the first and second script run very well, so nice,

but the 3rd has something error

the error source is "( var i = 0; i < paras.length; i ++ ) {"

can you help to fix it?

Kai Rübsamen
Participating Frequently
June 18, 2014

This line counts your paragraphs in the doc or in the selection. What is the error message? What is the situation in wich the error occurs?

HarveyLiuAuthor
Inspiring
June 17, 2014

Hi Kai Rübsamen,

Thank you for your responses!

First of all, I work in financial print field, and every days has tons of job to do, like set left and first indent this kind of tedious things, set table....so on

but every job has many team member work on, so we only can make a very clear list of the paragraph style and character style, purpose to ever one can very clear which style is what function, I can not set any style for each indent, i have to set those things by manual.

for example:

If the contents like this:

(1) xxxxxxxxxxxxxxxxxxxxxxxxx.

i have to set first indent to -8, and left indent is 8 or 16 or....

if del “(1)” like this:

xxxxxxxxxxxxxxxx

I have to set the first indent = 0mm or 8mm

so, I realy need a script for set three kinds of first indent.

Kai Rübsamen
Kai RübsamenCorrect answer
Participating Frequently
June 17, 2014

Your description is just as bad as before


Script 1:

// left Indent: whatever, firstLineIndent: 8 mm

var curDoc = app.activeDocument;

if ( !app.selection.length ) {

    var paras = curDoc.stories.everyItem().paragraphs;

}

else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( "baseline" )) {

        var paras = app.selection[0].paragraphs;

}

else {

    alert("Something wrong with your selection!");

    exit();

}

paras.everyItem().firstLineIndent = "8mm";


Script 2:

// left Indent: whatever, firstLineIndent: 0

var curDoc = app.activeDocument;

if ( !app.selection.length ) {

    var paras = curDoc.stories.everyItem().paragraphs;

}

else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( "baseline" )) {

        var paras = app.selection[0].paragraphs;

}

else {

    alert("Something wrong with your selection!");

    exit();

}

paras.everyItem().firstLineIndent = "0mm";


Script 3:

// left Indent: 8 mm, firstLineIndent: -8 mm

var curDoc = app.activeDocument;

if ( !app.selection.length ) {

    var paras = curDoc.stories.everyItem().paragraphs;

}

else if(app.selection.length == 1 && app.selection[0].hasOwnProperty( "baseline" )) {

        var paras = app.selection[0].paragraphs;

}

else {

    alert("Something wrong with your selection!");

    exit();

}

for ( var i = 0; i < paras.length; i ++ ) {

    var curPara = paras;

    if ( curPara.leftIndent == 0 ) {

        curPara.leftIndent = "8mm";

    }

    curPara.firstLineIndent = "-8mm";

}


If nothing is selected, all paragraphs are honored. If some text is selected, the paragraphs in the selection get the indent.


If this is not what you want, give detailed information, e.g. "Script 1 does not work, because … , also screenshot before, screenshot expected result" and "Script 2 … "


Kai Rübsamen
Participating Frequently
June 17, 2014

HarveyLiu,

with all respect, you asked now within four days four times the same question in different threads. Please stop that! You got help from Trevor and one other member.

I wrote yesterday those three scripts, but make the decision to delete the scripts, because your purpose is not clear. As Trevor said, why not use paragraph styles for all things.


Give us a chance to understand your goal! So make screenshots before and after and give detailed instructions what should happen in which case.