Author Topic: Q8 AppScp: text box syntax - newbie needs help!  (Read 2287 times)

0 Members and 1 Guest are viewing this topic.

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Q8 AppScp: text box syntax - newbie needs help!
« on: April 05, 2009, 12:27:47 PM »
UPDATE: this morning tabs were my problem... now is the least of my problems.
it seems like such a simple task: create a text box at the top of each page (just two pages), throw in some variables (same for each one) and format it a little.
and if i want to come back and update the info from the variables, overwrite the contents of both boxes without creating a new one on top. 

i am editng this posting from this morning, and replaced the code below, but not the associated message.
i'm trying to stay upbeat here, but this is so frustrating.
help.
-------------------------------------

hey everyone
i know this falls into probably the most basic of basic questions... which tells you how new i am.
-- i need to set a tab in my text box.
-- i also want it to test if it "SlugTxt" text box exists
-- and if it does exists to delete text and overwrite contents
-- and if it does not exist to create and write text.

am i being too greedy? if you could just help with the syntax on the tab set i can probably figure out the rest.
any help would be so great. its a sunny sunday afternoon here in NY and i just cant get this! argh.
it compiles but it doesnt work!

-- action to  make slug
tell application "QuarkXPress"
   activate
   -- if i add in the "of page 2" here it compiles but doesnt run.
       -- but i dont know how to make it make/edit the text box for "every" page.
   tell layer "Non-Printing" of page 2 of layout space 1 of project 1
      
      set SlugTxt to make text box at beginning with properties {bounds:{"-1p4", "0p", "0p", "51p"}, name:"SlugText", color:"White"}
      
      tell story 1 of SlugTxt
         set contents of it to (companyname & " — " & jobdesc & tab & "Proof " & " " & proofno1 & " — " & nowdate)
         
         tell paragraph 1 of story 1 of SlugTxt
            set font to "Times New Roman"
            set size to "9pt"
            set style to {bold}
            set color to "slug line-does not print"
            
            -- cant get the tab to set. throws up an error
            --set tab to {{justification:right, position:{"50p9"}}}
         end tell
      end tell
   end tell
end tell



« Last Edit: April 05, 2009, 10:53:14 PM by 4610036 »

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #1 on: April 06, 2009, 04:58:51 AM »
You need to set the paragraph's "Tab List" like so…

001   tell application "QuarkXPress"
002        activate
003        if not (exists document 1) then error "No document is open."
004        if not (exists current box) or box type of current box ¬
005             is not text box type then error "No text box is selected"
006        tell document 1
007             set Selected_Box to current box
008             tell Selected_Box
009                  tell paragraph 1
010                       set tab list to {{justification:left justified, position:"10 mm"}, {justification:left justified, position:30}}
011                  end tell
012             end tell
013        end tell
014   end tell

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #2 on: April 06, 2009, 09:38:05 AM »
thanks larsen
drat i circled around that line for ages yesterday. thanks so much
its frustrating when you know if must be that simple.  :)

i still havent quite gotten the syntax on this text box. i'm a bit confused by using the set SlugTxt (variable  name) to make text box. 

but you cant ask if it exists until you define it. but the way i have the code, the definition is "making it"

if i just define it as a name: "name_box", it seems to trip up when i tell it to set contents of "name_box".


.........AND....
i want to create it at the top of both pages, but it doesnt like the "every page" reference.

tell layer "Non-Printing" of every page of layout space 1 of project 1
      set SlugTxt to make text box at beginning with properties {bounds:{"-1p4", "0p", "0p", "51p"}, name:"SlugText", color:"White"}
      
   end tell
   tell story 1 of SlugTxt
      set contents of it to (compname & " — " & jobdesc & tab & "Proof " & " " & proofno1 & " — " & nowdate)


i'm sure youre busy though. i'll take another stab are overall structure and see if that doesnt help.
thanks for the help along. 
every little bit helps, and the struggling along this road is all part of the learning process! yay!

really appreciate the help.

m./

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #3 on: April 06, 2009, 10:29:02 AM »
You need to set up a repeat loop to do it for every page try;

set thePages to every page of layout space 1 of project 1
repeat with eachPage in thePages
    tell layer "Non-Printing" of eachPage
        set SlugTxt to make text box at beginning with properties {bounds:{"-1p4", "0p", "0p", "51p"}, name:"SlugText", color:"White"}
    end tell
  -- tell story 1 of Slugtxt etc in here
end repeat

To find out if it already exists you need to use the name "SlugText", which you have assigned at creation time, to select on. I'm not going to guarantee the syntax here as I haven't got Quark running to test on at the minute. But I think it would be

set thePages to every page of layout space 1 of project 1
repeat with eachPage in thePages
  tell layer "Non-Printing" of eachPage
    try
        set SlugTxt to first text box whose name is "SlugText"
    on error
        set SlugTxt to make text box at beginning with properties {bounds:{"-1p4", "0p", "0p", "51p"}, name:"SlugText", color:"White"}
    end try
  end tell
-- tell story 1 of SlugTxt blah blah
end repeat

