CS2 Javascript crashing InDesign works as 2 parts and in CS3.

This is a discussion on CS2 Javascript crashing InDesign works as 2 parts and in CS3. within the Adobe Indesign forums in Adobe Tools category; I have a script which works fine in CS3 but when I set it up in CS2 I found it was crashing InDesign. I've tried to cut it down to the minimum and set the 2 parts as functions. The first function makeMyslug create a new layer called slug and then some text frames on all master pages, with details about the document. The second function printMyslug prints all pages to postscript and adds a page number to the postscript file. If I have a document open and run each of the functions separately all is well. If I try ...

Go Back   Application Development Forum > Adobe Tools > Adobe Indesign

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-17-2008, 11:03 PM
John_Kordas@adobeforums.com
Guest
 
Default CS2 Javascript crashing InDesign works as 2 parts and in CS3.

I have a script which works fine in CS3 but when I set it up in CS2 I found it was crashing InDesign. I've tried to cut it down to the minimum and set the 2 parts as functions.

The first function makeMyslug create a new layer called slug and then some text frames on all master pages, with details about the document. The second function printMyslug prints all pages to postscript and adds a page number to the postscript file.

If I have a document open and run each of the functions separately all is well. If I try and run both function in one go InDesign crashes. The script seems to crash InDesign once the printing process begins.

NOTE for this example to work you will need to have a document open and make sure there are no blank pages. I'll post in as a reply so that it can be copied if anyone is able to help me out.

Any suggestions would be greatly appreciated.
Reply With Quote
  #2  
Old 08-17-2008, 11:04 PM
John_Kordas@adobeforums.com
Guest
 
Default Re: CS2 Javascript crashing InDesign works as 2 parts and in CS3.

//Here is the script.

var mySluglay, myBlueBlk, mySlugChr, mySlugPar, myPageNo, myTitle

myPageNo = 1;
myTitle = "Test";

myDocument = app.activeDocument;

function makeMyslug(){
//Create a layer for the slug items.
mySluglay = myDocument.layers.item("Slug");
if (mySluglay == null){
mySluglay = myDocument.layers.add({name:"Slug"});
}
//Create a blue background color.
myBlueBlk = myDocument.colors.item("BlueBack");
if (myBlueBlk == null){
myDocument.colors.add({name:"BlueBack", model:ColorModel.process, colorSpace:ColorSpace.cmyk, colorValue:[100, 60, 0, 0]});
}
//Create a cahr style.
mySlugChr = myDocument.characterStyles.item("SlugChar");
if (mySlugChr == null){
myDocument.characterStyles.add({name:"SlugChar", appliedFont:"Arial"});
}
//Create a para style.
mySlugPar = myDocument.paragraphStyles.item("SlugPar");
if (mySlugPar == null){
myDocument.paragraphStyles.add({name:"SlugPar"});
}
// Set units to mm.
app.activeDocument.viewPreferences.horizontalMeasu rementUnits = MeasurementUnits.MILLIMETERS
app.activeDocument.viewPreferences.verticalMeasure mentUnits = MeasurementUnits.MILLIMETERS;

with(myDocument.documentPreferences){
//Slug
slugBottomOffset = "20";
slugTopOffset = "20";
slugInsideOrLeftOffset = "0";
slugRightOrOutsideOffset = "0";
}
//Set the document’s ruler origin to page origin. This is very important
//--if you don’t do this, getting objects to the correct position on the
//page is much more difficult.
myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

//Create the slug details on all master pages.
with(myDocument.masterSpreads.item(0)){

myDocument.pages[0].appliedSection.continueNumbering = false;
myDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPageNo);
var myDetails = "Title: "+myTitle;

var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight;

mp = app.activeDocument.masterSpreads.everyItem().pages .everyItem().getElements();

for (i = 0; i < mp.length; i++){

var myTitleBox = mp[i].textFrames.add(myDocument.layers.item("Slug"), undefined, undefined, {geometricBounds:[myPageHeight+6,10,myPageHeight+14, myPageWidth-10], contents:myDetails});
myTitleBox.label = "Title";
myTitleBox.textFramePreferences.verticalJustificat ion = VerticalJustification.bottomAlign;
myTitleBox.parentStory.paragraphs[0].appliedCharacterStyle = "SlugChar";
myTitleBox.parentStory.paragraphs[0].appliedParagraphStyle = "SlugPar";
myTitleBox.parentStory.fillColor = myDocument.swatches.item("Paper");
myTitleBox.parentStory.pointSize = 10;
myTitleBox.bringToFront();
myTitleBox.textFramePreferences.ignoreWrap = true;
myTitleBox.textFramePreferences.textColumnCount = 1;

var mycount = app.activeDocument.masterSpreads.item(0).pages.ite m(0).textFrames.item("Title");

var myBlueBlock = mp[i].textFrames.add(myDocument.layers.item("Slug"), undefined, undefined, {geometricBounds:[myPageHeight+6, 8,myPageHeight+20, myPageWidth-8]});
myBlueBlock.label = "BlueBlock";
myBlueBlock.fillColor = "BlueBack";
myBlueBlock.textFramePreferences.verticalJustifica tion = VerticalJustification.bottomAlign;
myBlueBlock.sendToBack();

var myWhiteBlock = mp[i].textFrames.add(myDocument.layers.item("Slug"), undefined, undefined, {geometricBounds:[myPageHeight+14.5, 9,myPageHeight+19, myPageWidth-9]});
myWhiteBlock.label = "WhiteBlock";
myWhiteBlock.fillColor = myDocument.swatches.item("Paper");

var myPageNoBox = mp[i].textFrames.add(myDocument.layers.item("Slug"), undefined, undefined, {geometricBounds:[myPageHeight-5, 10, myPageHeight+18, myPageWidth-10]});
myPageNoBox.label = "PageNo";
myPageNoBox.insertionPoints.item(0).contents = SpecialCharacters.autoPageNumber;
myPageNoBox.insertionPoints.item(0).contents = SpecialCharacters.emSpace;
myPageNoBox.insertionPoints.item(0).contents = "Page No";
myPageNoBox.parentStory.paragraphs[0].appliedCharacterStyle = "SlugChar";
myPageNoBox.parentStory.paragraphs[0].appliedParagraphStyle = "SlugPar";
myPageNoBox.textFramePreferences.verticalJustifica tion = VerticalJustification.bottomAlign;
myPageNoBox.textFramePreferences.ignoreWrap = true;
myPageNoBox.textFramePreferences.textColumnCount = 1;
}
}
}

