Copy contents of 2 layers to new document with javascript

Hi guys !
Basically i have created a new cutfile generator for a Zund cutting machine we have here at work i have got it to the point where i can create a Registration mark layer and Cut layer now i would like to save this as a layered PDF as this is how the cutter software prefers it. What i would like to know is how with Javascript can I copy the contents of "Regmark" layer and "Cut" layer to a dynamically created new document ? Any thoughts on this will be greatly appreciated thanks so much !
Regards,
Bass

Hi guys,
Just something i forgot to add, the follow piece of code copies content of "Regmark" layer to new document but its going back and selecting contents of "Cut" layer i am unable to do thanks once again !
var sourceDoc = app.activeDocument;
sourceDoc.select(sourceDoc.layers.item("Regmark").pageItems)
app.copy();
var destinationDoc = app.documents.add();
app.pasteInPlace();
/* NEED SOMETHING HERE TO TAKE ME BACK TO sourceDoc */
sourceDoc.select(sourceDoc.layers.item("Cut").pageItems)
app.copy();
/* ONCE AGAIN SOMETHING TO TAKE ME TO destinationDoc */
app.pasteInPlace();
I know im probably going about this all wrong but it's the only thing i can figure out from looking on forum and JS help thanks so much !
Regards,
Bass

Similar Messages

  • JS - Center Selection to Artboard / New Document with certain Artboard size

    TL;DR:
    how do I center my current selection to the artboard?
    just like hitting the "horizontal align-center" and "vertical align-center" buttons.
    Hi,
    I've been searching for the last two hours and before my head hits the keyboard I wanted to ask you for help.
    What I'm struggling with:
    in my init function i create a new document and then copy all layers from the previous document step by step to the new document and then save it as SVG.
    // Init
    (function(){
              destination = Folder.selectDialog('Select folder for SVG files.', docPath);
              if (!destination){return;}
              holderDoc = app.documents.add();
              stepThroughAndExportLayers(docRef.layers);
    my problem is that holderDoc = app.documents.add(); always creates a document that is not the same size as my initial document where the layers get copied from.
    so I want the exact same artboard size as in my initial document.
    I'm fine with either doing it as fixed values or taking directly the values of the inital doc.
    i tried this in the segment where I create the new document:
    // Init
    (function(){
      destination = Folder.selectDialog('Select folder for SVG files.', docPath);
      if (!destination){return;}
      holderDoc = app.documents.add();
      holderDoc.artboards[0].artboardRect = [0,0,128,128];
      stepThroughAndExportLayers(docRef.layers);
    and get this error message:
    "Error 1200: an Illustrator error occured: 1346458189 ('PARM')
    Line: 83
    -> holderDoc.artboards[0].artboardRect = [0,0,128,128];"
    which from what I've read on the web means that illustrator doesnt know what document to pick. but i have called it directly. so what could be the issue?
    to clearify: I do not want to fit the artboard to the images/layer. the artboard should always have a certain size. (for me 128px by 128px)
    I would highly appreciate you helping me with either fixing my approach or propose a completely new one.
    Thanks so much in advance.
    // edit: workaround
    (function(){
              destination = Folder.selectDialog('Select folder for SVG files.', docPath);
              if (!destination){return;}
              var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];
              var ABRect = activeArtboard.artboardRect;
              holderDoc = app.documents.add();
              holderDoc.artboards.add(ABRect);
              holderDoc.artboards.remove(0);
              holderDoc.artboards.setActiveArtboardIndex(0);
              //stepThroughAndExportLayers(docRef.layers);
    i now added a new artboard to the new document with the same size as the artboard on the initial document.
    i remove the predefined artboard on the new doc and set the new artboard as active.
    BUT!
    the artboard is now not centered into the window. which lets illustrator place my image with ctrl+c -> ctrl+v somewhere outside the artboard.
    i now need to align my selection to the center of the artboard. but i cant find any reference on how to center a selection to the artboard.

    yes of course. i never modify the author's comments in original scripts.
    but I wont post the script anywhere when it doesnt work anyway haha.
    this is what I've done now:
    // Init
    (function(){
              destination = Folder.selectDialog('Select folder for SVG files.', docPath);
              if (!destination){return;}
              var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];
              var ABRect = activeArtboard.artboardRect;
              // create new document with same artboard as original
              holderDoc = app.documents.add(DocumentColorSpace.RGB, new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"), new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"));
              stepThroughAndExportLayers(docRef.layers);
    in order to create the new document with the same dimensions as my orignal doc, I first read the artboardRect dimensions of the current artboard and then create the document with those values passed as parameters. the calculation is to get the real width since artboardRect gives you left,top,right,bottom values and not just height and width.
    this only works for square formats though. to make it properly you'd have to change the second "new UnitValue" to use the top and bottom values of artboardRect but I currently dont need to do so.
    * Layers to SVG - layers_export.jsx
    * @version 0.1
    * Improved PageItem selection, which fixed centering
    * @author Anton Ball
    * Exports all layers to SVG Files
    * I didn't want every layer in the SVG file so it first creates a new document
    * and one by one copies each layer to that new document while exporting it out
    * as an SVG.
    * TODO:
    * 1. More of an interface wouldn't hurt. Prefix option and progress bar of some description.
    // Variables
    var docRef = app.activeDocument,
              docPath = docRef.path,
              ignoreHidden = true,
              svgExportOptions = (function(){
                        var options = new ExportOptionsSVG();
                        options.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
                        options.embedRasterImages = true;
                        options.fontType = SVGFontType.OUTLINEFONT;
                        return options;
              destination, holderDoc;
    // Functions
    var stepThroughAndExportLayers = function(layers){
              var layer,
                        numLayers = layers.length;
              for (var i = 0; i < numLayers; i += 1){
                        layer = layers[i];
                        if (ignoreHidden && !layer.visible){continue;}
                        copyLayerTo(layer, holderDoc);
                        // Resize the artboard to the object
                        selectAll(holderDoc);
                        exportAsSVG(validateLayerName(layer.name, '-'), holderDoc);
                        // Remove everything
                        holderDoc.activeLayer.pageItems.removeAll();
              holderDoc.close(SaveOptions.DONOTSAVECHANGES);
    // Copies the layer to the doc
    copyLayerTo = function(layer, doc){
              var pageItem,
                        numPageItems = layer.pageItems.length;
              for (var i = 0; i < numPageItems; i++){
                        pageItem = layer.pageItems[i];
                        pageItem.duplicate(holderDoc.activeLayer, ElementPlacement.PLACEATEND);
    // Selects all PageItems in the doc
    selectAll = function(doc){
              var pageItems = doc.pageItems,
                        numPageItems = doc.pageItems.length;
              for (var i = 0; i < numPageItems; i += 1){
                        pageItems[i].selected = true;
    // Exports the doc to the destination saving it as name
    exportAsSVG = function(name, doc){
              var file = new File(destination + '/' + name + '.svg');
              holderDoc.exportFile(file, ExportType.SVG, svgExportOptions);
    // Makes sure the name is lowercase and no spaces
    validateLayerName = function(value, separator){
              separator = separator || '_';
              //return value.toLowerCase().replace(/\s/, separator);
              return value.replace(/\s/, separator);
    // Init
    (function(){
              destination = Folder.selectDialog('Select folder for SVG files.', docPath);
              if (!destination){return;}
              var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];
              var ABRect = activeArtboard.artboardRect;
              // create new document with same artboard as original
              holderDoc = app.documents.add(DocumentColorSpace.RGB, new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"), new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"));
              stepThroughAndExportLayers(docRef.layers);

  • How to create a new document with a given theme, instead of choosing it every time.

    Hi,
    for work I only use a custom made keynote theme.
    I've already deleted all the default themes, and the only one that is listed in the app is the one I actually use.
    However every time I create a new document I have to chose its theme (that's normal having plenty of themes, but in my case is just a waste of time).
    I was wondering if there's a way to tell keynote to start a new document with a given theme, in order to avoid to chose it every time.
    Thank you for reading and for the help you will give.
    Giacomo

    Keynote > Preferences > General tab
    select “Use theme,” and then click Choose to select a theme.

  • Create a new document with settings appropriate for SWF or XFL output.

    I'm studying up for the CS4 ACE exam, and I'm stumped on something. In the "Laying out a Document" section, it says: "Create a new document with settings appropriate for SWF or XFL output." There isn't really anything specific to creating a document for flash, except that you wouldn't add bleed. I can't find anything online that addresses this. Am I missing something here? Any document can be exported to SWF or XFL. This seems rather ambiguous. What is there to know about this?

    You're right that any document can be exported to SWF or XFL. I'm not sure what you're going to be asked on the ACE exam, but here are some resources:
    Help topic:
    http://help.adobe.com/en_US/InDesign/6.0/WS2DECDF40-B6DA-40b6-804F-2703D6C6A460.html
    Tim Cole's first of 3-part series:
    http://blogs.adobe.com/indesignchannel/2008/11/indesign_2_flash_part_i_1.html
    My blog entry:
    http://blogs.adobe.com/indesigndocs/2009/03/exporting_interactive_indesign.html

  • I cannot install my copy of Photoshop elements on my new PC with windows 8, it wasOK with Windows7

    I cannot install my copy of Photoshop elements on my new PC with windows 8, it was OK with Windows 7.
    Can I get an update for this?
    BizRit

    The workaround for this problem is to revert to IE9 or earlier, install your old PSE, then reinstall the latest IE version.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • Links that open a new window with javascript:void(null); do not work in 3.1

    I've been noticing that any site I go to that opens content in a new window with "javascript:void(null);" will be ignored by Safari 3.1. The links work in Firefox and used to work in Safari as well. Any suggestions?

    General rule of thumb in the Mac universe...
    When Safari is updated most if not all third party add-ons break. That's because most don't play by the rules. The developer thinks they know how to do it better than Apple so they just do it their way. So the first rule of survival is to KNOW what you have installed on your machine at all times. Use something like textedit to create a document listing all of the third party stuff you have installed and religiously update the list. Second rule is to wait a few days before applying an update. Third rule is to visit your third party developers' sites and make sure their little gadget is compatible with the new Safari update.
    Being aware of things will make life much easier for you in the long run.

  • Move/Copy multiple Layers to other document  with Script

    Hello, I have one question to how move or copy multiple layers to other document?.
    With this script i can move one by one:
    var docRef = app.activeDocument;
    var moveLayer1 = docRef.artLayers.getByName('Title');
    var moveLayer2 = docRef.artLayers.getByName('Background');
    var moveTo = app.documents.getByName('Untitled-1');
    var layerRef = moveLayer1.duplicate( moveTo, ElementPlacement.PLACEATBEGINNING);
    var layerRef2 = moveLayer2.duplicate( moveTo, ElementPlacement.PLACEATBEGINNING);
    but i need move two layer in one step....

    var docRef = app.activeDocument;
    select_layer("Title");
    select_layer("Background", true);
    var moveTo = app.documents.getByName('Untitled-1');
    duplicate_active_layer(docRef, moveTo);
    function select_layer(name, add_to_sel)
        try {
            var desc = new ActionDescriptor();
            var ref  = new ActionReference();
            ref.putName( charIDToTypeID( "Lyr " ), name);
            desc.putReference( charIDToTypeID( "null" ), ref );
            desc.putBoolean( charIDToTypeID( "MkVs" ), false );
            if (add_to_sel) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );
            var ok = true;
            try { executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO ); } catch(e) { ok = false; }
            ref  = null;
            desc = null;
            return ok;
        catch (e) { alert(e); throw(e); }
    function duplicate_active_layer(src_doc, dst_doc)
        try {
            app.activeDocument = src_doc;
            var d = new ActionDescriptor();
            var r1 = new ActionReference();
            r1.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
            d.putReference( charIDToTypeID( "null" ), r1 );
            var r2 = new ActionReference();
            r2.putName( charIDToTypeID( "Dcmn" ), dst_doc.name);
            d.putReference( charIDToTypeID( "T   " ), r2 );
            d.putInteger( charIDToTypeID( "Vrsn" ), 2 );
            executeAction( charIDToTypeID( "Dplc" ), d, DialogModes.NO );
            d = null;
            r1 = null;
            r2 = null;
        catch (e) { alert(e); throw (e); }

  • How do I stop fonts from changing when I drag/copy a text box to a new document?

    I am using Mac OS X version 10.7.5 with CS6 version 8.0. When I create an ad in indesign and copy it or drag it onto another page (the finished layout page for a newspaper) Some of the fonts that are enabled in my suitcase, show as if they are not found when dragged to the new document. When i use "find font" and replace the "missing" font with the exact same one it was built with (in the other document) it comes in slightly different, and needs some adjusting. I deal with many ads and bringing them together to build many collective pages. How can I transfer my individual ad pages to my collective layout pages without having issues with font? I would like to still be able to edit the ad on the (collective) page, so placing a PDF or ID doc is not an option.
    Please help! this is slowing down production and proving very frustrating!
    Thanks in advance.

    Do you use styles in these ads? Same named styles inthe receiving document with different definitions (or same named styles with differnt defintions used as the basis for other styles) can cause this. Another possibility is moving an element from a file saved in a previous version of ID into a newer version document. Legacy text frames are not recomposed until you try to edit them.

  • Creating a new document with separate images

    Can someone help me create a new document that has two separate images. I can create a new document but don't know how to place two separate photos in the document. For instance create a document that is 8.5 x11 with two images each 8.5 x 5.5.

    there is a number of ways to do this. also reading the manual to get a basic understanding of how Photoshop works will do wonders. Another method of learning is lynda.com
    here is one way.
    1 make a doc that is 8.5 x 11 at whatever resolution you need.
    2 use a guide as a center point.
    3 open the two pics you want to use.
    4 make sure they are the same res as your 8.5 x 11
    5 drag the layers from the open pics to the 8.5 x 11
    6 crop and size the pics in the file so they fit in each half

  • New Document with Layer Comp & Groups Link ?

    I'd like to create a script that creates a new photoshop document that automatically creates a set of layer comps with specific names that are linked with groups with identical names or the same name. I don't know whether to create this in Adobe Configurator but since I want to create a 'new' document that does this automatically I don't know if Adobe Configurator is the best route to go ?
    An added bonus it would be benifical to select the layer comp, and save only the selected layer comp or an option to save the entire composition or a layer comp.

    What good are Layer Comps that show Groups if one is to add Layers only
    later on or should Layers in the Groups be created right away?
    In Photoshop when you create a new document File -> New it would create the following layer comps and layer groups.
    The layer comps would be linked to the layer groups with the same name or identical name if allowed, for example if the Layer Group name is not Layer Comp A, rather CompyDesignA the script would know to still link it to Layer Comp A.
    I don't know how many layers I would add to the layer group so the script wouldn't create these layers, the script would then export the layer comp with the selected layer group.
    For example, I select Layer Comp A which is tied to the Layer Group, Layer Group A / or similiar name if I select the layer comp Layer Comp A it would know to save only the Layer Group 'Layer Group A / or similar name' automatically, with the option to save the entire composition with all layer comps and all layer groups, understand ?
    I suppose that upon creating the new composition/document each layer group would have a layer created called 'background' and the first layer created above that background layer would have a screen blend mode applied, automate the task.

  • Ilustrator freezes creating a new document with web profile.

    Hi,
    I have the illustrator instalation from creative cloud subscription and everytime i create a new document and on the profile combo choose "web", the illustrator freezes forever.
    Im using mac version in a macbook pro 13" corei7 with 8gigs ram.

    I'm having the same issue with i7 2500k, SSD, 16gb ram, 6870 2gb vram 10.7.4.
    Anyone have any idea if i can get a crash report to help you guys out with figuring this?
    Basically whenever i go -> new and change the document profile to web (or a few others) it just LOCKS and needs to be force quitted.
    I've also just ran with the default and it locks up anyway.    

  • Creating a new document with columns and printing effects

    If you create a new document and set columns into it in the new document menu, and then subsequently create images, tables, text etc. in the document that are bigger than one column (that stretch for example across the entire page), will the part of the image that's in the gutter print and/or show up if it's saved as a PDF?
    Help!
    Thanks!

    Guides are only there as a reference for you to help in alignment.They don't restrict what or where objects can be placed or affect their visibility or printability.
    To see what your page will look like in print, switch to Preview Mode (fast way is to press W with nothing selected).

  • Setting english as the default language for a new document with arabic version of CC apps

    first off, appologies for the screen name, the name i'm sure i had registered before with account was suppose dot be looged in as was barred, so i used this in frustration.  Read the book, The Etymologicon to learn more.
    and another note.  why is the font size in the subject on this form gigantic? intentional of cockup?
    Now, to the point.
    Please please enlighten me, I'm sure it's simple but i can't find the answer and have been haphazardly ploughing the net for half the night.
    I have installed the Arabic langauge version of CC software becuase i need to do a lot of bilingual layouts.
    But
    I generally use, and start with english, but the defualt new document is always set to all the arabic settings, which is a nightmare.
    How do i make english the defualt type (and all the paragraph and language options) while retaining the functionaility of arabic version. 
    I've found instructions for CS2-6 but nothing remotely sensible about CC, and presume i'm missing something really really obvious.

    Hi,
    Here you have some interesting tutos about foreign languages in LV :
    Localizing Your LabVIEW Application to Different Languages
    Localize LabVIEW Applications in Multiple Languages
    Let me know what happens.
    Regards,
    Message Edité par Steve Mohamed le 02-27-2009 09:02 AM
    Steve M.
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Vidéo-t'chats de l'été : présentations techniques et ingénieurs pour répondre à vos questions

  • Can I create a new document with a locked PDF file, add new pages, and lock it all again?

    I published a PDF document ten years ago and now want to add Creative Commons licensing language to the copyright page.  But I forgot the password!  I gather from the Forum that there is no way to recover the password.  However, I wonder if I can take the locked PDF file, create a new document (adding a new page for the licensing information), then lock the whole thing up again.  Will this work?  Thanks for your help!                                                                               

    To create an unprotected file you would need the password.

  • Closing a new document with textvariable

    1. In Indesign CS4 version 6.0.2 ,
    if I create a new document and insert a textvariable, I can save the document and I can close it.
    2. In scripting Indesign CS4 version 6.0.2 with VB.net (Visual Studio 2008 + Framework 3.5),if I open a document manually created under Indesign CS4 version 6.0.2 with a textvariable, I can save the document and I can close it.
    3. In scripting Indesign CS4 version 6.0.2 with VB.net (Visual Studio 2008 + Framework 3.5),if I create a new document and insert a textvariable, I can save the document, but I can't close it. Indesign give a win32 error.
    MyPub = myIndesign.Documents.Add(False)
    MySpread = MyPub.Spreads.Item(1)
    myTextFrames = MySpread.TextFrames
    MyInfos = myTextFrames.Add
    Dim FileNameVariable As InDesign.TextVariable = Nothing
    For Each Item As TextVariable In MyPub.TextVariables
          If Item.VariableType = idVariableTypes.idFileNameType Then
                   FileNameVariable = Item
                   Exit For
         End If
    Next
    Dim FileNameVariableInstance As InDesign.TextVariableInstance = Nothing
    FileNameVariableInstance = MyInfos.TextVariableInstances.Add(idLocationOptions.idAtBeginning)
    FileNameVariableInstance.AssociatedTextVariable = FileNameVariable
    MyPub.Save(FullPath)   'OK
    MyPub.close               'Error Win32 in Indesign.exe
    I try to save the document before creating the FileNameVariableInstance but it's the same result.
    Do you know a way to do it ?
    Regards

    After searching a lot I have finally found the solution :
    MyPub = myIndesign.Documents.Add(False)
    MySpread = MyPub.Spreads.Item(1)
    myTextFrames = MySpread.TextFrames
    MyInfos = myTextFrames.Add
    Dim MyVars as Indesign.TextVariables = MyPub.TextVariables
    Dim FileNameVariableInstance As InDesign.TextVariableInstance = Nothing
    FileNameVariableInstance = MyInfos.TextVariableInstances.Add(idLocationOptions.idAtBeginning)
    FileNameVariableInstance.AssociatedTextVariable = MyVars.item(8) ''index of the textvariable equals to idFileNameType
    MyPub.Save(FullPath)   'OK
    MyPub.close               'OK

Maybe you are looking for