0

I'm working on a calendar in InDesign and I have a circle object (oval) that I want to position over the day of the month:

enter image description here

I'm pretty sure it should be possible to write a script that sets the x,y position properties of the oval object on each page to the proper values. I've already got the seven x values and the 6 y values that make up the month-grid, but I'm very new to JavaScript so I don't know how to get started. The sample scripts I saw were very involved, and I think what I want to do is much simpler, albeit with some iterations, etc.

If anyone can help me script the basics to get me started I would greatly appreciate it.

3

Yes, it is possible to position an InDesign object via scripting. First you need to somehow adress the oval, so you can later move it. If it is the only oval on the spread you can use

var myOval = app.activeWindow.activeSpread.ovals.firstItem();

to save the oval in the variable myOval.

Afterwards you can just use

myOval.move([x, y]);

to move the oval into its position. Is this enough info to get you started?

3

Here is a proposal:

    var main = function() {
    var doc = app.properties.activeDocument,
    today = (new Date()).getDate(),
    found, x1, x2, y1, y2;


    if ( !doc ) return;

    app.findGrepPreferences = null;
    app.findGrepPreferences.properties = {
        findWhat : "^"+today+"$",
        pointSize:24
    };

    found = doc.findGrep();

    if ( !found.length ) {
        alert("Nothing found");
        return;
    }

    found = found[0];

    if ( !found.parentTextFrames.length )  {
        alert( "The text may be overriding. Script can't continue" );
        return;
    }

    x1 = found.horizontalOffset;
    x2 = found.endHorizontalOffset;
    y1 = found.baseline;
    y2 = y1-found.ascent;
    pz = found.pointSize;
    xc = (x1+x2)/2;
    yc = (y1+y2)/2;

    var p = found.parentTextFrames[0].parentPage;

    var dateLayer = doc.layers.item ( "dateLayer");
    dateLayer.isValid && dateLayer.remove ();
    dateLayer = doc.layers.add ( {name:"dateLayer"} );
    dateLayer.move ( LocationOptions.AT_BEGINNING );

    var o = p.ovals.add (  {
        geometricBounds:[yc-pz/3, xc-pz/3,yc+pz/3, xc+pz/3],
        strokeColor:"Black",
        strokeWeight:2,
        itemLayer:dateLayer
    });

  }

  var u;
  app.doScript ( "main();",u,u,UndoModes.ENTIRE_SCRIPT, "Mark date" );
  • +1 for the work. For completeness, not having tested this, it looks like it will GREP for a number at 24pt, so this is going to require some tailoring if the style changes or there are other numbers on the page. It is possible to GREP for a style name I think. – Yorik Sep 21 '16 at 15:53
  • You are totally right. I should have said one has to tweak for its own needs. Thx for pointing this. – Loic Sep 21 '16 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.