//print function
function printMyslug(){
alert("Start print process.");
myDocument.printPreferences.printer = Printer.POSTSCRIPT_FILE;
myDocument.printPreferences.ppd = PPDValues.DEVICE_INDEPENDENT;
for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){ myPageName = myDocument.pages.item(myCounter).name; myDocument.printPreferences.pageRange = myPageName; //The name of the exported files will be the base name + the page name + ".pdf". //If the page name contains a colon (as it will if the document contains sections), //then remove the colon. var myRegExp = new RegExp(":","gi"); myPageName = myPageName.replace(myRegExp, "_"); myFilePath = "/c/idjavascript/test_" + myPageName + ".ps"; myFile = new File(myFilePath); document.printPreferences.printFile = myFile; try{ myDocument.print(false); } catch(e){ alert("Page "+myPageName+" may be blank plesae check."); } } }

//call the makeMyslug function

makeMyslug();

//call the printMyslug function

printMyslug();
Reply With Quote
  #3  
Old 08-18-2008, 05:30 AM
try67
Guest
 
Default Re: CS2 Javascript crashing InDesign works as 2 parts and in CS3.

What do you mean by "crashes"? Is there any error message, or does it simply exit?
Reply With Quote
  #4  
Old 08-18-2008, 07:47 PM
John_Kordas@adobeforums.com
Guest
 
Default Re: CS2 Javascript crashing InDesign works as 2 parts and in CS3.

The error I get is:

Microsoft Visual C++ Runtime Library

Runtime Error!

Program: C:\Program Files\Adobe\Adobe InDesign CS2\InDesign.exe

This application has requested the Runtime to terminate it in an unusale way. Please contat the application's support team for more information.

Once I click OK the InDesign is gone.
Reply With Quote
  #5  
Old 08-24-2008, 08:26 PM
John_Kordas@adobeforums.com
Guest
 
Default Re: CS2 Javascript crashing InDesign works as 2 parts and in CS3.

The only thing I found that stop the script crashing InDesign was to comment out the myDocument.print(false) and put in an alert to check if the path was correct and it works.

I have a feeling that the print process may be trying to execute before the slug area is created.

Can anyone suggest a way to check that one function or part of the script is complete before the second part starts?
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 07:21 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.