Extensions and Plugins > Xdata by Em Software

Stack or Double

(1/1)

afig:
A simple script to double or stack text elements.

For this example, We have a document which is formatted with a static number of lines. We will use 10 lines for our example. There can be Company Name, Agent Name, 2 Agent Titles, an Email and a Web Address. In addition, there is a phone block containing up to 10 phones.

The straight forward way to handle this is to use a line counter and subtract avaiable lines as you identify populated fields.

For example, I have:

Company Name
Agent Name
Agent Title
Email Address
Web Address

This leaves me 5 lines to work with and if I happen to have 10 phones, they all double.

The logic ends up looking like this:

If linecounter = 10
   If phonecount = 10
      put phone1 & ", " & phone2 into phoneline1
      put phone3 & ", " & phone4 into phoneline2
      .
      .
      .
   else if phonecount = 9
   .
   .
   .
else if linecounter ≤ 0
   ERROR
endif

Something like that. This is a basic example, but we could be dealing with more elements and more lines and each additional element or line adds to the clutter.

My solution was to build a repeat loop which decides whether to stack or double the phone elements. The example I will show here actually does quite a bit more because the format is more complicated then just stack or double.

The short version looks something like this:

worddelimiters set to "|"
itemcount = number of phone items
linecounter = number of available lines
pstring = pipedelimited phone variable (phone1|phone2|etc.)

«--
«if pstring≠""
«put (the number of words in pstring) into itemcount
«repeat while pstring≠""
«if itemcount > (linecounter*2)
«put "ERROR: TOO MUCH INFO<\#13>" into lines
«exit repeat
«else if itemcount ≤ linecounter
«repeat (itemcount)
«put lines & word 1 of pstring & "<\#13>" into lines
«put linecounter - 1 into linecounter
«put word 2 to the number of words in pstring of pstring into pstring
«end repeat
«exit repeat
«else if itemcount > linecounter
«put lines & word 1 of pstring & ", " & word 2 of pstring & "<\#13>" into lines
«put linecounter - 1 into linecounter
«put word 3 to the number of words in pstring of pstring into pstring
«put itemcount - 2 into itemcount
«else if itemcount = 0
«exit repeat
«endif
«end repeat
«endif
«--

For the more adventurous souls, I have a real world example.

In this example, we have three text blocks which have to do the following within a static space (say 100 points of vertical space);

Top align

Center between

Bottom align

To add to the complexity, all elements can have custom text properties (font size, leading, font face, etc.). We are not only tracking the number of lines used, but also the ammount of vertical space (in points) so that we might vertically center the name & title and then the ammount of horizontal space used for each line so that we might scale as needed. We flag an error when the space is used up.

So to set the stage, our variable data collected so far would be something like;

linecounter = 5

itemcount = 6

pstring = <f”B Helvetica Bold”z6.5*p(,,,8)>Office: (000) 000-0000<f”B Helvetica Bold”z6.5*p(,,,8)>|8|<f”Helvetica”z6.5*p(,,,8)>Fax: (000) 000-0000<f”Helvetica”z6.5*p(,,,8)>|8|<f”Helvetica”z6.5*p(,,,8)>Cell: (123) 456-7890<f”Helvetica”z6.5*p(,,,8)>|8|<f”Helvetica”z6.5*p(,,,8)>Toll Free: (888) 222-1111<f”Helvetica”z6.5*p(,,,8)>|8|<f”Helvetica”z6.5*p(,,,8)>Email: firstname.lastname<\@>website.com<f”Helvetica”z6.5*p(,,,8)>|8|<f”Helvetica”z6.5*p(,,,8)>Website: www.website.com/firstname.lastname<f”Helvetica”z6.5*p(,,,8)>|8|

pod = 70500|63750|64000|79750|107625|134500|

I know, that last two parts look bad but that's what your tagged phone variable and your metric value per phone item looks like. The data is pipe delimited (worddelimiter) with words alternating between your pre-stylized phone and your leading (for our purposes, your horizontal space).

Instead of building individual lines, we will just build our paragraph or page breaks right into the phone block variable.

The logic looks something like this:

«--
«put (the number of words in pstring)/2 into itemcount
«repeat while pstring≠""
«if itemcount > (linecounter*2)
«put "ERROR: TOO MUCH INFO<\#13>" into lines
«exit repeat
«else if itemcount ≤ linecounter
«repeat (itemcount)
«if word 3 of pstring≠""
«put lines & word 1 of pstring & "<*p(,,," & word 2 of pstring & ")\#13>" into lines
«else
«put lines & word 1 of pstring & "<*p(,,," & word 2 of pstring & ")\#11>" into lines
«endif
«put tank & word 1 of pod & "|" into tank
«put linecounter - 1 into linecounter
«put word 3 to the number of words in pstring of pstring into pstring
«put word 2 to the number of words in pod of pod into pod
«end repeat
«exit repeat
«else if itemcount > linecounter
«if word 2 of pstring ≥ word 4 of pstring
«if word 5 of pstring≠""
«put lines & word 1 of pstring & ", " & word 3 of pstring & "<*p(,,," & word 2 of pstring & ")\#13>" into lines
«else
«put lines & word 1 of pstring & ", " & word 3 of pstring & "<*p(,,," & word 2 of pstring & ")\#11>" into lines
«endif
«put tank & (word 1 of pod + word 2 of pod + 4125) & "|" into tank
«put linecounter - 1 into linecounter
«else
«if word 5 of pstring≠""
«put lines & word 1 of pstring & ", " & word 3 of pstring & "<*p(,,," & word 4 of pstring & ")\#13>" into lines
«else
«put lines & word 1 of pstring & ", " & word 3 of pstring & "<*p(,,," & word 4 of pstring & ")\#11>" into lines
«endif
«put word 1 of pstring & ", " & word 3 of pstring into holder
«put tank & (word 1 of pod + word 2 of pod + 4125) & "|" into tank
«put linecounter - 1 into linecounter
«endif
«put word 5 to the number of words in pstring of pstring into pstring
«put word 3 to the number of words in pod of pod into pod
«put itemcount - 2 into itemcount
«else if itemcount = 0
«exit repeat
«endif
«end repeat
«--

Here we actually want to jump out of the text box we are in after our last element. We also want to collect our metric values as we combine phone elements. Lastly, we want to apply the greater of two leading values to our paragraph style so that we don't get ascenders running into descenders.

On output, we have two overlapping text boxes. The top one is top aligned and the bottom one is bottom aligned. We calculate the remaining vertical space and divide it in half to create a false paragraph which should center the middle block when it is applied. It kind of looks like this on output.

Company Name

<fake spacer>

Name
title
<jump to second box>

address block
phone block
<jump out of box>

This was obviously fun to troubleshoot and debug while under a deadline.

I hope you enjoyed the read.

Andrew

edit: 6/26 - cleaned up some stuff.

Emma:
More great ideas! My head is hurting, but I know that when I need to do something like this I'll come back to this post and find what I need! Thanks.

Navigation

[0] Message Index

Go to full version