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

Viewing 4 reply threads
  • Author
    Posts
    • #89241

      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 !

    • #89246
      Loic Aigon
      Member

      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” );

      • #94640
        Akiva Atwood
        Participant

        Hi Loic

        Correct me if I’m wrong — you routinely use Functional Programming with ID scripting?

      • #94692
        Loic Aigon
        Member

        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

      • #94696
        Akiva Atwood
        Participant

        Hi Loic

        Thanks. It’s a great bit of code

        (I’ve been studying Functional Programming)

        Akiva

    • #89254

      Seem to have an issue with or above the line 14. I can’t find it.
      :-\

    • #89255

      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

    • #89312
      Loic Aigon
      Member

      Hi Kai,

      Basically the same process but with more verbose code ;)

Viewing 4 reply threads
  • You must be logged in to reply to this topic.
>
Notice: We use cookies on our websites to give you a great online experience. If you keep browsing, we'll assume you're ok with this. For more information, see our privacy policy. By closing this banner, you agree to the use of cookies.I AGREENo