🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #8827

JS to copy spreads of docs of a directory to a new document

#8827
From: Martin Fischer*
Date: Sun, 24 Sep 2006 15:23
41 lines
2176 bytes
I have tried to make a script that copies every spread of every document of a choosen directory to a new document. This script works, but after saving and closing the target doc and throwing out the message "Ready" InDesign CS2 (4.0.4, OSX 10.4.7) crashes - every time!

Does anybody have an idea why InDesign crashes?
Is there a better way to do the job?



 
var myDoc = app.documents[0]; 
var myFolder = Folder.selectDialog("Choose directory");	 
if(myFolder != null){  
	var myFiles=myFolder.getFiles("*.indd");  
	if (myFiles.length>0){  
		var myCollectedFileName="_"+ myFolder.name + ".indd";  
		var myFirstDoc = app.open(myFiles[0]); 
		var myTargetDoc = app.documents.add(); 
		myTargetDoc.pages.add() 
		myTargetDoc.documentPreferences.properties = myFirstDoc.documentPreferences.properties; 
		myFirstDoc.close(SaveOptions.no); 
		for (k = 0; k < myFiles.length; k++) { 
			collectDocFiles(myFiles[k]);  
		}

		var myColFile = new File(myFolder + "/" + myCollectedFileName);	  
		myTargetDoc.save(myColFile); 
		myTargetDoc.close(SaveOptions.no); 
		alert("Ready") 
	}  
}

function collectDocFiles(theDocFile) {  
	var mySourceDoc = app.open(theDocFile);  
	if ((myTargetDoc.documentPreferences.facingPages == true) && (myTargetDoc.spreads[-1].pages.length != mySourceDoc.spreads[0].pages.length)) 
		myTargetDoc.pages.add(); 
	for (oneSpread = 0; oneSpread < mySourceDoc.spreads.length; oneSpread++)  
		mySourceDoc.spreads[oneSpread].duplicate(LocationOptions.after,  myTargetDoc.spreads[-1])  
	mySourceDoc.close(SaveOptions.no);  
}  


Martin
Technical Details
Message-ID: <3bc1c201.-1@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!news.isoc.lu!webcrossing

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,d496ada15f5bb3fa,start
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Martin Fischer*" <martin.fischer@online.de>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.germany.com!news.isoc.lu!webcrossing
Newsgroups: adobe.scripting.indesign
Subject: JS to copy spreads of docs of a directory to a new document
Message-ID: <3bc1c201.-1@webcrossing.la2eafNXanI>
Date: Sun, 24 Sep 2006 08:23:07 -0700
Lines: 47
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit