How to duplicate a document?

Hi guys,
I need to run a script that performs some modifications to the file, and in order to do that I would like to be working on a temp file.
process:
- run the script
- script duplicates file
- script runs on duplicated file
- close/dump duplicate file
I need help with the duplication process, i've done it before in a PSD script but the API seems to be different for Illustrator.
here's an AI example taken from "AI CS4 scripting reference"
// Duplicates any selected items from
// the active document into a new document.
var newItem;
var docSelected = app.activeDocument.selection;
if ( docSelected.length > 0 ) {
     // Create a new document and move the selected items to it.
     var newDoc = app.documents.add();
     if ( docSelected.length > 0 ) {
          for ( i = 0; i < docSelected.length; i++ ) {
               docSelected[i].selected = false;
               newItem = docSelected[i].duplicate( newDoc, ElementPlacement.PLACEATEND );
     else {
          docSelected.selected = false;
          newItem = docSelected.parent.duplicate( newDoc,ElementPlacement.PLACEATEND );
else {
     alert( "Please select one or more art objects" );
Now although this can be tweaked to duplicate all layers, wether selected or not, it doesn't maintain the layers.
So it duplicates all pageItems into one single layer.
How can i duplicate the entire Document as is with same layers and pageItems structure?
thanks

You would have to use recursion in that case.
Here is a short (and incomplete) example of how to iterate through all the pageItems in all the layers. Be careful with recursion, because you could run out of memory if your document is enormous. I've put in a counter that limits the recursive steps to 5,000, but you can experiment.
var doc = app.activeDocument;
var docLayers = doc.layers;
var maxSteps = 5000;
var stepsSoFar = 0;
function walkLayers(aLayerArray) {
    if (stepsSoFar < maxSteps) {
        stepsSoFar++;
        for (var i=0; i<aLayerArray.length; i++) {
            // create an object representing a layer state
            var aLayer = aLayerArray[i];
                // do something with aLayer
            for (var j=0; j <aLayer.pageItems.length; j++ ) {
                var pItem = aLayer.pageItems[j];
                // do something with pItem
            // if this layer has layers of its own, iterate through those
            if (aLayer.layers.length > 0) {
                walkLayers(aLayer.layers);
walkLayers(docLayers);

Similar Messages

  • How to duplicate return of RFC.Exception Application error to test fix

    I am calling a RFC using a sync step in an BPM process. I am checking for system error and have an exception branch. However we got the below error (probably due to the ECC system not being available at that precise moment or something) which was not trapped by the exception alert handling because this comes in as an Application error and not a System error. My questions are :
    1) How to handle this return of .Exception message so that the BPM raises the alert in the exception branch? I have read in other threads that we need to assign the below message structure as the Fault Message and set this under the Exceptions property of the Synchronous send step. If this is true, I am mostly interested in the below question so I can test this.
    2) How to duplicate this issue? I am not sure when exactly the .Exception message is returned on a RFC call, this is not configured anywhere on the ABAP side.
    <rfc:ZRFC_GET_DATA.Exception xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
            <Name>RFC_ERROR_COMMUNICATION</Name>
            <Text>CPIC-CALL: CMRCV on convId: 01667803
                   LOCATION    CPIC (TCP/IP) on local host with Unicode
                   ERROR       connection to partner broken
                   TIME        Mon Mar 16 11:21:51 2009
                   RELEASE     640
                   COMPONENT   NI (network interface)
                   VERSION     37
                   RC          -6
                   MODULE      niuxi_mt.c
                   LINE        905
                   DETAIL      NiPRead (xx.xx.xx.xx/yyyy, hdl 64)
                   SYSTEM CALL recv
                   COUNTER     2
            </Text>
            <Message>
                   <ID>RFC_ERROR_COMMUNICATION</ID>
                   <Number>null</Number>
            </Message>
    </rfc:ZRFC_GET_DATA.Exception>

    Is the error resolved means that the RFC is working fine?
    I think this error due to the RFC destination set to Non-unicode which is expecting unicode option
    Check the R/3 machine whether it is unicode or not try to set the RFC destination option of unicode  in other way and check the error getting replicated or not
    Rajesh

  • HOW TO - Duplicate iWeb Page as a Template?

    January 19, 2006
    Hello:
    Do you know HOW TO
    duplicate an iWeb Page I make
    so I can use it again as a template?
    Thanks,
    JOHN
    800 470-4602

    John,
    No easy task with iWeb's file structure. It appears the sites are all stored together. If you create a second site, you'll see that it's not a new document, just a new heading in the Site Organizer column. Site info is stored in a package called "Domain" in UserName/Library/Application Support/iWeb. This contains all media. The pages themselves are most likely in index.xml.gz. I'm assuming template info and content have been compiled in the xml docs in this zipped file. Sorry that I have no better news.

  • How to turn off document expired

    Locking as duplicate, please continue with [/questions/964298] ~J99
    I still need to know how to stop the 'document expired' message coming up when I reload certain pages.
    <sub>(A Further comment addressed to cor-el hidden by a forum moderator)</sub>
    P.S. if you are on Firefox 21 note that is insecure and unsupported ~J99
    <!-- cor-el, you are specifically requested not to respond, as you're obviously just pasting random pages from the manual to up your post count and have no interest in actually answering the question. -->

    Locking as duplicate, please continue with [/questions/964298]
    I will bump the other post for you but if you tell people not to answer then you should not be surprised at a lack of replies.
    I have hidden some of your comments they are misguided and to say the least tactless.

  • How to change the document color mode(RGB to CMYK)?

    Kindly advice me how to change the document color mode(RGB to CMYK) via scripting in "illustrator cs3".
    Thanks.

    Somebody wrote and posted this a couple of years ago.
    // Duplicate the selection from the active document into a new document.
    // To invoke the JavaScript debugger, remove comment delimiters
    //$.level = 1; debugger;
    var newItem;
    var docSelected = app.activeDocument.selection;
    if ( docSelected.length > 0 ) {
    // Create a new document and move the selected items to it.
    var newDoc = app.documents.add();
    if ( docSelected.length > 0 ) {
    for ( i = 0; i < docSelected.length; i++ ) {
    docSelected[i].selected = false;
    newItem = docSelected[i].duplicate( newDoc,
    ElementPlacement.PLACEATEND );
    else {
    docSelected.selected = false;
    newItem = docSelected.parent.duplicate( newDoc,
    ElementPlacement.PLACEATEND );
    else {
    alert( "Please select one or more art objects" );
    It should give some ideas about how to proceed.

  • Reconnect base and target document if duplicate marketing document

    How can you reconnect the links between the base and target documents when you duplicate marketing documents? 
    For example,  an error was made during the entry of the GR PO and we performed the Goods Return.  However, when you create a Goods Receipt PO and then a Goods Return, the original PO is now closed.  How can you re-open the original PO or else link a new target document to it?
    Thank you.

    Thats right.  You can create a new business process for Exceptions and exceptions have to handled as a one off situation.
    I would suggest you take measures to minimize the error by putting business rules in place and for these one off situations simply type in the PO / SO number in the remarks.
    Creating all document is a big efforts.
    Suda

  • Hello! I just want to know how to open a document (.pdf or .doc).

    I have looked at Labview\vi.lib\platform\browser.llb\Open a Document on Disk.vi but the vi has many subvi's. It works well but when I  build a new application I always get errors when I try to open the document. Thank you.

    Altenbach....  we're gonna start calling you "Hawkeye" 
    There was not much info on the other post other than tst's reply..  I'll check it out..
    Thanks buddy!
    RayR
    EDIT PORTION:
    Humm...  the titles were similar....  "Hello! I just want to know how to open a document (.pdf or .doc) after the press of a control button. Thank you."
    But you're right.. nothing mentioned about a build..  >> SORRY: Not Duplicate Post <<
    Message Edited by JoeLabView on 09-21-2007 11:38 AM

  • How to link PDF document in Report Layout??

    I need to display the contents of PDF document after the form letter report. I tried OLE object but at the runtime it does not display the content. Does any one knows how to attach PDF document in reports layout?
    Thanks
    Ravindra

    you will have to concatinate your report output with the static PDF document. in reprots 10g you can create a cusotm destination that could implement this functionality.
    out of the box, reports does not provide the ability to add static content in PDF to reports' generated PDF output.
    thanks,
    philipp

  • How to create shipment document with out inbound delivery document

    Dear Friends
    How to create shipment document with out outbound/inbound delivery document.
    In my client scenario, there is no inbound delivery for normal purchases.
    Just there are raising the PO to vendor, then they are doing MIGO for goods receipt.
    Can we do shipment creation with reference to PO?
    If it is possible, how it will be?
    Please let it solve
    With regards
    Lakshmikanth

    Dear Sameer,
    Please go to transaction VT01N here you enter Transportation planning point and shipment type then press enter.
    Now system will take you to the shipment document creation screen here you click on Select deliveries or press F6 now system will take you to the select outbound deliveries screen in this screen you enter selection data then execute, now deliveries will get assigned to that shipment.
    After assigning the deliveries enter the remaining data then complete the shipment finally save the shipment document.
    For more information please go through this SAP help link
    Note:- Shipment process need to be carry out for the deliveries before PGI.
    http://help.sap.com/saphelp_47x200/helpdata/en/f5/04898047bd11d2bf750000e8a7386f/frameset.htm
    I hope this will help you,
    Regards,
    Murali.

  • How do we send document from one group to other through sharepoint designer??

    Hi SharePointers,
    Looking for help..
    Requirement: I have 3 groups 1.requestors 2. Approvers 3. Vendors.
    In Requestor group, there are so many Requestors and every Requestor logged in to subsite and  create a new document in the same DocHub. But No Requestor can see documents created by others. ie, Requestor can see his own documents not by others created.
    How to implement this. Is UserProfile service useful here or any other?
    Finally , when Requestor click on save button then I have to send the particular document to Approvers group for approve/rejection.
    Can you please suggest me that how to send the document to others through Designer workflows.? 
    Note: Currently we are using ootb
    Kindly show me the way to do this.
    Many thanks in advance..

    Hi Praveen,
    By OOB option, we cannot send documents as attachment via workflow.
    You could use document url as workaround or use code to achieve it:
    http://community.office365.com/en-us/f/154/t/204397.aspx
    http://sharepointstuff.codeplex.com/
    http://sharepointconnoisseur.blogspot.com/2012/03/emailing-documents-as-attachments.html
    Regards,
    Rebecca Tu
    TechNet Community Support

  • How can I move documents from my iPad to the cloud?

    I am trying to move documents into the cloud from my iPad. Every time I select the upload icon, only my photos show up. How do I find my documents?

    squirrels,
    To save a single PDF document on iPad to Acrobat.com (i.e. one document at a time)
    Open a PDF document in Adobe Reader for iOS.
    Tap anywhere in the document to display the toolbar.
    Tap this icon in the toolbar.
    Select "Save to Acrobat.com".
    If prompted, sign in with your Adobe ID.
    If you want to transfer a lot of PDF documents on your iPad to any cloud storage service, you can transfer them to your Windows/Mac desktop computer using iTunes first.
    How to transfer PDF documents from your iPad/iPhone to your computer
    and upload them to the cloud storage service of your choice via a web browser.
    Does it answer your question?
    Please let us know if you still have a problem with uploading files.

  • How can i share documents with different users on the same mac?

    How can i share documents with different users on the same mac?

    Shared how? The other users can read the documents or you all can read and write the documents?
    The first is easy just place the documents in /Users/Shared anyone can access the files there and the other users will be able to read them.
    The second is a bit trickier.

  • I`d like to know how can i insert documents, xls/doc/pdf into iCloud and have them in my iPhone and my iPad. I just found one way, through ibooks, but i think it isn't a practical option.

    I`d like to know how can i insert documents, xls/doc/pdf into iCloud and have them in my iPhone and my iPad. I just found one way, through ibooks, but i think it isn't a practical option.

    Just use Drop Box instead.

  • How to show sharepoint documents in salesforce ?

    How to show sharepoint documents in salesforce ?
    I should also be able to upload documents from salesforce directly to sharepoint document library/list if the users attach a document for a record in salesforce.   Any idea how to achieve this?
    What are the things need to be done if my sharepoint is available in intranet Or if it is SharePoint Online , how can we link this to salesforce (as Salesforce is global and can be accessed from anywhere). What are the security measures that I need to look
    at and how to achieve this? 
    Ex:- I have a record in salesforce account object. I have to attach a document for that record which should be directly uploaded to sharepoint and shouldn't exist in salesforce, but it should display the listview to the users once its uploaded to sharepoint
    and they should see them as if they exist inside salesforce, once they click on the link in the listview of the relatedlist, it should open the document from sharepoint.
    Thanks in advance.

    Hi,
    According to your post, my understanding is that you want to show SharePoint documents in salesforce.
    You need to integrate SharePoint with Salesforce.
    Nick Swan
    has written an article on how to integrate Salesforce and SharePoint 2007 through the Business Data Catalog.
    But it might be useful as the theory is the same for using SharePoint 2010 and the Business Connectivity Services:
    Salesforce and SharePoint
    Outside of that, there are some useful third-party products you can have a look at.
    Cloud Connector: http://www.layer2.de/en/community/FAQs/cloud-connector/Pages/Office-365-Salesforce-Integration-Migration-Replication.aspx
    DocAve Data Replication: http://www.avepoint.com/salesforce-data-replication/?gclid=CNjZ8sGwl6kCFYEc4Qod-xD-uQ
    DataZoom Script: http://www.siafoo.net/snippet/261
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How to print material document in header level?

    Hi Guys,
    How to print material document from header level. I can only print them in item level. But i want that in header level. For example, I have 4 movements inside a material document and I want to issue only one output from the header level.
    I can see the option Goto -> Additional Function -> output, but it is disabled. Please let me know hot to acheive this and if you need further info on this. Please throw some light on this.
    Thanks
    Yasin.

    HIi
      Your question is not clear.  What exactly you want to be.
    1.  To print material header in your smart form / Sap Script what is the problem. Itu2019s quite easy you can do it. Let me know what problem you are facing.
    2. The option is disables because of business functionality ask your functional guys to help you on the same.
    Regards
    Swati

Maybe you are looking for

  • Gray image frames when opening CS4 in CS3

    Hi, When I export a CS4 inx file to open in CS3, without the images correctly linked there is no image preview, just gray boxes. Is there anyway for this not to happen? For now, I have to give the editor this inx file for editing copy only on a diffe

  • Somehow multiple users showed up to a Lion Party!

    So I got a NEW LION SERVER.. installed fresh. Got my cert going. Great! Followed Lynda.com instructions. Had some file sharing going..Great..everyone was accesing important shared files. Was super fast too! Somehow after logging in and out...some ext

  • Easiest way to share mail to Iphone?

    I was hoping to use mobile access server to access mail remotely via Iphone. Now I've learnt that mobile access server requires two servers. This really *****. So...what will be the easiest way to make a user's internal mail account available to them

  • What kde says about gcc 3.4.2

    kde-config: /usr/lib/libstdc++.so.6: no version information available (required by kde-config) kde-config: /usr/lib/libstdc++.so.6: no version information available (required by kde-config) kde-config: /usr/lib/libstdc++.so.6: no version information

  • Sales orders and delivery creation

    Hi : im selecting sales orders , items and schedule line from a custom table based on plant, shipping point and delivery creation date. Is there any relation between Schedule lines and delivery creation date. For delivery creation date d_date = SY-DA