Welcome, Guest. Please Login
Rorohiko Workflow Resources
  Welcome the Message Board of Rorohiko Workflow Resources. To register, please e-mail [email protected] - automatic registration has been turned off because of relentless spambots and spammers. This Message Board is not actively monitored. If you have an urgent question, please e-mail [email protected]. If you post it here, it will probably be many weeks before we notice.
  HomeHelpSearchLogin  
 
Page Index Toggle Pages: 1
Send Topic Print
APID Events - Page position changed (Read 7047 times)
WellerUK
YaBB Newbies
*
Offline



Posts: 5
APID Events - Page position changed
12/19/07 at 02:49:17
 
Hi there

I need to fire a custom script right after I change the page order (by draging & dropping in the pages palette). Now page obviously isn't a "page item" so there is no event (that I'm aware of) to detect changes to it.

Here's a list of things I've tried so far

1. I put sensor object with "modified" event filter on the page. No effect
2. I put text frame with auto page number in it and changed the event filter to "modified-recomposed-overset"
    &"modified-recomposed-nooverset". No Effect
3. I started a new thread on Rorohiko Message Board. Any help appreciated

Weller


OT: I'm only playing with APID for couple of days and it already shifted some of my InDesign workflows into another dimension. Thanks for greeeat (and cheap) InDesign scripting extension. (this is my first ever post here, so I hope you'll excuse me for a little off-topic enthusiasm. won't happen again, I promise)


Back to top
 
 
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: APID Events - Page position changed
Reply #1 - 12/19/07 at 10:58:53
 
Hello,

We're closed for the week before Christmas - we're back at work next week, the week of Xmas and beyond...

I'll get back to you about this ASAP, some time next week...

Cheers

Kris
Back to top
 

Kris
WWW  
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: APID Events - Page position changed
Reply #2 - 12/24/07 at 10:49:36
 
Ok, back at work!


Short answer: there is currently no 'clean' way to do it with the current version of APID. This kind of event is definitely a candidate for addition in a future version, but there is no such thing.  Cry

However... there is a workaround that might be 'good enough' for your purposes. I tried it in CS3; as far as I can tell, it should work in CS2 as well, but I have not tried it out...

Step 1: Add a new page item to one of your master pages, somewhere on the pasteboard (we best put it on a master page so it does not get affected by page deletions - otherwise we might involuntary delete this page item along with the script it contains when deleting a page)

Step 2: attach the following script to the page item via the APID palette


var document = GetDocumentFromChild(theItem);
var lastPageCount = document.extractLabel("pageCount");
if (lastPageCount == null || lastPageCount == "")
{
  lastPageCount = document.pages.length;
}
else if (lastPageCount != document.pages.length)
{
  PageAddedEvent();
  lastPageCount = document.pages.length;
}
document.insertLabel("pageCount",lastPageCount+""); // +"" forces conversion to string

// ***************************

function PageAddedEvent()
{
  alert("Page Added or Removed");
}

// ***************************

function GetDocumentFromChild(childItem)
{
  var parentDocument = null;

  do // do{}while(false); construct; bail out using 'break'
  {
    //
    // Climb the parent chain starting from the child until we cannot
    // go any further, or until we hit a 'Document' object
    //
    while
    (
     childItem != null
     &&
     childItem.parent != childItem
     &&
     ! (childItem instanceof Document)
    )
    {
     childItem = childItem.parent;
    }

    if (! (childItem instanceof Document))
    {
     break; // bail out
    }
   
    parentDocument = childItem;
  }
  while (false);

  return parentDocument;
}


Step 3: Set the event filter to something like 'idle#trigger'. The '#trigger' suffix is a CS3 construct - the CS2 version will ignore the '#trigger' suffix. It causes an idle event to be sent every second or so to a separate ExtendScript engine called 'trigger'. Using a separate engine can help reducing possible interference between this thing and other scripting stuff.

The PageAddedEvent() function will called every time one or more pages are added or removed.

There are disadvantages to this approach: because it's all done at idle time, a sufficiently nimble-moused user can add and delete a page in quick succession, and cause this script to not 'see' the page addition/deletion, but apart from that it seems to work reasonably well.

Hope this helps!

Cheers,

Kris
Back to top
 

Kris
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print