Author Topic: Duplicating a Picture Box in Quark  (Read 663 times)

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Duplicating a Picture Box in Quark
« on: September 26, 2016, 10:54:08 AM »
I figured out that this basic part was the thing messing up my more complicated script. If I have 9 picture boxes in Quark, this script is duplicating picture box 1 nine times instead of duplicating all 9 boxes just one time each. Any help I could get with why this isn't working right would be awesome. :)

Code: [Select]
on open of droppedFiles --> This is the line of code that begins a droplet. 
   with timeout of 900 seconds -->The script will try for 15 minutes before timing out. Default is 2 minutes, which is way too little.
       
       
       
       tell application "QuarkXPress"
           activate
           
           repeat with afile in droppedFiles
               open afile
               
               
               
               tell document 1
                   
                   set pictureBoxes to every picture box
                   
                   repeat with i from 1 to number of pictureBoxes
                       set pictureBox to item i of pictureBoxes
                       set duplicateBox to duplicate pictureBox to after pictureBox
                   end repeat
                   
                   close saving yes
                   
                   
               end tell --end of tell document 1 block
           end repeat --end of first repeat loop
       end tell --end of tell Quark block
   end timeout
end open --> This is the line of code that ends a droplet.

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Duplicating a Picture Box in Quark
« Reply #1 on: September 27, 2016, 07:09:53 AM »
Hi! The problem is when you duplicate a box at after another one, it takes the source box' number and add 1. So duplicating box #1 results in a new box becoming box #2; cycling through your results (pictureBoxes), will then take box #2 which is the one you just created (duplicated), so box #1's duplicate. And so on. You end up with as many copies of the #1. Does it make sense to you?
So the idea is to take the list in reverse (so duplicating the last item won't interfere with the rest of the script) which can be done like this:
repeat with i from (number of pictureBoxes) to 1 by -1

HTH.
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Duplicating a Picture Box in Quark
« Reply #2 on: October 03, 2016, 11:44:44 AM »
Thanks so much! That really helped. :)

The duplicating part works great. I'm having an issue once I try to resize the duplicated picture box. The image has a tendency to want to move with the picture box.
I tried setting the content lock and format lock for the image to true. Despite being locked, the image still moves. Is there another setting I hadn't thought of that would change it so I can resize the picture box without the image moving?

Code: [Select]
-----------------------------------------------------------------------------------------	

--CHOOSING THE FILES TO PROCESS
tell application "Finder"
set myFolder to choose folder with prompt "Select a folder"
set droppedFiles to (every file of folder myFolder whose name extension contains "qx") as alias list
end tell

-----------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------

--DUPLICATING THE PICTURE BOXES, RESIZING THE PICTURE BOXES & ADDING A DROP SHADOW TO EACH PICTURE BOX

tell application "QuarkXPress"
activate

repeat with afile in droppedFiles
open afile as alias

tell document 1

--The fancy part that adds a drop shadow to images in the document only once
set pictureBoxes to every picture box
repeat with i from (number of pictureBoxes) to 1 by -1
set pictureBox to item i of pictureBoxes


--Duplicating the picture box
set duplicateBox to duplicate pictureBox to after pictureBox


--Trying to lock the image
if content lock of image 1 of pictureBox is false then set content lock of image 1 of pictureBox to true
if format lock of image 1 of pictureBox is false then set format lock of image 1 of pictureBox to true

display dialog "Content lock: " & content lock of image 1 of pictureBox as string
display dialog "Format lock: " & format lock of image 1 of pictureBox as string


--Getting the bounds (coordinates) of the picture box
set y1 to coerce (item 1 of (bounds of pictureBox as list)) to real
set x1 to coerce (item 2 of (bounds of pictureBox as list)) to real
set y2 to coerce (item 3 of (bounds of pictureBox as list)) to real
set x2 to coerce (item 4 of (bounds of pictureBox as list)) to real


--Moving the top of the box down so it is only 0.08" high but the other coordinates are the same as the original box that was duplicated
set new_y1 to y2 - 0.08 as number
set bounds of duplicateBox to {new_y1, x1, y2, x2}


--Adding the drop shadow to the duplicated box
select duplicateBox
tell application "System Events" to key code 97 using {command down} -->Pressing Command F6 to activate the drop shadow item style

set selection to null

end repeat

-----------------------------------------------------------------------------------------



-----------------------------------------------------------------------------------------

--UNLOCKING PAGE ITEMS THAT THE SCRIPT LOCKED
try
set format lock of every item to false
set content lock of every item to false
set locked of every item to false
end try


-----------------------------------------------------------------------------------------



-----------------------------------------------------------------------------------------

--SAVING & CLOSING THE DOCUMENTS

close saving yes

---------------------------------------------------------------


end tell --end of tell document 1 block
end repeat --end of first repeat loop
end tell --end of tell Quark block

--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
« Last Edit: October 03, 2016, 03:05:54 PM by mbornbach »

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Duplicating a Picture Box in Quark
« Reply #3 on: October 04, 2016, 02:31:46 AM »
Hi! Glad it works :-)

As for the content, I don't really get what you mean. Are you trying to keep the picture in place while moving one of the edges? (Like taking one handle of the middle of the box and go inside of the box?) If so, you need to subtract 0.08 from the image positon as well. Are you with me?

As for the locking part, here is a piece of code Matthias or someone else at Quark posted here (as far as I remember). Mind the word item (as you code) might be too wide for your requirements.

Code: [Select]
tell application "QuarkXPress9"
activate
tell document 1
try
set locked of (every generic box whose locked is true) to false

