3 Replies Latest reply on Jun 17, 2011 3:19 AM by OlivierBerquin

    [AS] Beast of a script needs help converting from Quark 8 to InDesign CS5

    Luke Hodsdon

      First off, THANK YOU for even reading this post. Here's the dilema. I work in a publishing company that used an AppleScript from Quark 8 to automate our pagination from set text we pull from our sales reps worksheets. About 8 months ago we switched fully to InDesign CS5, but have had to hold onto Quark 8 to be able to keep running our pagination. I'd like to see if the geniuses (yes, I've been trolling these forums looking to solve this myself and seen some great problems fixed) on these forums can help me figure out the proper conversion I would need to be able to leave Quark 8 in the rearview.

       

      Here's our current code... (I warned you it was a beast)

       

      set Ad_Props to {¬
           {Ad_Label:"SPREAD – ", Ad_Width:2.495, Ad_Height:1.62, Ad_Text_Angle:0}, ¬
           {Ad_Label:"FULL – ", Ad_Width:1.225, Ad_Height:1.62, Ad_Text_Angle:0}, ¬
           {Ad_Label:"SPREAD – ", Ad_Width:2.495, Ad_Height:1.62, Ad_Text_Angle:0}, ¬
           {Ad_Label:"JUNIOR – ", Ad_Width:0.90625, Ad_Height:1.62, Ad_Text_Angle:0}, ¬
           {Ad_Label:"1/2H – ", Ad_Width:1.225, Ad_Height:0.785, Ad_Text_Angle:0}, ¬
           {Ad_Label:"1/2V – ", Ad_Width:0.5875, Ad_Height:1.62, Ad_Text_Angle:90}, ¬
           {Ad_Label:"1/3V – ", Ad_Width:0.5875, Ad_Height:1.2025, Ad_Text_Angle:90}, ¬
           {Ad_Label:"1/4 – ", Ad_Width:0.5875, Ad_Height:0.785, Ad_Text_Angle:0}, ¬
           {Ad_Label:"1/4 Strip – ", Ad_Width:0.26875, Ad_Height:1.62, Ad_Text_Angle:90}, ¬
           {Ad_Label:"1/8H – ", Ad_Width:0.5875, Ad_Height:0.3675, Ad_Text_Angle:0}, ¬
           {Ad_Label:"1/8V – ", Ad_Width:0.26875, Ad_Height:0.785, Ad_Text_Angle:90}, ¬
           {Ad_Label:"Junior (GOLF) – ", Ad_Width:0.8, Ad_Height:1.62, Ad_Text_Angle:0}, ¬
           {Ad_Label:"1/3V (GOLF) – ", Ad_Width:0.375, Ad_Height:1.62, Ad_Text_Angle:90}, ¬
           {Ad_Label:"1/3sq. (GOLF) – ", Ad_Width:0.8, Ad_Height:0.785, Ad_Text_Angle:0}, ¬
           {Ad_Label:"1/6V (GOLF) – ", Ad_Width:0.375, Ad_Height:0.785, Ad_Text_Angle:90}, ¬
           {Ad_Label:"Directory Listing Only – ", Ad_Width:0.3, Ad_Height:0.3, Ad_Text_Angle:0}, ¬
           {Ad_Label:"INSERT (# in notes) – ", Ad_Width:0.3, Ad_Height:0.3, Ad_Text_Angle:0}, ¬
           {Ad_Label:"Other (See Notes) – ", Ad_Width:0.3, Ad_Height:0.3, Ad_Text_Angle:0}, ¬
           {Ad_Label:"------------ – ", Ad_Width:0.3, Ad_Height:0.3, Ad_Text_Angle:0}}
      set Position_Width to number
      set Position_Width to 11.375
      set Position_Height to number
      set Position_Height to 1.875
      set Jump_Height to number
      set Jump_Height to 0
      set Variable_Count to number
      set Variable_Count to 0
      set Variable_Height to number
      set Variable_Height to (1.875 + (1.62 * Variable_Count))
      set Last_Ad to number
      set Last_Ad to 0
      
      tell application "QuarkXPress"
           activate
           try
                display dialog "WARNING: This version of 'Dummy Square Maker' runs much slower than the last version, a confirmation will tell you when you are finished. Please be patient." & return & return & "Make sure to have the text box selected" buttons {"Cancel", "Accept"} default button 2 with icon caution
                set ThisBox to object reference of current box
                
                tell story 1 of ThisBox
                     set (every paragraph where it is return) to ""
                     set style sheet of every text to null
                     set style sheet of every text to "DUMMY TEXTS"
                     repeat with i from 1 to (count of paragraphs)
                          try
                               tell paragraph i
                                    set ThePage to my get_CurrentPage()
                                    try
                                         if it contains " – " then
                                              set style sheet to "AD SIZE"
                                              set Ad_Size to contents
                                              set {This_Width, This_Height, this_angle} to {"", "", ""}
                                              repeat with This_Ad in Ad_Props
                                                   if Ad_Size contains (Ad_Label of This_Ad) then
                                                        set This_Width to Ad_Width of This_Ad
                                                        set This_Height to Ad_Height of This_Ad
                                                        set this_angle to Ad_Text_Angle of This_Ad
                                                        exit repeat
                                                   end if
                                              end repeat
                                              
                                              set Ad_Box to my Make_Box(ThePage, {1.875, 10.875, This_Height + 1.875, This_Width + 10.875}, this_angle)
                                              duplicate contents to (end of Ad_Box)
                                              
                                         else if it contains "—" then
                                              set style sheet to "AD REP/PLACEMENT"
                                              duplicate contents to (end of Ad_Box)
                                              
                                         else if it starts with "©" then
                                              set style sheet to "AD REP/PLACEMENT"
                                              delete (character 1)
                                              duplicate contents to end of Ad_Box
                                              
                                              if Position_Width ≤ 19.75 then
                                                   set Jump_Height to Jump_Height + This_Height
                                                   
                                                   (*_________________This is where Ad Boxes Stack_________________*)
                                                   if (Jump_Height ≤ 1.62) then
                                                        set origin of bounds of Ad_Box to {Position_Height, Position_Width}
                                                        set Position_Height to Position_Height + This_Height
                                                        
                                                        (*_________________This is where Ad Boxes more right_________________*)
                                                   else
                                                        set Position_Height to Variable_Height
                                                        (*set Position_Width to Position_Width + This_Width + 0.05*)
                                                        set Position_Width to Position_Width + Last_Ad + 0.05
                                                        set origin of bounds of Ad_Box to {Position_Height, Position_Width}
                                                        set Jump_Height to This_Height
                                                        set Position_Height to Variable_Height + This_Height
                                                   end if
                                                   set Last_Ad to This_Width
                                                   
                                                   (*_________________This is where New Row appears_________________*)
                                              else
                                                   set Position_Width to 11.375
                                                   set Variable_Count to Variable_Count + 1
                                                   set Variable_Height to (1.875 + (1.62 * Variable_Count))
                                                   set Position_Height to Variable_Height
                                                   set origin of bounds of Ad_Box to {Position_Height, Position_Width}
                                                   set Position_Height to Position_Height + This_Height
                                                   set Jump_Height to This_Height
                                                   set Last_Ad to This_Width
                                              end if
                                              
                                         else
                                              duplicate contents to (end of Ad_Box)
                                         end if
                                    end try
                               end tell
                          on error errmsg number errnum
                               display dialog "There has been an error " & "[" & i & "] (" & errmsg & " [" & errnum & "])" buttons {"Okay"} default button 1 with icon stop
                          end try
                     end repeat
                     delete contents
                     set style sheet of every text to null
                end tell
                beep 2
                display dialog "Automation Finished" & return & return & "IMPORTANT NOTE: Color your Ad Squares according to Sales Rep, and select them all and 'BRING TO FRONT [F5]', this is VITAL." buttons {"Okay"} default button 1 with icon stop
           on error errmsg number errnum
                beep 3
                if errnum ≠ -128 then
                     beep
                     display dialog errmsg & " [" & errnum & "]" buttons {"OK"} default button 1 with icon stop
                end if
           end try
      end tell
      
      on Make_Box(ThePage, TheBounds, this_angle)
           local ThePage, TheBounds, this_angle
           tell application "QuarkXPress"
                tell page ThePage of document 1
                     set Ad_Box to make new text box at end with properties {bounds:TheBounds, vertical justification:centered, color:"Rep_Other", shade:100, opacity:10, text angle:this_angle, frame:{style:solid line, color:"Black", shade:60, width:0.1}}
                end tell
           end tell
           (*end tell*)
           return Ad_Box
      end Make_Box
      
      on get_CurrentPage()
           tell application "QuarkXPress"
                tell document 1
                     return page number of current page
                end tell
           end tell
      end get_CurrentPage
      

        • 1. Re: [AS] Beast of a script needs help converting from Quark 8 to InDesign CS5
          OlivierBerquin

          Hi Luke,

           

          Do you know AS language?
          At first glance, this script shouldn’t be difficult to transcode to InDesign ...

          How to address the paragraph style is a little different.Otherwise, it's almost the same as for QXP.

           

          I don’t think anyone here will do all the transcoding for you, but if you are worried about a particular topic, can you tell us the problem.

           

          Regards.

           

          Oli.

          • 2. Re: [AS] Beast of a script needs help converting from Quark 8 to InDesign CS5
            Luke Hodsdon Level 1

            Thank Oli.

            I did write that script for Quark, but it was from a lot of forum surfing and trial and error. I know some AS coding, but hearing that the transition could be fairly simple I'm willing to give anything a try. My poking and prodding will have to be on hold for a while as our next magazine production cycle is rolling in.

             

            I'm sure i'll have some questions when i start to get my hands dirty.

             

            Thanks!

            • 3. Re: [AS] Beast of a script needs help converting from Quark 8 to InDesign CS5
              OlivierBerquin Level 1

              Hi,

               

              I think with this, you can already make good progress in your work.

              Good luck!

               

              --

               

              global mydocument

               

              tell application "Adobe InDesign CS5.5"

               

                   set mydocument to active document

               

                   tell mydocument

               

                        set myParaStyle to paragraph style "DUMMY TEXTS"

               

                        tell page 1

                             set TheBounds to {0, 0, 20, 50}

                             set Ad_Box to make text frame

                             tell Ad_Box

                                  set geometric bounds to TheBounds

                                  set vertical justification of text frame preferences to center align

                                  set contents to "This is the contents"

                             end tell

               

                             set myStory to parent story of Ad_Box

                             set applied paragraph style of every paragraph of myStory to myParaStyle

                        end tell

                   end tell

              end tell

              --

               

              Your two handlers then look like this:

               

               

              --

              on Make_Box(ThePage, TheBounds, this_angle)

                   local ThePage, TheBounds, this_angle

                   tell application "Adobe InDesign CS5.5"

                        tell page ThePage of mydocument

                             set Ad_Box to make text frame

                             tell Ad_Box

                                  set geometric bounds to TheBounds

                                  set vertical justification of text frame preferences to center align

                             end tell

                        end tell

                   end tell

                   return Ad_Box

              end Make_Box

               

               

              on get_CurrentPage(CurrentTextFrame)

                   tell application "Adobe InDesign CS5.5"

                        tell mydocument

                             return name of parent page of parent page of CurrentTextFrame

                        end tell

                   end tell

              end get_CurrentPage

              --

               

              Shorter version:

              --

              on get_CurrentPage(CurrentTextFrame)

                   tell mydocument of application "Adobe InDesign CS5.5"

                        return name of parent page of parent page of CurrentTextFrame

                   end tell

              end get_CurrentPage

              --

               

              Ce message a été modifié par: OlivierBerquin