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
docClose event is not working for me (Read 24095 times)
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
docClose event is not working for me
05/24/09 at 23:36:18
 
Hi there,

I am trying to make a simple scripted plug-in which saves/restores the current document's layout window position when it is closed/opened.
Event Filter: docClose, docLoaded
Code:
if (theItem.eventCode == "docLoaded") {
	var gKasMyDoc = app.activeDocument
	var gKasDocumentName = gKasMyDoc.name;
	KasRestoreDocumentsPosition();
}
else if (theItem.eventCode == "docClose") {
	var gKasMyDoc = app.activeDocument
	var gKasDocumentName = gKasMyDoc.name;
	KasSaveDocumentsPosition();
}

function KasSaveDocumentsPosition() {
	alert("about to close");
	var myCurrentBounds = app.layoutWindows[0].bounds;
	app.setDataStore(gKasDocumentName, myCurrentBounds);
	alert(app.getDataStore(gKasDocumentName));
}

function KasRestoreDocumentsPosition() {
	var myRestoredBounds = app.getDataStore(gKasDocumentName);
	if (myRestoredBounds != undefined) {
		app.layoutWindows[0].bounds = myRestoredBounds;
		alert(app.getDataStore(gKasDocumentName));
	}
} 


docLoaded works as expected, but docClose doesn't.

I tried to make it simpler:
Code:
if (theItem.eventCode == "docClose") {
		alert(theItem.eventCode);
}
else if (theItem.eventCode == "docLoaded") {
		alert(theItem.eventCode);
} 



When a document is open an alert appears, but when closed not. What am I missing?
Thanks in advance.

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



Posts: 181
New Zealand
Gender: male
Re: docClose event is not working for me
Reply #1 - 05/25/09 at 07:05:01
 
Hi Kasyan,

I'll check it out - it might be a bug; it's been a while I revisited that code and maybe APID simply does not work properly. I know docClose has been a hard one to get it working right - I don't remember, need to check my documentation, but maybe I have disabled it on purpose.

One reason for that is that docClose is not really a good event, and I don't personally use it - in many cases, I found it's better to latch on to docSave instead (and not docSaved nor docClose).

docClose happens very late in the game, the document is in the process of closing, and there's not much you can do - any processing you do can only sensibly affect something outside of the document.
Back to top
 

Kris
WWW  
IP Logged
 
Harbs
YaBB Newbies
*
Offline


Kris Does Great Work ;-)
!

Posts: 13
Gender: male
Re: docClose event is not working for me
Reply #2 - 05/25/09 at 07:13:53
 
It does look like docClose is not working.

You can use docDeselected instead...
Back to top
 
WWW  
IP Logged
 
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
Re: docClose event is not working for me
Reply #3 - 05/25/09 at 19:53:43
 
Thank you both for the quick response.

I remember that I tried to use docClose event when I just started using APID. I just installed an older version -- 1.0.45 -- and it works. However, it is useless in my case: the event triggers the script AFTER the layout window is closed, so attempt to get its bound generates an error.

The docDeselected works when more then one document is opened, but while the last document is being closed, no event appears.

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



Posts: 181
New Zealand
Gender: male
Re: docClose event is not working for me
Reply #4 - 05/25/09 at 20:53:38
 
P.S. APID 1.0.47 should have this fixed - i.e. for what it's worth, docClose works again in the current 'work-in-progress'. I'll check on docDeselected to make sure it also works when the document is the sole document.

Have you tried using docSave instead?

Cheers,

Kris
Back to top
 

Kris
WWW  
IP Logged
 
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
Re: docClose event is not working for me
Reply #5 - 05/26/09 at 20:54:23
 
Replacing docClose with docSave did the trick -- now the script does what I want.
But I found a weird phenomenon: I added the following line at the start of the script to check events:
Code:
alert("Event Code is " + theItem.eventCode); 


and found out that when I close a document docSave event appears (my current version is 1.0.47-pre3.0.rel)

I have another question: my script saves position of the first layout window for each document saved by a user using setDataStore(), and all this information is stored somewhere. With time, the information about billions of files can accumulate. Can this degrade the performance?
Back to top
 
