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
How to use 10008 and 10009 call extensions? (Read 12522 times)
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
How to use 10008 and 10009 call extensions?
10/23/09 at 23:31:29
 
Hi all,

Recently I wrote a script compares two documents  and finds the differences between them.  However  I stumbled upon a problem: it doesn’t work when the documents  have identical names but saved in different locations. It’s often the case in my workflow, since I want to compare two versions of a file: one is being accessed over the network on a remote volume on my G5 while the other is local in my backup folder.
I remembered that the latest version of APID has new ‘callExtensions’: kOpcode_GetDocGUID and kOpcode_FindDocGUID.
So, I made a little test, but it didn’t work for me:

I opened two documents, both have the same name — Sample1.indd — one from hard drive, another from flash drive — and run the following script:

Code:
var myDoc1 = app.documents[0];
var myDoc2 = app.documents[1];
$.writeln("myDoc1.fullName - " + myDoc1.fullName.fsName);
$.writeln("myDoc2.fullName - " + myDoc2.fullName.fsName);

guid1 = app.callExtension(0x90B6C, 10008, myDoc1);
guid2 = app.callExtension(0x90B6C, 10008, myDoc2);
$.writeln("guid1 - " + guid1);
$.writeln("guid2 - " + guid2);

var theDoc1 = app.callExtension(0x90B6C, 10009, guid1);
var theDoc2 = app.callExtension(0x90B6C, 10009, guid2);
$.writeln("theDoc1.fullName - " + theDoc1.fullName.fsName);
$.writeln("theDoc2.fullName - " + theDoc2.fullName.fsName); 



And here is the result I got in console — theDoc1 and theDoc2 reference to the same document Shocked :
Code:
myDoc1.fullName - D:\DeleteMe\Sample1.indd
myDoc2.fullName - H:\My Current Scripts\Compare Documents\Sample1.indd
guid1 - {0466c13e-fdce-0e81-afa92805b47cead9}
guid2 - {a1b5aa61-81a6-a333-0ee1b3b312cb9830}
theDoc1.fullName - D:\DeleteMe\Sample1.indd
theDoc2.fullName - D:\DeleteMe\Sample1.indd 



What did I wrong?

What is the difference between the ‘front doc GUID’ — kOpcode_FrontDocGUID and the ‘active doc GUIDkOpcode_ActiveDocGUID? I thought that active document and front document are synonyms.

Thank you in advance.

Kasyan
Back to top
 
WWW 225729910  
IP Logged
 
Harbs
YaBB Newbies
*
Offline


Kris Does Great Work ;-)
!

Posts: 13
Gender: male
Re: How to use 10008 and 10009 call extensions?
Reply #1 - 10/24/09 at 00:06:04
 
You didn't do anything wrong.

There's currently no way around this bug...  Cry
Back to top
 
WWW  
IP Logged
 
Harbs
YaBB Newbies
*
Offline


Kris Does Great Work ;-)
!

Posts: 13
Gender: male
Re: How to use 10008 and 10009 call extensions?
Reply #2 - 10/24/09 at 00:29:11
 
Just a bit of further clarification:

As it turns out, the bug is not in the reference to the document, but rather in the way InDesign creates the collections from the document references. So even though the UID give you correct references, it doesn't help when you try to access collections within that document. If you use doc.labeledPageItems(), you will get the ones from the correct document. It's just the collections which have this problem.

You can try comparing the documents using doc.labeledPageItems("*")...
Back to top
 
WWW  
IP Logged
 
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
Re: How to use 10008 and 10009 call extensions?
Reply #3 - 10/24/09 at 02:31:40
 
Thank you for the explanation, Harbs.
When I was writing my 'Compare two documents' script I've noticed that something really bizarre is happening to the documents collection.

Kasyan
Back to top
 
WWW 225729910  
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: How to use 10008 and 10009 call extensions?
Reply #4 - 10/24/09 at 07:26:17
 
Hi Kasyan,

I did a bit of digging in my e-mail archive - here's the relevant info snatched from an old e-mail:

Quote:
doc.pageItems...

can lead 'into' the wrong document - so 'doc' is OK, but 'doc.pageItems.item(0)' is wrong.

Observe this script, which uses doc.pageItems (InDesign collections) as well as doc.labeledPageItems (APID hack). doc.labeledPageItems always picks up the correct page items (but of course, it's an inefficient way to find the page items), whereas doc.pageItems (with the _same_ doc) goes wrong depending on which of the two same-name docs is the active document.

var doc = app.activeDocument;

doc.pageItems.item(0).fillColor="C=100 M=0 Y=0 K=0";
doc.pageItems.item(1).fillColor="C=0 M=100 Y=0 K=0";

var pageItems = GetPageItems(doc);
pageItems[0].fillColor="Black";
pageItems[1].fillColor="C=0 M=0 Y=100 K=0";

function GetPageItems(doc)
{
     var allPageItems = doc.labeledPageItems("*");
     var retVal = [];
     for (var idx = 0; idx < allPageItems.length; idx++)
     {
           var item = allPageItems[idx];
           if (item.parent instanceof Page || item.parent instanceof Spread)
           {
                 retVal.push(item);
           }
     }

  return retVal;
}

I _could_ write some solution, but the problem runs deep, and the task would be fairly daunting - I would need to replace the whole collection mechanism inside InDesign. Even things like doc.swatches... go wrong (that's why I am using named swatches).

Another indication to how bad it is - even the debugger is confused and shows the wrong document contents in the browser, while the effect of pageItems[0].fillColor="Black"; clearly shows that doc is correct.

Bad 'un.


If I remember correctly, you should run the above script with two same-name documents open in InDesign, each with two dummy page items in them.
Back to top
 

Kris
WWW  
IP Logged
 
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
Re: How to use 10008 and 10009 call extensions?
Reply #5 - 10/24/09 at 07:33:11
 
Thank you, Kris.
Back to top
 
WWW 225729910  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print