Author Topic: Bounds of multiple Boxes  (Read 394 times)

0 Members and 1 Guest are viewing this topic.

Offline Star123

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Bounds of multiple Boxes
« on: April 08, 2019, 03:48:00 PM »
Hi Guys,

I am using MacIntosh X (Yosemite), Quark Xpress 9.5 and Script Editor 2.5.

I created the below script to make a picture box, then to paste it in the cursor position, then to insert some text from the clipboard and to move the cursor to the end of the story.

But What I Need is 
Prompt the user to select box 1. From that bounds create a new text box 1.

Prompt the user to select box 2. From that bounds create a new text box 2.

Repeat until the user Cancelled.

Thanks in Advance.
Star

Code: [Select]
tell application "QuarkXPress"
activate
tell document 1

set thedata to every text of (the clipboard)
set thedata to thedata as text
set ccount to count paragraphs of thedata

try
set theSelection to selection
set thebox to (make picture box at beginning with properties {bounds:{5, 10, 10, 20}})
delay 0.5
set tool mode to drag mode
tell current page
set selected of thebox to true
set selected of text box 1 to false
cut thebox
end tell

select text box 1
set tool mode to 1
delay 1
paste

set box type of picture box 1 to text box type
select text box 2

set inserttext to paragraph 1 of thedata
set the clipboard to inserttext as text
delay 0.2

paste

set paracount to count of paragraphs of text box 1
set ccount to count characters of paragraph paracount of text box 1
--set ccount to ccount - 1
set selection to insertion point after character ccount of paragraph paracount of text box 1
tell application "System Events" to keystroke tab
delay 0.1


end try
end tell
end tell



Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 441
  • Karma: 6
  • Gender: Male
Re: Bounds of multiple Boxes
« Reply #1 on: April 09, 2019, 05:27:00 AM »
Hi there! Nice to hear some people's still living :-)

Would you have a Quark file to send me as an example to work on?
An important thing to keep in mind is that box numbers are attributed on a regular basis that is the 1st box created is #1, the 2nd #2, etc. Unless you create a box "at beginning", then every boxes will shift (+1). And if you create a box "at end", then it'll be #[last+1].

