5 Replies Latest reply on Mar 27, 2017 1:03 PM by Kasyan Servetsky

    Open file(s), toggle Data Merge Records, Export

    iamadamkennedy

      Hello,

       

      I've read through the developer guides and can't find any language about Data Merge exports.

       

      What I'm looking to accomplish should be a rather simple script. The pieces I haven't been able to track down are in bold below.

       

      1. Open file

      2. Select Data Merge Source

      3. For each

           a. Toggle Data Merge

           b. Save as InDesign file (name defined by column 1 in data merge underlying file)

           c. Export to PDF (name defined by column 1 in data merge underlying file)

      4. Next

      5. Close file

       

      // defines the csv file to use for dataMerge
      var csvFile = File('filepath');
      
      // defines the csv file to use for dataMerge
      var exportLocation = File('filepath');
      
      // opens InDesign template
      app.open(File("filepath"));
      
      //defines myDoc
      var myDoc = app.activeDocument
      
      // loads defined csv file as datamerge
      app.activeDocument.dataMergeProperties.selectDataSource(csvFile,);
      
      //runs loop
      For each //datamerge record
      //preview
      //save as indesign
      //export as pdf
      Next
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       

      Would appreciate any help or thoughts on this. Thank you.

        • 1. Re: Open file(s), toggle Data Merge Records, Export
          Laubender Adobe Community Professional & MVP

          Hi,

          a moderator moved your question to the InDesign Scripting forum.

           

          What is your InDesign version on what OS ?

          Are you aware, that there is ExtendScript DOM documentation for nearly all InDesign versions?

          Here one Gregor Fellenz compiled for CC 2017 12.0.0.81:

          InDesign ExtendScript API (12.0)

           

          Though, I don't think, that much changed the last years with datamerge.

          See some references below or search the API documentation for "datamerge":

           

          DataMergePreference

          InDesign ExtendScript API (12.0)

           

          DataMergeOption

          InDesign ExtendScript API (12.0)

           

          Regards,
          Uwe

          • 2. Re: Open file(s), toggle Data Merge Records, Export
            Laubender Adobe Community Professional & MVP

            Search the InDesign Scripting forum for datamerge.

            One thread that came up with a search was:

            DataMerge preview

             

            It seems, that Preview is not scriptable by DOM objects directly.

            And I remember that Preview should be avoided before a merge, because the function has a bug.

            Also search for that in the InDesign forum.

             

            FWIW: Maybe Preview for datamerge is scriptable by invoking the right menuAction in the UI, but as I mentioned above, this could perhaps spoil your merged results.

             

            What do you exactly mean by: "toggle Data Merge Records" ?

            Can you show some screenshots perhaps?
            Do that with the forum's "Insert Image" control in the editor bar:

             

            InsertInlineImage-ScreenCapture-AdobeForums.png

             

            Regards,
            Uwe

            • 3. Re: Open file(s), toggle Data Merge Records, Export
              iamadamkennedy Level 1

              Thank you for the insight on the DOM documentation. I am going to be writing this in vbs so I can get better integration with Excel, where all of the source data is pulling from.

               

              I've realized I don't need to preview the datamerge, and rather need to utilize the Create Merged Document capability of InDesign, restricting to a Single Record in my For Each loop.

               

              It seems there is a lot more documentation on jsx than vbs for things of this nature. Any direction on where to look for the datamerge option coding for vbs?

               

              Here is what I would need it to do.

               

              'sets InDesign
              Set myInDesign = CreateObject("filepath")
              
              'sets myDocument
              Set myDocument = myInDesign.Open("filepath")
              
              
              'loads defined csv file as datamerge  
              myDocument.dataMergeProperties.selectDataSource(csvFile,); 
              
              
              For Each [record in datamerge]
              
                  'create merged document on record i+1
                  unknown
              
                  'sets myDocument
                  Set dmDocument = myInDesign.activeDocument
              
                  'save as new filename
                  dmDocument.Save "filepath pulled from row 1 of datamerge"
              
                  export as pdf
                  dmDocument.Export idExportFormat.idPDFType, "filepath pulled from row 1 of datamerge",
                  False, myInDesign.PDFExportPresets.Item("[preset]")
              
              Next
              
              
              
              
              
              
              
              
              
              
              
              

               

              Again, big thanks for any tips or direction. Very appreciated.

              • 4. Re: Open file(s), toggle Data Merge Records, Export
                Laubender Adobe Community Professional & MVP

                Sorry, i cannot help with the vbs side of scripting.


                Perhaps you don't know, but one is able to execute vbs code with InDesign ExtendScript's doScript() method.

                Search for doScript() in the forum here. Also see this post here where Excel is called by vbs using ExtendScript:

                 

                Re: How do you run VB from JSX and return a value?

                 

                Regards,
                Uwe

                • 5. Re: Open file(s), toggle Data Merge Records, Export
                  Kasyan Servetsky Level 5

                  You can get all data from excel, as array, using this function Get data directly from Excel

                  1 person found this helpful