WWW 225729910  
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: docClose event is not working for me
Reply #6 - 05/27/09 at 14:56:16
 
Hi Kasyan,

The docSave might be normal - if a document is modified, closing a document automatically makes InDesign attempt to save it before closing.

Yes, if you keep track of all that stuff in the app dataStore, it will accumulate - it actually resides inside your InDesign preferences folder. I'd look into a scheme where I would maybe try to save that data into the document's data store instead - but there's more to it than at first is apparent.

For example, you don't want one user's window position to be inherited by another when the document is opened on another workstation. Also, what happens if the screen resolution is changed since last time you've opened the document? You might move it 'out of reach' of the user.

Maybe you can use a slightly more convoluted setup, where you remove older window positions from the app datastore - e.g. anything more than a week old, or only keep the last 100 window positions - as new entries are made, older entries are deleted.

Or alternatively, you could write it to a file instead of storing it in the app's datastore - making it easier to erase the file at regular times.

Back to top
 

Kris
WWW  
IP Logged
 
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
Re: docClose event is not working for me
Reply #7 - 05/28/09 at 03:43:36
 
Thank you, Kris. I will follow your advice without fail.
Back to top
 
WWW 225729910  
IP Logged
 
Harbs
YaBB Newbies
*
Offline


Kris Does Great Work ;-)
!

Posts: 13
Gender: male
Re: docClose event is not working for me
Reply #8 - 05/28/09 at 04:27:51
 
You can also save the data in a document dataStore. You can pair the data with the user name to keep the window position for each user unique.

There will be a limited number of users per document...  Smiley
Back to top
 
WWW  
IP Logged
 
Kasyan
YaBB Newbies
*
Offline


I Love YaBB 2!

Posts: 21
Kiev, Ukraine
Gender: male
Re: docClose event is not working for me
Reply #9 - 05/31/09 at 02:33:31
 
Since I couldn’t find dataStore property of document, I used insert/extractLabel instead. Here is the current version of the script. It stores data with a document and for each user, as you advised me.

Code:
try {
	var gKasMyDoc = app.activeDocument;
	var gKasDocumentName = gKasMyDoc.name;
	if (File.fs == "Windows") {
		var gKasUserName = $.getenv("USERNAME");
	}
	else if (File.fs == "Macintosh") {
		var gKasUserName = $.getenv("USER");
	}
	var myLabel = "KasSavedBounds_" + gKasUserName;
} catch(err) {}

if (theItem.eventCode == "docLoaded") {
	KasRestoreDocumentsPosition();
}
else if (theItem.eventCode == "docSave") {
	KasSaveDocumentsPosition();
}

function KasSaveDocumentsPosition() {
	try {
		var myCurrentBounds = app.layoutWindows[0].bounds.join(",");
		gKasMyDoc.insertLabel(myLabel, myCurrentBounds);
	} catch(err) {}
}

function KasRestoreDocumentsPosition() {
	var myRestoredBounds = gKasMyDoc.extractLabel(myLabel).split(",");
	if (myRestoredBounds != "") {
		for (i = 0; i < myRestoredBounds.length; i++) {
			myRestoredBounds[i] = parseInt(myRestoredBounds[i]);
		}
		app.layoutWindows[0].bounds = myRestoredBounds;
	}
} 



The idea to make such a plug-in came to me when I read, in the Adobe forum,  about a problem that appeared in InDesign CS4: unlike CS3, it doesn’t save a document’s position, which irritates some users – I assume there are quite a number of them. I thought it was quite easy to solve this with APID.

I have yet another question: If I want to generate a plug-in for all possible versions — CS, CS2, CS3, CS4, both for Mac and PC, should I have all 8 copies of InDesign installed?
Back to top
 
WWW 225729910  
IP Logged
 
Harbs
YaBB Newbies
*
Offline


Kris Does Great Work ;-)
!

Posts: 13
Gender: male
Re: docClose event is not working for me
Reply #10 - 05/31/09 at 08:36:24
 
Hi Kas,

Cool idea.

There is no document dataStore property. There is a dataStore property for scripted plugins though.

For your purposes a script label should work fine, though.

A compile from any version of InDesign works. That's the great thing about APID! Smiley
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print