Copy link to clipboard
Copied
Hi Scripters,
This script inverts manual and para styles para rules indents (the para style(s) is(are) updated!).
It seems to work but I find its writing … very ugly! No idea to make it more beautiful!
The first loop "for" inverts all the indents. The second one updates the para styles, according the "if" statement.
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Invert Para Rule Indents! …");
function main()
{
var myDoc = app.activeDocument;
var myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements();
for (P = 0; P < myParas.length; P++)
{
var AL = myParas
.ruleAboveLeftIndent;
var AR = myParas
.ruleAboveRightIndent;
var BL = myParas
.ruleBelowLeftIndent;
var BR = myParas
.ruleBelowRightIndent;
myParas
.ruleAboveLeftIndent = AR;
myParas
.ruleAboveRightIndent = AL;
myParas
.ruleBelowLeftIndent = BR;
myParas
.ruleBelowRightIndent = BL;
}
for (P = 0; P < myParas.length; P++)
{
var AL = myParas
.ruleAboveLeftIndent;
var AR = myParas
.ruleAboveRightIndent;
var BL = myParas
.ruleBelowLeftIndent;
var BR = myParas
.ruleBelowRightIndent;
var myStyle = myParas
.appliedParagraphStyle;
var ALs = myStyle.ruleAboveLeftIndent;
var ARs = myStyle.ruleAboveRightIndent;
var BLs = myStyle.ruleBelowLeftIndent;
var BRs = myStyle.ruleBelowRightIndent;
if ( AL == ARs && AR == ALs && BL == BRs && BR == BLs ) {
myStyle.ruleAboveLeftIndent = ARs;
myStyle.ruleAboveRightIndent = ALs;
myStyle.ruleBelowLeftIndent = BRs;
myStyle.ruleBelowRightIndent = BLs;
}
}
}
Thanks in advance!
(^/)
Copy link to clipboard
Copied
Hi,
Let me ask what exactly is a goal?
According to your code is:
1. inverse left/right indent of both rules of every paragraph found in a doc
2. redefine applied paraStyle but ONLY if this style IS NOT manually overriden
Is this correct?
Jarek
Copy link to clipboard
Copied
Hi Jarek,
Yeap! 😉
Copy link to clipboard
Copied
So at point 2 there is a conflict:
-- one style is possibly applied to many paragraphs
-- some of them could be manually modified - some not.
-- script will sometimes redefine a style definition - sometimes will not.
I suggest to reconsider this "if" statement.
Jarek
Copy link to clipboard
Copied
I've played with this situation:
4 paras with para rules [of course, they run per 2, above & below].
In "black color", manual para rules ; the para style has no para rules by default.
In "red color", a para with para rules option. the first para is pure (see selection), the second has its para rules option manually modified.
Before the script:
After:
All the indents are inverted.
As you see, the para style applied to the first "red" para is always pure (updated).
The three other are always overridden!
So, the script seems to run well!
(^/)
Copy link to clipboard
Copied
OK. It goes from the back side - first para after style... got your point.
I built it this way:
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Invert Para Rule Indents! …");
function main()
{
var
myDoc = app.activeDocument,
myParas = myDoc.stories.everyItem().paragraphs.everyItem().getElements(),
cPara;
// to clear last run stored labels
myDoc.paragraphStyles.everyItem().label= "";
//
while (cPara = myParas.shift())
if (!testStyle(cPara))
redefinePara(cPara);
}
function testStyle(thisPara) {
// to detect the way of redefining ==> style OR para
if (!thisPara.appliedParagraphStyle.index || // none
thisPara.appliedParagraphStyle.ruleAboveLeftIndent != thisPara.ruleAboveLeftIndent||
thisPara.appliedParagraphStyle.ruleAboveRightIndent != thisPara.ruleAboveRightIndent||
thisPara.appliedParagraphStyle.ruleBelowLeftIndent != thisPara.ruleBelowLeftIndent||
thisPara.appliedParagraphStyle.ruleBelowRightIndent != thisPara.ruleBelowRightIndent
) return false;
// to avoid processing a style which is redefined already
if (thisPara.appliedParagraphStyle.label != "inverted") redefineStyle (thisPara);
//
return true;
}
function redefineStyle (thisPara) {
// no rules no action
if (!(thisPara.ruleAbove && thisPara.ruleBelow) ) return;
//
var frozenLeftVal = thisPara.ruleAboveLeftIndent;
//
thisPara.appliedParagraphStyle.ruleAboveLeftIndent = thisPara.ruleAboveRightIndent;
thisPara.appliedParagraphStyle.ruleAboveRightIndent = frozenLeftVal;
//
frozenLeftVal = thisPara.ruleBelowLeftIndent;
thisPara.appliedParagraphStyle.ruleBelowLeftIndent = thisPara.ruleBelowRightIndent;
thisPara.appliedParagraphStyle.ruleBelowRightIndent = frozenLeftVal;
// to avoid processing style redefined already
thisPara.appliedParagraphStyle.label = "inverted";
}
function redefinePara (thisPara) {
// no rules no action
if (!(thisPara.ruleAbove && thisPara.ruleBelow) ) return;
//
var frozenLeftVal = thisPara.ruleAboveLeftIndent;
//
thisPara.ruleAboveLeftIndent = thisPara.ruleAboveRightIndent;
thisPara.ruleAboveRightIndent = frozenLeftVal;
//
frozenLeftVal = thisPara.ruleBelowLeftIndent;
thisPara.ruleBelowLeftIndent = thisPara.ruleBelowRightIndent;
thisPara.ruleBelowRightIndent = frozenLeftVal;
}
why this way:
1. to collect part of code in functions
2. to avoid redefining style (updating para) which is already redefined
3. to skip paras with no rules
...
4. I suggest to use "ENTIRE_SCRIPT" mode instead of "FAST_ENTIRE_SCRIPT". I've experienced many times - while using "Fast mode" - Indesign doesnt update changes made to object (text.contents, box.resize, etc) by script.
Jarek
PS to tell you the true - not fully tested...
Copy link to clipboard
Copied
Aha! Thanks Jarek!
I'll test it tonight and I"ll give you my comments tomorrow!
Good night!
(^/)