9 Replies Latest reply on Oct 9, 2010 4:14 AM by Peter Kahrel

    Applescript vs Javascript

    hovercraft2x

      Hi There,

       

      I'm a developer totally new to using inDesign.  I'm looking to do a mail merge type operation to a document created in InDesign.  Basically I want to take a report and populate the datapoints in it programmatically drawing the data from some data source, either a database, excel sheet or whatever.  If possible i'd also like to dynamically populate the values in a few bar graphs and pie charts. 

      What would the better tool be for this?

       

      Thanks,

        • 1. Re: Applescript vs Javascript
          [Jongware] Most Valuable Participant
          What would the better tool be for this?

           

          Excel? Access?

           

          Filling in data into an existing template is easy, but InDesign doesn't natively "do" bar and piece charts. You'd have to draw these (using a script) from scratch, using basic drawing operations. (That rules out "dynamically", I guess.)

           

          It honestly sounds like InDesign is not the proper tool for you.

          • 2. Re: Applescript vs Javascript
            Kasyan Servetsky Level 5

             

            I think AS is a better choice for you since you are going to interact with other applications.

             

            JS provides ability to interact only with some adobe apps: photoshop, illustrator, bridge, etc. -- but not with such programs as Excel, Filemaker, Mail etc. But you may read a text files exported from them -- for example in CVS format -- to get data. Or, another approach is to 'mix' both scripting languages: write part of the script for InDesign in JS and part of the code for, let's say Mail, in AS. Then you can trigger the AS script from JS script using doScript method. I used this approach several times in my scripts and it works well.

             

             

             

            Kasyan

            • 3. Re: Applescript vs Javascript
              hovercraft2x Level 1

              Using InDesign is our only option for creating the report.  As far as the graphs go, it is possible we could use a separate product to create images of the graphs and then drop them into the report.

               

              From the sounds of it, javascript cannot read from external data sources, while applescript can?

              • 4. Re: Applescript vs Javascript
                sstanleyau Level 4

                You can do charts in InDesign, but be prepared for a fair bit of work. You might do better to create them in Illustrator, although its support for chart scripting is pretty lame (I draw them from scratch in Illustrator, FWIW).

                 

                If you're after some AS code for drawing pie charts, there's an AppleScript of mine at scriptbuilders.net called Humble Pie that doe a decent job.

                • 5. Re: Applescript vs Javascript
                  Muppet Mark-QAl63s Level 4

                  Graphs are one of the options that you can declare as variable in Illustrator. What you may be able to do is create a Illustrator template(s) with a graph as a variable data object. Write your excel graph data to an xml file then import that to build your various graphs. You can loop through the data sets and output each set to file. Then place those in InDesign (I don't think ID has any import options that work with AI Data Sets like you can with PS Layers or Compositions or does it?). As for AppleScript I would still prefer to deal with parsing CSV or TDT than trying to script an open workbook much in the same manner as you would have to with JavaScript…

                  • 6. Re: Applescript vs Javascript
                    sstanleyau Level 4
                    What you may be able to do is create a Illustrator template(s) with a graph as a variable data object. Write your excel graph data to an xml file then import that to build your various graphs.

                    I haven't done it myself, but it has serious limitations. I now one big user who gave up on it and converted to drawing from scratch.

                     

                    I've also seen some pretty impressive charts drawn in InDesign itself, and I've done pie charts that way. But it does involve a bit of encoding.

                     

                    FWIW.

                    • 7. Re: Applescript vs Javascript
                      Muppet Mark-QAl63s Level 4

                      Shane, I would agree you are quite limited with the amount of styling that you can apply. But while AppleScript has rounding as taught in school. It lacks any algebre why didn't I listen at school and trigonometry I've forgot since school… It is an option all be it pretty basic.

                      • 8. Re: Applescript vs Javascript
                        sstanleyau Level 4

                        You're right about the lack trig stuff, although all I needed for pie charts was thes:

                         

                        on getSine(x)

                        --convert from degrees to radians

                        set x to x * (2 * pi) / 360

                        set answer to 0

                        set numerator to x

                        set denominator to 1

                        set factor to -(x ^ 2)

                         

                        repeat with i from 3 to 40 by 2

                        set answer to answer + numerator / denominator

                        set numerator to numerator * factor

                        set denominator to denominator * i * (i - 1)

                        end repeat

                         

                        return answer

                        end getSine

                         

                        on getCosine(x)

                        --convert from degrees to radians

                        set x to x * (2 * pi) / 360

                        -- cosine = π/2 - sine, so...

                        set x to pi / 2 - x

                        set answer to 0

                        set numerator to x

                        set denominator to 1

                        set factor to -(x ^ 2)

                         

                        repeat with i from 3 to 40 by 2

                        set answer to answer + numerator / denominator

                        set numerator to numerator * factor

                        set denominator to denominator * i * (i - 1)

                        end repeat

                         

                        return answer

                        end getCosine

                         

                        on getTan(x)

                        --tan = sine/cosine

                        set y to getCosine(x)

                        if y > 0 then

                        return getCosine(x) / y

                        else

                        return 9.99999999E+100

                        end if

                        end getTan

                        • 9. Re: Applescript vs Javascript
                          Peter Kahrel Adobe Community Professional & MVP

                          > I've also seen some pretty impressive charts drawn in InDesign itself

                           

                          Marc Autret's pie chart builder is impressive (it's JavaScript):

                          http://www.indiscripts.com/post/2010/06/claquos2-pie-chart-builder-for-indesign

                           

                          Peter