Quark Image Importing

Hi All,

Below code I got from the Quark forum, I was trying to run this scripts and it is working very fine abut after placing of few images I am getting one error, below is the code and error:


property DocWidth : 26 * 72 -- Document's width (in points)
property DocHeight : 20 * 72 -- Document's height (in points)
property DocMargins : 36 -- Documnent's margin (in points) (they are all the same for this script)
property LabelHeight : 14 -- Height of the Label text box (in points)
property LabelOffset : 6 -- Distance between the picture and the label (in points)
property CropMarks_Length : 24 -- Length of each crop marks (in points)
property CropMarks_Offset : 9 -- Distance between the crop marks and the picture (in points)
property CropMarks_Thickness : 0.5 -- Thickness of each crop marks (in points)
property TypeList : {"BMP ", "EPSF", "GIFf", "JPEG", "PDF ", "PICT", "PNGf", "TIFF"} -- Graphic File Format s (Modify to fit your needs)

-- Other properties (do not change the following values
property SourceFolder : "" -- Path (as text) of the picture folder
property DocName : "" -- The Quark document's name
property Top_Origin : 144 -- Top origin of the temporary picture (in points)
property Left_Origin : 144 -- Left origin of the temporary picture (in points)
property Size_Origin : 144 -- Width and Height of the temporary picture (in points)
property Page_Spaces : {} -- List of records of free space (per page)

tell application "QuarkXPress Passport"
   activate
   -- A) create a blank document that is 26" wide by 20" tall
   tell default document 1
      -- Save old values
      set Old_Facing to facing pages
      set Old_AutoText to automatic text box
      set Old_Horizontal to horizontal measure
      set Old_Vertical to vertical measure
      -- Set desired values
      set facing pages to false
      set automatic text box to false
      set horizontal measure to points
      set vertical measure to points
   end tell
   
   make new document at end with properties {page width:DocWidth, page height:DocHeight, top margin:DocMargins, bottom margin:DocMargins, left margin:DocMargins, right margin:DocMargins}
   set Page_Spaces to {}
   set end of Page_Spaces to {{TheTop:DocMargins, TheLeft:DocMargins, TheWidth:DocWidth - (2 * DocMargins), TheHeight:DocHeight - (2 * DocMargins)}}
   set DocName to name of document 1
   
   tell default document 1
      -- Restore changed values
      set facing pages to Old_Facing
      set automatic text box to Old_AutoText
      set horizontal measure to Old_Horizontal
      set vertical measure to Old_Vertical
   end tell
end tell

-- B) prompt for location of desired folder (this is a bit of a luxury -- I would be happy just to have it look in the same place every time and skip this step)
set QFolder to "Please locate the folder containing the images you wish to import"
tell application "QuarkXPress Passport"
   set SourceFolder to (choose folder with prompt QFolder) as text
end tell

set ItemList to list folder SourceFolder without invisibles
set FileList to {}
-- Making sure we only process your graphic files
repeat with ThisItem in ItemList
   set TheInfo to info for (file (SourceFolder & ThisItem))
   if folder of TheInfo is false then
      if (file type of TheInfo) is in TypeList then
         set end of FileList to (ThisItem as text)
      end if
   end if
end repeat

-- Making style sheets
tell application "QuarkXPress Passport"
   if not (exists character spec "Label" of document DocName) and not (exists style spec "Label" of document DocName) then
      set CharStyle to make new character spec at document DocName's end with properties {name:"Label", color:"Registration"}
      set ParaStyle to make new style spec at document DocName's end with properties {name:"Label"}
      set character style of ParaStyle to CharStyle
   end if
   
   repeat with ThisFile in FileList
      --1a) Create the picture box, place image and fit the box to its contents
      set {PicBox, BoxHeight, BoxWidth} to my Make_PicBox(ThisFile)
      --1b) Create crop marks.around picture box
      set {Crop1, Crop2, Crop3, Crop4, Crop5, Crop6, Crop7, Crop8} to my Make_CropMarks(PicBox)
      --2) Create a name label below the box.
      set TextBox to my Make_LabelBox(Top_Origin + BoxHeight + LabelOffset, BoxWidth, ThisFile)
      --3) Find a place for this group and move it there
      set selection to null
      repeat with ThisBox in {PicBox, TextBox, Crop1, Crop2, Crop3, Crop4, Crop5, Crop6, Crop7, Crop8}
         set selected of ThisBox to true
      end repeat
      my Place_ThisGroup()
   end repeat -- repeat with ThisFile in FileList
end tell


-->> Handlers
on Make_PicBox(ThisPicture)
   tell application "QuarkXPress Passport"
      tell document DocName
         tell current page
            set PicBox to make new picture box at end with properties {bounds:{Top_Origin, Left_Origin, Top_Origin + Size_Origin, Left_Origin + Size_Origin}}
            tell PicBox
               set image 1 to file ((SourceFolder & ThisPicture) as text)
               set PicBounds to (bounds of image 1)
               set TheWidth to item 3 of PicBounds
               set TheHeight to item 4 of PicBounds
               set width of bounds to TheWidth
               set height of bounds to TheHeight
               set runaround to none runaround
            end tell
         end tell
      end tell
   end tell
   return {PicBox, TheHeight as real, TheWidth as real}
end Make_PicBox

on Make_LabelBox(FromHeight, BoxWidth, ThisLabel)
   tell application "QuarkXPress Passport"
      set ParaStyle to object reference of style spec "Label" of document DocName
      tell document DocName
         tell current page
            set TextBox to make new text box at end with properties {bounds:{FromHeight, Left_Origin, FromHeight + LabelHeight, Top_Origin + BoxWidth}}
            tell TextBox
               set contents of story 1 to ThisLabel
               set style sheet of paragraph 1 of story 1 to ParaStyle
               set runaround to none runaround
            end tell
         end tell
      end tell
   end tell
   return TextBox
end Make_LabelBox

on Make_CropMarks(ThisBox)
   tell application "QuarkXPress Passport"
      tell document DocName
         tell current page
            copy (coerce (bounds of ThisBox as points rectangle) to list) to {T, L, B, R}
            set T to T as real
            set L to L as real
            set B to B as real
            set R to R as real
            
            set L1 to L - CropMarks_Offset - CropMarks_Length
            set L2 to L - CropMarks_Offset
            set R1 to R + CropMarks_Offset
            set R2 to R + CropMarks_Offset + CropMarks_Length
            set T1 to T - CropMarks_Offset - CropMarks_Length
            set T2 to T - CropMarks_Offset
            set B1 to B + CropMarks_Offset
            set B2 to B + CropMarks_Offset + CropMarks_Length
            
            set Crop1 to make new line box at end with properties {start point:{T, L1}, end point:{T, L2}, width:CropMarks_Thickness, color:"Registration"}
            set Crop2 to make new line box at end with properties {start point:{T, R1}, end point:{T, R2}, width:CropMarks_Thickness, color:"Registration"}
            set Crop3 to make new line box at end with properties {start point:{B, L1}, end point:{B, L2}, width:CropMarks_Thickness, color:"Registration"}
            set Crop4 to make new line box at end with properties {start point:{B, R1}, end point:{B, R2}, width:CropMarks_Thickness, color:"Registration"}
            
            set Crop5 to make new line box at end with properties {start point:{T1, L}, end point:{T2, L}, width:CropMarks_Thickness, color:"Registration"}
            set Crop6 to make new line box at end with properties {start point:{B1, L}, end point:{B2, L}, width:CropMarks_Thickness, color:"Registration"}
            set Crop7 to make new line box at end with properties {start point:{T1, R}, end point:{T2, R}, width:CropMarks_Thickness, color:"Registration"}
            set Crop8 to make new line box at end with properties {start point:{B1, R}, end point:{B2, R}, width:CropMarks_Thickness, color:"Registration"}
         end tell
      end tell
   end tell
   return {Crop1, Crop2, Crop3, Crop4, Crop5, Crop6, Crop7, Crop8}
