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

Moving items from a template file to active document

Contributor ,
Oct 26, 2014 Oct 26, 2014

Copy link to clipboard

Copied

Hello Everyone,

What I am currently doing is I will leave a template file open and I will have to go to that file really quick and copy what I have selected in that file, go back to the file I am currently working on, then I will use an action that will paste it in the correct place. I was wondering if a script could copy what I have selected in my template file and paste it into my active file so I won't even have to leave my active file. Here is what I have so far.

var template = app.documents.getByName ("sig.ai");

var tempSelected = template.selection;

var docRef = app.activeDocument;

if ( tempSelected.length > 0 ) {

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

newItem = tempSelected.duplicate( docRef,

ElementPlacement.PLACEATEND );

}

}

else {

alert( "Please select one or more art objects in your temp file" );

}

It is not working, I just get the alert message, unless my template is my active file too, which does me no good. Not sure if this is possible to do I have trouble finding scripts that involve files other than the active file so I am not sure what all is capable. Thanks for taking the time to look at this for me I really appreciate it. I tried messing around with placing files but it is not editable enough for me to use.

TOPICS
Scripting

Views

662

Translate

Translate

Report

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

Community Expert , Oct 26, 2014 Oct 26, 2014

name all your items in the template, then you can get a reference to them from your active document without the need to select them

var thisDoc = app.activeDocument;

var template = app.documents[1];

var itemToDuplicate = template.pageItems['namedItem'];

itemToDuplicate.duplicate( thisDoc, ElementPlacement.PLACEATBEGINNING );

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 26, 2014 Oct 26, 2014

Copy link to clipboard

Copied

Hi djbgraphicdesign,

please try this:

if (documents.length == 2) {

    // your template should be the active document and one item should be selected (as minimum)

    // a second document should be opened in the "background"

    var template = app.activeDocument;

    var tempSelected = template.selection;

    var anotherDoc = app.documents[1];

    if ( tempSelected.length > 0 ) {

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

            newItem = tempSelected.duplicate( anotherDoc, ElementPlacement.PLACEATEND );

            }

        alert (i + " items duplicated");

        //app.activeDocument = anotherDoc;

        } else {

            alert( "Please select one or more art objects in your temp file" );

        }

    }

Have fun

Votes

Translate

Translate

Report

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
Contributor ,
Oct 26, 2014 Oct 26, 2014

Copy link to clipboard

Copied

imagecollection Yea I tried placing the file. I have a script that needs to interacts with specific groups in the template and when I place the file the groups don't exist it is just one big group that says "clipped group."

pixxxel schubser Thanks Pixxxel, the script works, but I am trying to figure out if there is a way to do it without having to go into the template file. Is there a way for me to move items from the template file (that is open but not active) into the file that is currently active? Or is it only possible to move items in an active file through script?

Votes

Translate

Translate

Report

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 Expert ,
Oct 26, 2014 Oct 26, 2014

Copy link to clipboard

Copied

name all your items in the template, then you can get a reference to them from your active document without the need to select them

var thisDoc = app.activeDocument;

var template = app.documents[1];

var itemToDuplicate = template.pageItems['namedItem'];

itemToDuplicate.duplicate( thisDoc, ElementPlacement.PLACEATBEGINNING );

Votes

Translate

Translate

Report

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
Contributor ,
Oct 27, 2014 Oct 27, 2014

Copy link to clipboard

Copied

Thanks Carlos,

That seems to be working. The only thing though is whenever I have the same spot colors in the template and in the design a swatch conflict dialog box will pop up asking me if I want to merge the swatches, is there away to automatically merge the swatches without the annoying dialog box? 

Votes

Translate

Translate

Report

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
Contributor ,
Oct 27, 2014 Oct 27, 2014

Copy link to clipboard

Copied

by design I mean the active document

Votes

Translate

Translate

Report

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
Guide ,
Oct 27, 2014 Oct 27, 2014

Copy link to clipboard

Copied

You get the Merge Swatches popup because you have to swatches that don't match.

eg. in template you may have swatch called "myRed" set to Spot colour, with CMYK of 0,100,100,0

and in active doc a swatch called "myRed" set to spot colour, with CMYK of 0,98,100,2

these will conflict.

simple solution would be to rename swatch from template to "templateRed".

if you need to then reduce the swatches something like,

thisDoc.pageItems['namedItem'].fillColor = thisDoc.swatches['myRed'].color;

swatchToDelete = app.activeDocument.swatches['templateRed'];

swatchToDelete.remove();

of course this assumes you know in advance exactly how the swatch is used.

Votes

Translate

Translate

Report

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
Contributor ,
Oct 27, 2014 Oct 27, 2014

Copy link to clipboard

Copied

imagecollection Thanks image, that was very helpful. I have another script that changed the value of my spot white swatch so I can see it on the artboard, that is what was causing the pop up box. I will have to run that part of the script after my template is in place. Thanks again!

Votes

Translate

Translate

Report

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
Guide ,
Oct 27, 2014 Oct 27, 2014

Copy link to clipboard

Copied

LATEST

no problems, glad I could help.

Votes

Translate

Translate

Report

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
Guide ,
Oct 26, 2014 Oct 26, 2014

Copy link to clipboard

Copied

could you just record and action to place a particular file in the document?

Votes

Translate

Translate

Report

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