Friday, April 2, 2010

Newbie script help

Why isn't this working??I've copied this virtually verbatim from two different scripts online.?I keep getting an error on line 2.?Apparently it works in CS2 but not in CS3, according to someone else who reported an error on the same line on the site from which I learned it.

All I'm trying to do is duplicate a layer set from one already open document--which by my logic ought to be document 0 in the index--to another, which ought to be documen 1.?I want to be able to use it in an action to copy our logo on to photos as we open them.

var docs = app.documents;

var sourceDoc = docs.index(0);
var sourceGroup = sourceDoc.layers.getByName('Stacked_basic_colors');
var targetDoc = docs.index(1);

sourceGroup.duplicate ( targetDoc );

We're stalled until someone can help me with this.?Thanks much in advance.

Clint

Newbie script help

I wouldn't think doc.index(0) would work in any version of Photoshop.

var docs = app.documents;

var sourceDoc = docs[0];
var sourceGroup = sourceDoc.layers.getByName('Stacked_basic_colors');
var targetDoc = docs[1];

sourceGroup.duplicate ( targetDoc );

Newbie script help

Interesting.?I copied it from this code for a script written for CS2 that applies a thumbnail script to multiple documents:

// docs is a reference to the Documents collection, that holds all open documents
docs = app.documents;

for (i=0; i %26lt; docs.length; i++) {
?// instead of getting the active document, iterate through each open doc
?doc = docs.index(i);

...

I just tested your script on our workflow and it almost works.?I don't get the error I was getting before, so thank you for fixing that.?Our workflow is apparently the issue now.?I'm getting the error, ''You can only duplicate layers from the frontmost document.''?How can I rewrite the script so that our logo PSD doesn't have to be already open--and thus in doc[0] position--as our action cycles through each photo?

What my wife wants to be able to do is batch cycle through a set of photographs, have an action (or script, or combination of the two) copy the layer set over to the currently open photo, relocate and possibly resize the logo on that photo, then save and close the photo and have the next one automatically open to repeat the process.

I really didn't expect this to be so time-consuming.?I've now spent three hours trying to psych this out.?Thanks again for the help.

Clint

Clint you may be better served if your logo psd file contains NO other layers by placing it as a smart item this way it does NOT already need to be open else you need to keep bringing your logo file back to the foremost after opening each of your files (which will always come to the front) you can do this with something like this:

app.activeDocument = app.documents[0];

I wasn't doubting that you copied the code, just that it ever worked. index is not a method of documents.

To bring a document to the front you make it actvie. The code below makes the sourceDoc active for the dupe then makes the targetDoc active so you can do what ever else is needed now that it has the duped layer/layerset.

Note that if you know the document's names you can also get the by name as you did with the layerset.

var docs = app.documents;

var sourceDoc = docs[0];
var sourceGroup = sourceDoc.layers.getByName('Stacked_basic_colors');
var targetDoc = docs[1];
app.activeDocument = sourceDoc;
sourceGroup.duplicate ( targetDoc );
app.activeDocument = targetDoc;

''I wasn't doubting that you copied the code, just that it ever worked. index is not a method of documents.''?Sure.?I just wanted to show why I'd included it, and that it was ostensibly for CS2.

Your fix--I see Mark had a similar take--fixed it.?Thank you, thank you.?My wife thanks you.?I have to ask: What's the best resource for learning Photoshop scripting??Something with lots of examples, please.?I'm sure as time goes by we'll have more need of it.

Clint

I think your best resource is here and http://ps-scripts.com/bb/index.php

Both have lot's of example code and people willing to help. The scripting guides that ship with Photoshop are another good rescource.

Excellent.?Thanks again for all your help.

No comments:

Post a Comment