1 Reply Latest reply on Sep 1, 2015 11:11 PM by Qwertyfly...

    Copy artboard to new document


      I have a document with multiple artboards, I'm trying to loop over them and copy each to a new document (sized to the original artboard). There is just one piece of text in each artboard. It's working, but the text is offset and not in the same position as the original. I'm trying to figure out where the offset is coming from, and how to correct it. Here's the script:


      var doc = app.documents[0];
      var numArtboards = doc.artboards.length;
      //copy original doc setting to preset
      var docPreset = new DocumentPreset();
      docPreset.width = doc.width;
      docPreset.height = doc.height;
      docPreset.colorMode = doc.documentColorSpace;
      docPreset.units = doc.rulerUnits;
      for(var j = 0; j < numArtboards; j++){
        //current artboard
        var curArtboard = doc.artboards[j];
        var rect = curArtboard.artboardRect;
        //add new doc with original doc's settings
        var newDoc = app.documents.addDocument("", docPreset);
        newDoc.pageOrigin = doc.pageOrigin;
        newDoc.rulerOrigin = doc.rulerOrigin;
        newDoc.artboards[0].artboardRect = rect;
        //activate original doc, copy current artboard
        //move to new document
        var sel = doc.selection;
        doc.selection[0].duplicate(newDoc.layers[0], ElementPlacement.PLACEATBEGINNING);


      I tried to create a DocumentPreset that has all the original doc's info, then make a new one with the same settings and artboard, then duplicate the artboard into it. Everything works except the positions of the duplicated text objects are wrong..


      Any ideas?





        • 1. Re: Copy artboard to new document
          Qwertyfly... Level 4

          it's doing exactly what it should and creates the duplicate in the same location as the original.

          it's not using your ruler origin or page origin.

          simple method would be to record position, duplicate, move to correct pos.


          here is an example:

          these 3 lines replace your duplicate line.


            var pos = doc.selection[0].position;
            var newitem = doc.selection[0].duplicate(newDoc.layers[0], ElementPlacement.PLACEATBEGINNING); 
            newitem.position = pos;