Skip to main content
John_Kordas
Inspiring
August 13, 2008
Question

ExtendScript for CS3 and CS2

  • August 13, 2008
  • 5 replies
  • 2214 views
I recently created a CS3 script but also need to make a CS2 version for some of the PC's that have not moved over to CS3. I currently have both CS2 and CS3 installed on my PC for this reason.

The issue I'm have is that ExtendScript for CS2 does not seem to work properly.

For example in CS3 to add a layer I did:

try{
myDocument.layers.item("Slug").name;
}
catch (myError){
myDocument.layers.add({name:"Slug"});
}

to achieve the same in CS2 I did:

var mysluglayer, myactlayer;

mysluglayer = app.activeDocument.layers.item("Slug");
try{
mysluglay = mysluglayer.name;
}
catch(myError){
mysluglayer = app.activeDocument.layers.add({name:"Slug"});
}

Now when I run it in ExtendScript I get and error on:

mysluglay = mysluglayer.name; ---> Object is invalid.

If I run the script from ID CS2 the script works.

Is this because I have 2 versions of ExtendScript on my PC?

The other issue is I'm trying to set Layer 1 as the active layer after by:

myactlayer = app.activeDocument.layers.activeLayer('Layer 1');
try{
myactlay = myactlayer.name
}
catch (myError){
myactlayer = app.activeDocument.layers.item('Layer 1');
}

The error I get is app.activeDocument.layers.activeLayer is not a function

Is this option available in CS2 or is it only available in CS3?
This topic has been closed for replies.

5 replies

John_Kordas
Inspiring
August 20, 2008
Thanks Dave that did the trick,

var mySluglay = app.activeDocument.layers.item("Slug");

//alert(mySluglay.name);
if (mySluglay != null){
myLayer = app.documents[0].layers.item("Layer 1");
app.documents[0].layoutWindows[0].activeLayer = myLayer;
}
Participating Frequently
July 10, 2009

Hi,

I want to know by javascript wich layers are active in my indesign´s document.

Could you help me please?

Thanks

Best regards

Inspiring
July 10, 2009

alert(app.activeWindow.activeLayer.name);

Ralf

Inspiring
August 20, 2008
LayoutWindow is an object class. To access a member of the class, you need to address the property of the parent object. So:

app.documents[0].layoutWindows[0].activeLayer = "Layer 1"

is what you need.

Except that that doesn't work! This looks like a documentation problem. If you run that you get an error message to the effect that it was expecting a layer object or a string. But actually, it doesn't take a string, because (I think) layer objects are properties of the document, not the window. So, instead, you must use:

myLayer = app.documents[0].layers.item("Layer 1");
app.documents[0].layoutWindows[0].activeLayer = myLayer;

Dave
John_Kordas
Inspiring
August 20, 2008
Unfortunately I have not had any luck with:

app.documents[0].activeLayer = "Layer 1";

did a check in the CS2 reference manual and activeLayer falls under LayoutWindow.

I've tried the following with no luck.

app.documents[0].LayoutWindow.activeLayer = "Layer 1";

app.LayoutWindow.activeLayer = "Layer 1";

app.activeDocument.LayoutWindow.activeLayer = "Layer 1";

Any suggestions?
John_Kordas
Inspiring
August 15, 2008
Greatly appreciated Dave,

This has been driving me mad.

Cheers, John.
Inspiring
August 14, 2008
There's an option in the Debug menu called Do not Break on Guarded Exceptions. I seem to recall that in CS2 it defaulted to Off. You need to turn it on.

My approach to creating new objects is to avoid the use of try/catch by doing something like this:

myLayer = aDoc.layers.item("layerName");
if (myLayer == null) {
myLayer = aDoc.layers.add({name:"layerName"});
}

As for setting the activeLayer, that's a property of a document object, so you should be able to just write:

app.documents[0].activeLayer = "Layer 1";

Dave