in

Quark Forums

Moving box to a layer

Last post 11-24-2009 3:04 AM by Emma. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 11-16-2009 9:22 AM

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,184

    Moving box to a layer

    I have a script to create a 'guide' box on a non-printing layer. I select the box and run the script and a magenta outlined box appears to show me the area in which items can appear.

    However, if my selected box is on page 2, the new box appears on page 2 until the command:

         move picture box "NEW" to beginning of layer "GUIDES"


     - at which point if moves to page 1

     How can I persuade my new picture box to stay on the page where it was created? Here is the script. Make a 2 page Quark doc, draw a picture box on page 2, keep it selected, then run the script. (My measurements are in millimetres, in case that causes problems...)

     


    set layer_exists to "NO"
    tell document 1 of application "QuarkXPress"
         set item spread coords to true
         set my_box to object reference of selection
         set the_props to properties of my_box
         tell current spread
              make new picture box at beginning
              set name of picture box 1 to "NEW"
              set bounds of picture box "NEW" to bounds of the_props
              tell picture box "NEW"
                   set new_width to (width of bounds as real) - 3.7
                   set new_height to (height of bounds as real) - 3.7
                   set new_x to (left of bounds as real) + 3.7
                   set new_y to (top of bounds as real) + 3.7
                   set width of bounds to new_width
                   set height of bounds to new_height
                   set left of bounds to new_x
                   set top of bounds to new_y
                   set frame to {color:color spec "Magenta" of document 1 of application "QuarkXPress", gap color:null, gap shade:"100%", inside trap:default, outside trap:default, shade:"100%", style:solid line, width:".2 pt", gap opacity:"100%"}
              end tell
         end tell
        
        
         repeat with i from 1 to count of layers
              if name of layer i = "GUIDES" then set layer_exists to "YES"
         end repeat
         if layer_exists is not "YES" then
              make new layer at front
              set name of layer 1 to "GUIDES"
              set suppress print of layer 1 to true
         end if
         set locked of layer "GUIDES" to false
         --This is the line that moves the box to page 1, which is a prob if working on a multipage doc...
         move picture box "NEW" to beginning of layer "GUIDES"
         set content of picture box "NEW" to none content
         set name of generic box "NEW" to null
         set locked of layer "GUIDES" to true
        
         set item spread coords to false
    end tell


    -------------------------
    [This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

     

  • 11-16-2009 10:28 AM In reply to

    Re: Moving box to a layer

    Put your move line inside of your current spread tell block
  • 11-17-2009 3:35 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,184

    Re: Moving box to a layer

     That does seem sensible. I've moved the creation of the layer bit to the beginning so I can do all the stuff within one 'tell' block. BUT for some reason I get the message:

    Can’t get picture box "NEW" of current spread of document 1.

     when the script gets to the 'move picture box to layer' line. It's happy to recognise the picture box in every other line. Very odd. It does the same thing if I say 'picture box 1' so I think the problem is to do with scope.

    So current script is:

     

    set layer_exists to "NO"
    tell document 1 of application "QuarkXPress"
        
         repeat with i from 1 to count of layers
              if name of layer i = "GUIDES" then set layer_exists to "YES"
         end repeat
         if layer_exists is not "YES" then
              make new layer at front
              set name of layer 1 to "GUIDES"
              set suppress print of layer 1 to true
         end if
         set locked of layer "GUIDES" to false
        
         set item spread coords to true
         set my_box to object reference of selection
         set the_props to properties of my_box
         tell current spread
              make new picture box at beginning
              set name of picture box 1 to "NEW"
              set bounds of picture box "NEW" to bounds of the_props
              move picture box "NEW" to beginning of layer "GUIDES"
             
              tell picture box "NEW"
                   set new_width to (width of bounds as real) - 3.7
                   set new_height to (height of bounds as real) - 3.7
                   set new_x to (left of bounds as real) + 3.7
                   set new_y to (top of bounds as real) + 3.7
                   set width of bounds to new_width
                   set height of bounds to new_height
                   set left of bounds to new_x
                   set top of bounds to new_y
                   set frame to {color:color spec "Magenta" of document 1 of application "QuarkXPress", gap color:null, gap shade:"100%", inside trap:default, outside trap:default, shade:"100%", style:solid line, width:".2 pt", gap opacity:"100%"}
              end tell
              set content of picture box "NEW" to none content
              set name of generic box "NEW" to null
         end tell
        
        
        
         set locked of layer "GUIDES" to true
        
         set item spread coords to false
    end tell


    -------------------------
    [This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

  • 11-17-2009 4:07 AM In reply to

    Re: Moving box to a layer

     Im thinking this may get you what you want or closer to it…

    tell application "QuarkXPress"
         tell document 1
              set item spread coords to true
              try
                   set my_box to object reference of selection
                   set the_props to properties of my_box
              on error
                   display dialog "You've nothing selected u muppet!!!"
                   return
              end try
              if exists layer "GUIDES" then
                   set Target_Layer to layer "GUIDES"
                   set locked of Target_Layer to false
              else
                   set Target_Layer to make new layer at front ¬
                        with properties {name:"GUIDES", suppress print:true}
              end if
              tell current spread
                   make new picture box at beginning
                   set name of picture box 1 to "NEW"
                   set bounds of picture box "NEW" to bounds of the_props
                  
                   tell picture box "NEW"
                        set new_width to (width of bounds as real) - 3.7
                        set new_height to (height of bounds as real) - 3.7
                        set new_x to (left of bounds as real) + 3.7
                        set new_y to (top of bounds as real) + 3.7
                        set width of bounds to new_width
                        set height of bounds to new_height
                        set left of bounds to new_x
                        set top of bounds to new_y
                        set frame to {color:color spec "Magenta" of document 1 of application "QuarkXPress", gap color:null, gap shade:"100%", inside trap:default, outside trap:default, shade:"100%", style:solid line, width:".2 pt"}
                   end tell
                   try
                        move picture box "NEW" to beginning of layer "GUIDES"
                   end try
                   set content of picture box "NEW" to none content
                   set name of generic box "NEW" to null
              end tell
              set locked of Target_Layer to true
              set item spread coords to false
         end tell
    end tell

    Pesonally I would just do the calculation of the new box's bounds first then make new with properties my bounds.

     Scripting of layers with Quark can be problematic hence the try move…

  • 11-17-2009 4:09 AM In reply to

    Re: Moving box to a layer

    BTW I dropped gap opacity:"100%" for my V6.5 Got 5 minutes so I tried how I would have done bounds…

     

    tell application "QuarkXPress"
         tell document 1
              set item spread coords to true
              try
                   set This_Box to object reference of selection
                   set My_Bounds to bounds of This_Box as list -- Might look like one but it ain't so ask for list
                   -- log My_Bounds
              on error
                   display dialog "You've nothing selected u muppet!!!"
                   return
              end try
              if exists layer "GUIDES" then
                   set Target_Layer to layer "GUIDES"
                   set locked of Target_Layer to false
              else
                   set Target_Layer to make new layer at front ¬
                        with properties {name:"GUIDES", suppress print:true}
              end if
              set {T, L, B, R} to {(item 1 of My_Bounds) as real, (item 2 of My_Bounds) as real, (item 3 of My_Bounds) as real, (item 4 of My_Bounds) as real}
              -- log T
              tell current spread -- This can be a bit doggy too!
                   set New_Box to make new picture box at beginning ¬
                        with properties {name:null, bounds:{(T + 3.7), (L + 3.7), (B - 3.7), (R - 3.7)}, content:none content, frame:{color:color spec "Magenta" of document 1 of application "QuarkXPress", gap color:null, gap shade:"100%", inside trap:default, outside trap:default, shade:"100%", style:solid line, width:".2 pt"}}
                   -- return
                   try
                        move New_Box to beginning of layer "GUIDES"
                   end try
              end tell
              set locked of Target_Layer to true
              set item spread coords to false
         end tell
    end tell 

  • 11-23-2009 2:44 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,184

    Re: Moving box to a layer

     Sorry for delay in replying, things got a bit busy... but this works beautifully! Thanks so much, and a much more elegant script than my clunky one. Will tidy up the bounds too as suggested!

     Emma

  • 11-23-2009 4:48 AM In reply to

    Re: Moving box to a layer

    Emma, both document & page have an 'active layer' property so it would be better to use this before creating the box then moving it. That way your box would just be created in the correct location. At present the 'try' was only because if the layer was created by the script then the new box was already in that layer if you get where Im coming from? Glad it helped anyhow…
  • 11-24-2009 3:04 AM In reply to

    • Emma
    • Top 10 Contributor
    • Joined on 07-07-2004
    • Leeds, UK
    • Posts 1,184

    Re: Moving box to a layer

    I spoke too soon! The box was not moving to the layer - as soon as I removed the 'try' I got the old message that it couldn't find the box 'NEW'. I'll try what you suggested with Active Layer next... if I get a moment!

     

    Emma

Page 1 of 1 (8 items)
Powered by Community Server (Commercial Edition), by Telligent Systems