end Make_CropMarks

on Place_ThisGroup()
   tell application "QuarkXPress Passport"
      tell document DocName
         set TheRef to (object reference of selection)
         set PlacingWidth to (width of bounds of TheRef) as real
         set PlacingHeight to (height of bounds of TheRef) as real
         my DoMenu("Edit", "Cut")
         set Place_Found to false
         repeat with ThisPage from 1 to Page_Spaces's length
            set SpaceList to (item ThisPage of Page_Spaces)
            if Place_Found is false then
               repeat with PlaceIndex from 1 to SpaceList's length
                  set ItsTop to TheTop of item PlaceIndex of SpaceList
                  set ItsLeft to TheLeft of item PlaceIndex of SpaceList
                  set ItsWidth to TheWidth of item PlaceIndex of SpaceList
                  set ItsHeight to TheHeight of item PlaceIndex of SpaceList
                  
                  if PlacingWidth <= ItsWidth and PlacingHeight <= ItsHeight then
                     set Place_Found to true
                     -- Remove used space from available space of that page
                     set (item ThisPage of Page_Spaces) to delete item PlaceIndex from (item ThisPage of Page_Spaces) -- Uses Acme Script Widgets
                     -- Separates the space vertically at Item's width and create remaining free space infos
                     if PlacingWidth < ItsWidth then -- There will be some free space to the right after placement
                        set FreeSpaceRigth to {TheTop:ItsTop, TheLeft:ItsLeft + PlacingWidth, TheWidth:ItsWidth - PlacingWidth, TheHeight:ItsHeight}
                        set end of (item ThisPage of Page_Spaces) to FreeSpaceRigth
                     end if
                     if PlacingHeight < ItsHeight then -- There will be some free space to the bottom after placement
                        set FreeSpaceDown to {TheTop:ItsTop + PlacingHeight, TheLeft:ItsLeft, TheWidth:PlacingWidth, TheHeight:ItsHeight - PlacingHeight}
                        set end of (item ThisPage of Page_Spaces) to FreeSpaceDown
                     end if
                     exit repeat
                  end if
               end repeat
            else
               set ThisPage to ThisPage - 1
               exit repeat
            end if
         end repeat
         
         if Place_Found is true then
            set current page to page ThisPage
            my DoMenu("Edit", "Paste")
            do updates
            my DoMenu("Item", "Group")
            set TheRef to (object reference of selection)
            set origin of bounds of TheRef to {ItsTop, ItsLeft}
         else
            my Add_Page()
            my DoMenu("Edit", "Paste")
            my Place_ThisGroup()
         end if
      end tell
   end tell
end Place_ThisGroup

on Add_Page()
   tell application "QuarkXPress Passport"
      tell document DocName
         make new page at end
         set end of Page_Spaces to {{TheTop:DocMargins, TheLeft:DocMargins, TheWidth:DocWidth - (2 * DocMargins), TheHeight:DocHeight - (2 * DocMargins)}}
      end tell
   end tell
end Add_Page

on SetTool(This_Tool)
   tell application "QuarkXPress Passport"
      tell document DocName
         if This_Tool is "Contents" then
            set tool mode to contents mode
         else if This_Tool is "Drag" then
            set tool mode to drag mode
         end if
      end tell
   end tell
end SetTool

on DoMenu(This_Menu, This_SubMenu)
   tell application "QuarkXPress Passport"
      try
         select menu item This_SubMenu of menu This_Menu
      on error errMsg number errNum
         display dialog ("An error " & errNum & " has occured" & return & return & errMsg) with icon stop
      end try
   end tell
end DoMenu 

And I really don’t know about error type. Please let me know what is this.

Thanks
Macrajeev

If you run this from script editor and view the event log, can you tell where the error is being thrown?

Do you have Acme Script Widget installed? This script uses the OSAX to handle list functions.