Hope this is what you're after


Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #4 on: April 06, 2009, 10:45:30 AM »
I had a quick play and from what you posted I think your going to have to change a thing or 2. I had errors trying to set the contents of the text box. Then when I checked my doc your text box does NOT appear to enter the page bounds. Which I think it must do else the "Tell page" will fail as soon as I moved it in slightly no problems. This is what I had.

001   tell application "QuarkXPress"
002        activate
003        if not (exists document 1) then error "No document is open."
004        tell document 1
005             delete (every text box whose name is "Slug Text")
006             if exists layer "Non-Printing" then
007                  repeat with i from 1 to (count of pages)
008                       tell page i
009                            show
010                            set Slug_Text to make text box at beginning with properties ¬
011                                 {bounds:{"-9 mm", "0 mm", "1 mm", "210 mm"}, name:"Slug Text", color:"White"}
012                            tell text box 1
013                                 tell story 1
014                                      set contents of it to "Some text to be added…"
015                                      tell paragraph 1
016                                           set font to "Times New Roman"
017                                           set size to "9pt"
018                                           -- set style to bold
019                                           set color to "Cyan"
020                                           set tab list to {{justification:left justified, position:"30 mm"}}
021                                      end tell
022                                 end tell
023                            end tell
024                            
025                       end tell
026                  end repeat
027             else
028                  -- No Layer? What do you want to do?
029             end if
030        end tell
031   end tell

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #5 on: April 07, 2009, 12:01:15 AM »
ok. WOW. thank u so much. i just wouldnt have learned this without your help.  you both suggested the repeat and was def. the way to go.

larsen i put your code in and it seemed to work fine in a blank document. but it kept getting confused about where to put the "contents" and kept saying it couldnt.

then i put it into my pre-existing multi-layered document and that was scary cos it kept making the text box, and then randomly throwing the contents into ANY pre-existing text box -- deleting text on the way.

i'm not sure if this is a real solution or not, but i was trying to think about how to separate my text box from the crowd and things like "select (text box whose name is "slug text") wasnt washing.

in the end, i used "make at the end" and set contents to "last box" . i'm going to try it out on a few documents at work and see if it breaks anything in the document.   also i think you made a very valid point about the text box being "on the page"

cdms,  one of the big problems i had with my original code -- in my head at least, is i used the "Set Slug_Text to make text box..."  thinking that then i could address the text box Slug_Text, as you mention at the bottom of your text "set story 1 of Slug_Text" but it never really seemed to work for me.  i'm sure its how i was talking to it. sigh.

i pasted what i ended up with today... at 1am. :-) satisfied that for now it seems to work.

oh and larsen the delete (every text box whose name..) works perfect.

can i just thanks again. i really dont know anyone who can help me with this and its just so great that youre taking the time to help me.

m./

tell application "QuarkXPress"
   activate
   if not (exists document 1) then error "No document is open."
   tell document 1
      delete (every text box whose name is "Slug Text")
      if exists layer "Non-Printing" then
         repeat with i from 1 to (count of pages)
            tell page i
               show
               make text box at end with properties {bounds:{"-1p4", "0 mm", "0p3", "51p"}, name:"Slug Text", color:"White"}
               tell story 1 of last text box
                  set contents of it to (compname & " — " & jobdesc & tab & "Proof " & " " & proofno1 & " — " & nowdate)
                  
                  tell paragraph 1
                     set font to "Times New Roman"
                     set size to "9pt"
                     set style to bold
                     set color to "slug line-does not print"
                     set tab list to {{justification:right justified, position:{"50p9"}}}
                  end tell
               end tell
               
            end tell
            
            
         end repeat

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #6 on: April 07, 2009, 03:28:44 AM »
If you make a new text box at the beginning then you can address it as "text box 1" or "first text box" if you make at the end then you can use "last text box" By far the best way to go about scripting boxes is to "name" them as you go then they can always be targeted in the future no matter wether you add, remove or reorder the item stack. Im not sure if "set style to bold" is going to work I did not look at that but I think its on styles {list} off styles {list} You should be able to address the text of your variable "Slug_Text" it was probably failing due to not being in the page bounds at this point.

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Re: Q8 AppScp: text box syntax - newbie needs help!
« Reply #7 on: April 08, 2009, 06:35:23 AM »
hi larsen
thanks. i agree, i would be much more comfortable calling my text box by name, particularly when the action is to overwrite content. i will try again to work that in.  it didnt seem to take before, but now that -- with your collective help -- i've managed to tighten up the other elements of the script, it might.

the set style to bold seems to work. that on style / off style confused me (like so many things here :-) ) so i tried the "plain language" option. 

today's dilema(s) involve learning all about if statements and buttons (in other words error buttons). my bosses are making fun of me saying the scripts wont work, so i have to error (bullet) proof em. yay.

and one more thing i might have to come back for help with..(but am researching this morning).... on pdf creation (helped out with in previous post) i probably should have read the introduction to posting protocols... i'm sure i'm not sposed to turn this into a long running chain about my code issues.   
i need to overwrite the existing file. so was trying to ask if it exists then delete it.

as always. thanks for the help.  i'm researching so hopeful i'll get there on my own.

m./