When you say "Prompt the user to select box 1. From that bounds create a new text box 1.", I suppose you mean that the user is prompted to select one box (because the user just don't know what number is such box). Are you with me? So I don't really understand what the scrit is supposed to do actually. Is the user supposed to select a picture box then the scripts modifies that box to a texte box and pastes the first paragraph of text in it? Then the user selects another picture box and the script goes on?
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.10.5 • QuarkXPress 9.5.4.1 + 2017 • Adobe CS5+6 =

Offline Star123

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Bounds of multiple Boxes
« Reply #2 on: April 09, 2019, 04:26:29 PM »
Hi Jean-Marie Schwartz,

I Feel Happy to see you again. Most of the time, You saved me a day. So Thanks for all you Done.
Quote
I suppose you mean that the user is prompted to select one box (because the user just don't know what number is such box). Are you with me?

Yes....
And one more thing is box height and width may vary from project to project.

I have send you a sample file for your Reference.

Thanks

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 441
  • Karma: 6
  • Gender: Male
Re: Bounds of multiple Boxes
« Reply #3 on: April 10, 2019, 07:52:02 AM »
Sorry, I have got nothing. Maybe trashed with Spams? Can you try one more time please?
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.10.5 • QuarkXPress 9.5.4.1 + 2017 • Adobe CS5+6 =

Offline Star123

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Bounds of multiple Boxes
« Reply #4 on: April 10, 2019, 12:10:57 PM »
I have resend it

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 441
  • Karma: 6
  • Gender: Male
Re: Bounds of multiple Boxes
« Reply #5 on: April 11, 2019, 03:26:29 AM »
Great! Found it in the Spams… Saved it ;-) I'll be back as soon as I can.
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.10.5 • QuarkXPress 9.5.4.1 + 2017 • Adobe CS5+6 =

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 441
  • Karma: 6
  • Gender: Male
Re: Bounds of multiple Boxes
« Reply #6 on: April 11, 2019, 11:12:04 AM »
Hi John,

Trying to understand better what you want.

So on one side, you have a text file with some paragraphs. Is the number of paragraphs directly related to the number of columns in the Quark file? (I can see 24 paras for 6 columns…)
Are those paragraphs strictly set? I mean do they have the same length all the time for a given column? Or is the length variable from one paragraph to another?

On the other side, in the Quark file, from file to file there would be 2 to 6 columns, right? So the file the user is running the script on might show up 2, 3, 4, 5 or 6 columns, is that right? And the columns always have variable dimensions from file to file and from column to column, right? Are the boxes always positioned at the same Y coordinates (vertical measures) from file to file?

Are all the text boxes embedded (inline)? And do they need to remain inline? Is the box height correctly set to welcome the data? Or does the script need to adaptate the height according to the paragraph length?



Anyway, here is a first try on Testing2.qxp that I sent you by email. (line 1 and 2 kept alone, line 2 contains the inline text boxes). The following script is taking the number of paragraphs of Data File (the text that is in the Clipboard) into account and duplicating line 2 as many times as needed (so if there are 30 paras and 6 columns, it'll add 4 more lines after line 2 so there'll be 5 lines of 6 columns). Then the script will populate all the inline text boxes with the text as asked.

Please let me know if anything is going wrong. And note that I'll be off till Monday.


Code: [Select]
(* 

SELECT THE PARAGRAPHS HERE BELOW PRIOR TO RUN THIS SCRIPT !!!

Paragraph 1 from Data File
Paragraph 2 from Data File
Paragraph 3 from Data File
Paragraph 4 from Data File
Paragraph 5 from Data File
Paragraph 6 from Data File
Paragraph 7 from Data File
Paragraph 8 from Data File
Paragraph 9 from Data File
Paragraph 10 from Data File
Paragraph 11 from Data File
Paragraph 12 from Data File
Paragraph 13 from Data File
Paragraph 14 from Data File
Paragraph 15 from Data File
Paragraph 16 from Data File
Paragraph 17 from Data File
Paragraph 18 from Data File
Paragraph 19 from Data File
Paragraph 20 from Data File
Paragraph 21 from Data File
Paragraph 22 from Data File
Paragraph 23 from Data File
Paragraph 24 from Data File
Paragraph 25 from Data File
Paragraph 26 from Data File
Paragraph 27 from Data File
Paragraph 28 from Data File
Paragraph 29 from Data File
Paragraph 30 from Data File



*)

set the_data to every text of (the clipboard)
set the_text to every paragraph of the_data
--set the_count to length of the_text
repeat while ((item -1 of the_text) is "")
set the_text to (reverse of (rest of (reverse of the_text)))
end repeat
set NOP to length of the_text -- number of paragraphs in Data File

tell application "QuarkXPress9"
tell document 1
set my_list to {}
set props to properties of every text box
repeat with a_box in props
if anchored of a_box is true then
set end of my_list to a_box
end if
end repeat
set NOC to length of my_list -- number of "cells" in line 2
try
if NOP > NOC then
set repeat_line_2 to NOP div NOC
repeat (repeat_line_2 - 1) times
tell story 1 of current box
copy line 2 to after line -1
end tell
end repeat
end if
end try
set my_list to {}
set props to properties of every text box
repeat with a_box in props
if anchored of a_box is true then
set end of my_list to a_box
end if
end repeat
set my_list to reverse of my_list
repeat with j from 1 to length of my_list
try
set story 1 of object reference of item j of my_list to item 1 of the_text
set the_text to rest of the_text
end try
end repeat
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.10.5 • QuarkXPress 9.5.4.1 + 2017 • Adobe CS5+6 =

Offline Star123

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Bounds of multiple Boxes
« Reply #7 on: April 11, 2019, 04:36:54 PM »
Hi Jean-Marie Schwartz,

Thank You Soooooooooo Much..............

Your Script is Awesome. It works more than my expectation.

Every time I came to this Forum. You saved me a day. But this time, You saved me a month. Because this task will be a great challenge to me while TyeSetting.

One Again Thank You So Much,
John
« Last Edit: April 11, 2019, 05:04:22 PM by Star123 »

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 441
  • Karma: 6
  • Gender: Male
Re: Bounds of multiple Boxes
« Reply #8 on: April 15, 2019, 02:33:36 AM »
Lucky you  ;D Thanks be to Michel who taught me a lot!  ;) Glad the script meets your expectations and more! Enjoy!
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.10.5 • QuarkXPress 9.5.4.1 + 2017 • Adobe CS5+6 =