Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Use Applescript to copy Layer Objects between documents

Community Beginner ,
May 01, 2009 May 01, 2009

I am trying to script the following with AppleScript:

1. User chooses reference and target files

2. open the reference file

3. Select and copy the objects on a specific layer to the clipboard

4. Paste clipboard contents into specific layer in target file

The InDesign CS3 dictionary has a copy command, but I encounter an error every which way I try to use it

copy v : Copies the selection in the active document window to the clipboard.

My script so far:

-- prompt user for reference and target files

set the reference_file to choose file with prompt "Select the InDesign reference file:" without invisibles

--set the target_file to choose file with prompt "Select the target file:"

tell application "Adobe InDesign CS3"

activate

set myLayer to "Layer 1"

open reference_file

tell active document

set reference_layer to object reference of (layer myLayer)

select every page item of reference_layer

copy selection

--close reference_file saving no

end tell

end tell

ERROR MESSAGE:

"Adobe InDesign CS3 got an error: selection of active document doesn’t understand the copy message."

Any one know how to use the copy verb correctly?

TOPICS
Scripting
5.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , May 01, 2009 May 01, 2009

Hi:

Try using

copy

by itself, without a following parameter. In my scripts, I tell the App to do this, not the document or page.

hth,

egr

Translate
LEGEND ,
May 01, 2009 May 01, 2009

It might be as simple as

set selection to every page item of reference_layer

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 01, 2009 May 01, 2009

Hi:

Try using

copy

by itself, without a following parameter. In my scripts, I tell the App to do this, not the document or page.

hth,

egr

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 01, 2009 May 01, 2009

thank you both for your assistance. separating the copy into it's own tell block did the trick.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 01, 2009 May 01, 2009

There's no need to copy -- use the duplicate command instead. It'll be quicker, and doesn't overwrite the clipboard's contents:

tell application "Adobe InDesign CS3"

set active layer of document 2 to "Layer 1" -- the target document

duplicate (every page item of document 1 where name of its item layer is "Layer 1") to page 1 of document 2

end tell

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 04, 2009 May 04, 2009

Thanks for the suggestion.

In testing I run into the following two errors:

1. The set active layer fails with the following message:

"Adobe InDesign CS3 got an error: Can’t set active layer of alias \"MAC4025:Users:gfloro:Desktop:copy_ref2target:Document2.indd\" to \"Layer 1\"."

2. the duplicate line erros with the following message:

"Adobe InDesign CS3 got an error: every page item of alias \"MAC4025:Users:gfloro:Desktop:copy_ref2target:Document1.indd\" whose name of «class pilr» = \"Layer 1\" doesn’t understand the duplicate message."

I'll continue testing away, but if you have any other suggestions, I'll be glad to try them out.

Thanks,

Gregory

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2009 May 04, 2009

I just tried it and it does work. Do both of your document have only a single page? If not the you will have to address which page of Document 1 you wish to duplicate. Have both documents open and Document 1 foremost, then run the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 04, 2009 May 04, 2009

Larry,

I just tried again, removed all my additions to the suggested script, and it to work. Though when the items were duplicated from one document to the other, the stacking order changed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2009 May 04, 2009

Here's what I tried and it worked for me

tell application "Adobe InDesign CS3"
   
    set active layer of document 2 to "Layer 1" -- the target document
   
    (duplicate (every page item of document 1 where name of its item layer is "Layer 1") to page 1 of document 2) send to back
   
end tell

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 04, 2009 May 04, 2009
LATEST

>the stacking order changed

Yes -- the page items actually get duplicated one at a time. One solution is to temporarily group them, then ungroup after the duplicate. Or duplicate them one at a time, doing your own ordering.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 04, 2009 May 04, 2009

> In testing I run into the following two errors:

They suggest you were using references to files, not open InDesign documents.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines