3 Replies Latest reply on Jan 20, 2017 6:47 PM by jbryan

    Export Adobe Illustrator file and edit contents w/AppleScript

    jbryan

      Hello all! (First post of a newbie here.)

       

      BACKGROUND

      Our FM solution is used by graphic designers to manage packaging graphics projects for hundreds of products. The primary deliverable for every project is an Adobe Illustrator art file. Each file has a "legend" at bottom of the art that designers manually type (or copy-paste) data about the project into; description, size, print method, etc. I automated the creation of the legend, to simplify workflow and reduce human error.

       

      DETAILS

      Start by exporting an Adobe Illustrator template file (.ait) from a container field to the TemporaryPath, looping through every child record of the current record; opening the template file and then populating data in the Illustrator document. Just got it to work today, so feeling pretty good but would love any tips & recommendations to make it leaner/faster/better.

       

      FILEMAKER SCRIPT

      # create a file path in the temp folder naming the document with its UUID

      Set Variable [ $TemplatePath ; Value: Get (TemporaryPath) & “legend.ait” ]

       

      # export the file to the path

      Export Field Contents [ Job Settings::Legend Template ; “$TemplatePath” ]

       

      # loop through every deliverable record and create legend for each in Illustrator with AppleScript

      Go to Object [ Object Name: “Deliverable Portal” ]

      Go to Portal Row [ Select ; First ]

      Loop

        Set Variable [ $RowNumber ; Value: Get ( ActivePortalRowNumber ) ]

        Set Field [ Job::Deliverable Row ; $RowNumber ]

        Set Field [ Job::Deliverable Print Method ; Deliverable::Print Method ]

        Set Field [ Job::Deliverable Type ; Deliverable::Type ]

        Set Field [ Job::Deliverable Substrate ; Deliverable::Substrate ]

        Send Event [ “<unknown>” ; “aevt” ; “odoc” ; “$TemplatePath” ]

        Perform AppleScript [ My Applescript Here… ]

        Go to Portal Row [ Next ]

        Set Variable [ $RowNumber ; Value: Get ( ActivePortalRowNumber ) ]

        Exit Loop If [ $RowNumber > Job::Deliverable Count ]

      End Loop

      Go to Portal Row [ Select ; First ]

       

      APPLESCRIPT

      tell application "FileMaker Pro Advanced"

        if it is running then

        set delivNumber to cell "Deliverable Row" of current record

        set delivTotal to cell "Deliverable Count" of current record

        set theDescription to cell "Event::Description" of current record

        set theSize to cell "Event::Size" of current record

        set theUPC to cell "Item::UPC" of current record

        set theJob to cell "Job #" of current record

        set theVendor to cell "Vendor" of current record

        set thePrintMethod to cell "Deliverable Print Method" of current record

        set theType to cell "Deliverable Type" of current record

        set theSubstrate to cell "Deliverable Substrate" of current record

        set theRequester to cell "User requester::Sort Name" of current record

        set theDesigner to cell "User designer::Sort Name" of current record

        end if

      end tell

       

      tell application "Adobe Illustrator"

        set the contents of text frame "Number" of document 1 to delivNumber

        set the contents of text frame "Total" of document 1 to delivTotal

        set the contents of text frame "Type1" of document 1 to theType

        set the contents of text frame "Description" of document 1 to theDescription

        set the contents of text frame "Size" of document 1 to theSize

        set the contents of text frame "UPC" of document 1 to theUPC

        set the contents of text frame "Job" of document 1 to theJob

        set the contents of text frame "Vendor" of document 1 to theVendor

        set the contents of text frame "PrintMethod" of document 1 to thePrintMethod

        set the contents of text frame "Type2" of document 1 to theType

        set the contents of text frame "Substrate" of document 1 to theSubstrate

        set the contents of text frame "Requester" of document 1 to theRequester

        set the contents of text frame "Designer" of document 1 to theDesigner

      end tell

        • 1. Re: Export Adobe Illustrator file and edit contents w/AppleScript
          erolst

          Without looking closer, I think you could optimize the AS code by addressing the record and document objects only once:

           

          tell application "FileMaker Pro Advanced"

            if it is running then

              tell current record

                set delivNumber to cell "Deliverable Row" of current record

                ..

              end tell

            end if

          end tell

           

          Analogous for the Illustrator-related code.

           

          Also, you're setting a variable to the Portal row number twice, then use it directly for the exit condition. You could simply use

           

          Exit Loop if [ Get ( ActivePortalRowNumber ) = Job::Deliverable Count ]

          Go to Portal Row [ next ]

           

          Note that this could be problematic if somehow the count is < the row count; so you may want to use

           

          Go to Portal Row [ next ; exit after last ]

          • 2. Re: Export Adobe Illustrator file and edit contents w/AppleScript
            jbryan

            Thanks erolst!

             

            Yes, your suggestions did clean up my AppleScript. However, the Exit Loop (in the FileMaker Script) had to stay as I originally wrote it (w/two Set Variable commands) otherwise the AppleScript loop kept running.

            • 3. Re: Export Adobe Illustrator file and edit contents w/AppleScript
              jbryan

              Forgot to mention that it worked better to rewrite the script for a button that goes on each row of my Deliverable portal. That way, a user can create a legend for the specific Deliverable they're working on rather than all related Deliverables. Turns out, the loop was fun but it was overkill!

               

              FINAL FILEMAKER SCRIPT

              # create a file path in the temp folder naming the document with its UUID

              Set Variable [ $TemplatePath ; Value: Get (TemporaryPath) & “legend.ait” ]

               

              # export the file to the path

              Export Field Contents [ Job Settings::Legend Template ; “$TemplatePath” ]

               

              # create legend (in Illustrator with AS) for the deliverable row

                Set Variable [ $RowNumber ; Value: Get ( ActivePortalRowNumber ) ]

                Set Field [ Job::Deliverable Row ; $RowNumber ]

                Set Field [ Job::Deliverable Print Method ; Deliverable::Print Method ]

                Set Field [ Job::Deliverable Type ; Deliverable::Type ]

                Set Field [ Job::Deliverable Substrate ; Deliverable::Substrate ]

                Send Event [ “<unknown>” ; “aevt” ; “odoc” ; “$TemplatePath” ]

                Perform AppleScript [ Applescript Here… ]

               

              FINAL APPLESCRIPT

              tell application "FileMaker Pro Advanced"

                if it is running then

                tell current record

                set delivNumber to cell "Deliverable Row"

                set delivTotal to cell "Deliverable Count"

                set theDescription to cell "Event::Description"

                set theSize to cell "Event::Size"

                set theUPC to cell "Item::UPC"

                set theJob to cell "Job #"

                set theVendor to cell "Vendor"

                set thePrintMethod to cell "Deliverable Print Method"

                set theType to cell "Deliverable Type"

                set theSubstrate to cell "Deliverable Substrate"

                set theRequester to cell "User requester::Sort Name"

                set theDesigner to cell "User designer::Sort Name"

                set theEmail to cell "User designer::Email"

                end tell

                end if

              end tell

               

              tell application "Adobe Illustrator"

                tell document 1

                set the contents of text frame "Number" to delivNumber

                set the contents of text frame "Total" to delivTotal

                set the contents of text frame "Type1" to theType

                set the contents of text frame "Description" to theDescription

                set the contents of text frame "Size" to theSize

                set the contents of text frame "UPC" to theUPC

                set the contents of text frame "Job" to theJob

                set the contents of text frame "Vendor" to theVendor

                set the contents of text frame "PrintMethod" to thePrintMethod

                set the contents of text frame "Type2" to theType

                set the contents of text frame "Substrate" to theSubstrate

                set the contents of text frame "Requester" to theRequester

                set the contents of text frame "Designer" to theDesigner

                set the contents of text frame "Email" to theEmail

                end tell

              end tell