Script to modify all objects with the same Object Style
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Script to modify all objects with the same Object Style
Tagged: object style, script
- This topic has 7 replies, 4 voices, and was last updated 6 years, 11 months ago by Akiva Atwood.
-
AuthorPosts
-
-
October 21, 2016 at 7:03 am #89241Audrey GagnonMember
I have a large document of 600 pages and I would like to move all text boxes with the same Object Style 0.25” upwards. I am looking for a script similar to “adjust layout” but specific to an object on all my pages.
Thanks a lot !
-
October 21, 2016 at 9:28 am #89246Loic AigonMember
Array.prototype.whose = function F(/*obj|fct*/condition)
//————————————–
// Note: support nested objs (see Example 1 below)
{
// Default test function (cached)
// —
F.OBJ_TEST || (F.OBJ_TEST = function T(t,o)
{
var r = 1,
k;for( k in o )
{
if( !o.hasOwnProperty(k) ) continue;
r = ( ‘object’ == typeof o[k] ) ?
T(t[k],o[k]) :
+(t[k] == o[k]);
if( !r ) break;
}
return r;
});// Vars
// —
var fCond = ‘function’==typeof condition || (condition instanceof Function),
oCond = fCond ? undefined : condition,
n = this.length,
z = 0,
i;// Do we use the default function?
// —
fCond = fCond ? condition : F.OBJ_TEST;// Processing…
// —
for( i=0 ; i < n ; ++i )
fCond(this[i],oCond) && (this[z++] = this[i]);this.length = z;
fCond = oCond = null;// Will allow compound calls :-)
// —
return this;
};var main = function() {
var doc = app.properties.activeDocument, xGap = .25;
if ( !doc ) return;
var items = doc.allPageItems.whose ( function(item) {
return item.appliedObjectStyle.name == “OZALTO”;
});var n = items.length;
while ( n– ) {
items[n].move ( undefined, [xGap, 0] );
}}
var u;
app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );
-
May 14, 2017 at 11:47 am #94640Akiva AtwoodParticipant
Hi Loic
Correct me if I’m wrong — you routinely use Functional Programming with ID scripting?
-
May 15, 2017 at 3:20 pm #94692Loic AigonMember
Hi Akiva,
If you are making a reference to the array prototype adornment, it’s a courtesy of InDiscripts. This snippet intends to mimick the whose function in applescript and it does it very well.
Other than that, I am not stuck to any paradigm ;)
Loic
-
May 15, 2017 at 10:34 pm #94696Akiva AtwoodParticipant
Hi Loic
Thanks. It’s a great bit of code
(I’ve been studying Functional Programming)
Akiva
-
-
October 21, 2016 at 11:22 am #89254Audrey GagnonMember
Seem to have an issue with or above the line 14. I can’t find it.
:-\ -
October 21, 2016 at 1:02 pm #89255Kai RübsamenMember
I have no idea, what Loic is trying to do here ;-)
So, please test this verry short version (will not work with grouped textframes):
var curDoc = app.activeDocument; var allTextFrames = curDoc.textFrames; var nFrames = allTextFrames.length; for (var i = 0; i < nFrames; i++) { var curFrame = allTextFrames[i]; if (curFrame.appliedObjectStyle.name == "name") { curFrame.move(undefined, [0, "-0.25in"]); } }
Kai
-
October 25, 2016 at 7:09 am #89312Loic AigonMember
Hi Kai,
Basically the same process but with more verbose code ;)
-
-
AuthorPosts
- You must be logged in to reply to this topic.