set format lock of (every image whose format lock is true) to false
set content lock of (every image whose content lock is true) to false

set format lock of (every story whose format lock is true) to false
set content lock of (every story whose content lock is true) to false
end try
end tell
end tell
beep 2
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Duplicating a Picture Box in Quark
« Reply #4 on: October 04, 2016, 08:10:54 AM »
Thanks. I'm trying to move the top edge of the picture box down, so that instead of being 2-3 inches high, the duplicated box is only .08" high. It should leave the image in place, cropping it so only a tiny bit of the bottom of the duplicated image is showing. Instead it moves the image down when I resize the duplicate box, so that a tiny bit of the top of the image is showing. 

What we usually do, by hand, is duplicate a picture box, send it backward, add a drop shadow to the duplicated box and move the top handle of the duplicated box down. This way, we get this nice subtle drop shadow effect that only shows up on the bottom of the original image, instead of all the way around the image. Of course, this requires both the original image and the image in the duplicated picture box to remain in the exact same place.

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Duplicating a Picture Box in Quark
« Reply #5 on: October 05, 2016, 02:33:16 AM »
OK, I understand better. It sounds like the script doesn't behave like by-hand.
So you'll need to do maths to "keep" the picture like in place. If the original is at 0,0, then the maths is simple: offset the image minus the difference between original's top and duplicate's top. Does it make sense? The problem is if the original is already offset leftwards and upwards, you'll need to do more complicate maths (in scripting, that is getting position in Quark, coercing the values, do the maths and reposition the picture in the duplicate). Does all this make sense to you?
This piece of code shall give you the image offset:

Code: [Select]
tell application "QuarkXPress9"
tell document 1
set props to properties of image 1 of current box
set {off1, off2} to (coerce offset of props to list)
set {Ys, Xs} to {coerce off1 to real, coerce off2 to real}
end tell
end tell
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Duplicating a Picture Box in Quark
« Reply #6 on: October 05, 2016, 10:02:16 AM »
It's working! :) Thanks Jean-Marie. I didn't think to use offset. I was trying to use the image's bounds at one point, but that wasn't working like I'd hoped.

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Duplicating a Picture Box in Quark
« Reply #7 on: October 06, 2016, 02:02:46 AM »
Glad it works! Clearly it's not easy to get everything that is behind the scenes! To be honest I learnt such a lot from Michel!
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Duplicating a Picture Box in Quark
« Reply #8 on: October 10, 2016, 05:23:41 PM »
Is it possible to group items in Quark? I found a bunch of information in the dictionary & applescript guide about working with boxes that are already grouped, but I'm not finding information on how to group the boxes.  I tried using system events to press command g after selecting the two boxes, but that's not grouping them. Or maybe I'm close with the system events solution if quark can't group boxes?

Code: [Select]
on open of droppedfiles
   
   tell application "QuarkXPress"
       activate
       repeat with afile in droppedfiles
           open afile as alias with Suppress All Warnings
           tell document 1
               
               --Looping through every picture box
               set pictureBoxes to every picture box
               repeat with i from (number of pictureBoxes) to 1 by -1
                   set pictureBox to item i of pictureBoxes
                   
                   
                   --Duplicating the picture box
                   set duplicateBox to duplicate pictureBox to after pictureBox
                   
                   
                   --Adding the drop shadow to the duplicated box
                   select duplicateBox
                   tell application "System Events" to key code 97 using {command down} -->Pressing Command F6 to activate the drop shadow item style
                   set selection to null -->unselecting the duplicate box, otherwise the shadow is applied to both boxes
                   
                   
                   --Trying to select the two boxes
                   select duplicateBox
                   select pictureBox
                   
                   
                   --Trying to group the two boxes           
                   try
                       tell application "System Events" to key code 5 using {command down} -->Pressing Command G to group the items
                   on error
                       my do_submenu("QuarkXPress", "Item", "Group")
                   end try
                   
                   
                   set selection to null
                   
               end repeat
               
           end tell
       end repeat
   end tell
end open


--The UI Scripting select submenu function
on do_submenu(app_name, menu_name, menu_item)
   try
       -- bring the target application to the front
       tell application app_name
           activate
       end tell
       tell application "System Events"
           tell process app_name
               tell menu bar 1
                   pick menu bar item menu_name
                   tell menu bar item menu_name
                       tell menu menu_name
                           pick menu item menu_item
                           click menu item menu_item
                       end tell
                   end tell
               end tell
           end tell
       end tell
       return true
   on error error_message
       return false
   end try
end do_submenu

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Duplicating a Picture Box in Quark
« Reply #9 on: October 11, 2016, 03:05:19 AM »
Hi! Here is how to group items. The idea is to have multiple items selected as to get the ability of grouping sth. Then you can either group those items like following or selecting menu item 10 of menu 5 (at least at my end). HTH.
Note that making new box at beginning in the following won't work (probably it would by naming the boxes within the properties).

Code: [Select]
tell application "QuarkXPress9"
tell document 1
set Box1 to make new picture box at end with properties {bounds:{"15 mm", "15 mm", "50 mm", "50 mm"}}
set Box2 to make new picture box at end with properties {bounds:{"50 mm", "50 mm", "100 mm", "100 mm"}}
try
set tool mode to drag mode
end try
set selection to null
-- Select the items to be grouped
set selected of Box1 to true
set selected of Box2 to true
set grouped of group box 1 to true
--set selection to null
end tell
end tell
beep 2
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =