This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > December 2006 > Setting Vector Text?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Setting Vector Text?
Stuart

2006-12-06, 8:09 pm

Would someone please post an example of setting vector text within a
script? I'm wanting to automate printing of envelopes for Christmas
cards. I've got my addresses stored in an Excel spreadsheet, and I've
saved it as a csv file, and I'm using Python's csv.reader API to read
the file. I'd like to loop through all my addresses and set a
(pre-existing) vector object's text to the current address each time
through the loop.

I've got some code that (I think) originated with either Joe Fromm or
Gary Barton for retrieving text from a vector. It contains a large
comment discussing how strangely text objects are encoded, which leads
me to believe that setting the text is not a straightforward task.

Any suggestions?
Willy

2006-12-06, 8:09 pm

I don't think I really understand. Are you wanting to use PSP to print the
addresses on the envelopes rather than perhaps using another software to do
it?
W

"Stuart" <stuart@nospam.com> wrote in message news:45699c1d$1_1@cnews...
> Would someone please post an example of setting vector text within a
> script? I'm wanting to automate printing of envelopes for Christmas
> cards. I've got my addresses stored in an Excel spreadsheet, and I've
> saved it as a csv file, and I'm using Python's csv.reader API to read the
> file. I'd like to loop through all my addresses and set a (pre-existing)
> vector object's text to the current address each time through the loop.
>
> I've got some code that (I think) originated with either Joe Fromm or Gary
> Barton for retrieving text from a vector. It contains a large comment
> discussing how strangely text objects are encoded, which leads me to
> believe that setting the text is not a straightforward task.
>
> Any suggestions?



Stuart

2006-12-06, 8:09 pm

In a nutshell, my question is this: How can I, in a PSP script, set the
text of a vector object?

I have a function named GetVectorTextObject (shown below) that I found
somewhere on the internet at some point in time in the past. What I
need is a "SetVectorTextObject" function. Can anyone point me to such a
function?

(Since posting this question, I've decided that automating the printing
of the Christmas cards is probably better implemented in VBA within the
spreadsheet itself. So, please ignore the "Christmas card" discussion
as it's irrelevant. But, I'd still like to know how to set vector text
within a script. Thanks.)


def GetVectorObjectText(TextObj):
''' return data about a text object. Returns a list of the
strings on each line.

Text objects are encoded strangely. The text is a list of
text segment objects. The segments are cumulative - anything
not set in one segment carries over from the previous one. The
typical output from PSP is the formatting for a text block,
followed
by the formatting of a text line, followed by the characters of
the line.

Formatting changes during the line, or text insert/delete
operations
after it was created will result in the creation of text
segments within
the same line. These will frequently have a Start position of
(0,0) defined.
Start positions of (0,0) can be ignored and treated as a
continuation of
the current text block.

New lines are represented by a new start position. In the case of
a blank line you will see to Start positions without any character
segments, so it is necessary to count lines by looking at the
instance of
Start positions.
'''
Lines = []
CurrentLine = None

LastStart = (-1,-1) # put it off the canvas
for Seg in TextObj['Segments']:
if Seg['Start'] is not None and \
Seg['Start'] != (0.0, 0.0) and \
Seg['Start'] != LastStart:
if CurrentLine is not None:
Lines.append( CurrentLine )
CurrentLine = ''
LastStart = Seg['Start']

if Seg['Characters'] is not None:
CurrentLine += Seg['Characters']

Lines.append( CurrentLine )
return Lines


Willy wrote:
> I don't think I really understand. Are you wanting to use PSP to print the
> addresses on the envelopes rather than perhaps using another software to do
> it?
> W
>

Willy

2006-12-06, 8:09 pm

I am still confused by what you mean " set the text of a vector object".
You can use the text tool do make text. If you are trying to attain the text
from your database and can get it into a variable, then you can use that
varible in the text tool dialog (where it has the text you recorded).
'Characters': is the entry I believe. You can adjust where the text is place
also in the dialog.
W


"Stuart" <stuart@nospam.com> wrote in message news:456a93bf$1_3@cnews...[color=darkred]
> In a nutshell, my question is this: How can I, in a PSP script, set the
> text of a vector object?
>
> I have a function named GetVectorTextObject (shown below) that I found
> somewhere on the internet at some point in time in the past. What I need
> is a "SetVectorTextObject" function. Can anyone point me to such a
> function?
>
> (Since posting this question, I've decided that automating the printing of
> the Christmas cards is probably better implemented in VBA within the
> spreadsheet itself. So, please ignore the "Christmas card" discussion as
> it's irrelevant. But, I'd still like to know how to set vector text
> within a script. Thanks.)
>
>
> def GetVectorObjectText(TextObj):
> ''' return data about a text object. Returns a list of the
> strings on each line.
>
> Text objects are encoded strangely. The text is a list of
> text segment objects. The segments are cumulative - anything
> not set in one segment carries over from the previous one. The
> typical output from PSP is the formatting for a text block,
> followed
> by the formatting of a text line, followed by the characters of
> the line.
>
> Formatting changes during the line, or text insert/delete
> operations
> after it was created will result in the creation of text segments
> within
> the same line. These will frequently have a Start position of
> (0,0) defined.
> Start positions of (0,0) can be ignored and treated as a
> continuation of
> the current text block.
>
> New lines are represented by a new start position. In the case of
> a blank line you will see to Start positions without any character
> segments, so it is necessary to count lines by looking at the
> instance of
> Start positions.
> '''
> Lines = []
> CurrentLine = None
>
> LastStart = (-1,-1) # put it off the canvas
> for Seg in TextObj['Segments']:
> if Seg['Start'] is not None and \
> Seg['Start'] != (0.0, 0.0) and \
> Seg['Start'] != LastStart:
> if CurrentLine is not None:
> Lines.append( CurrentLine )
> CurrentLine = ''
> LastStart = Seg['Start']
>
> if Seg['Characters'] is not None:
> CurrentLine += Seg['Characters']
>
> Lines.append( CurrentLine )
> return Lines
>
>
> Willy wrote:


RonV

2006-12-06, 8:09 pm

On Mon, 27 Nov 2006 01:33:58 -0600, Stuart <stuart@nospam.com> wrote:

>In a nutshell, my question is this: How can I, in a PSP script, set the
>text of a vector object?
>
>I have a function named GetVectorTextObject (shown below) that I found
>somewhere on the internet at some point in time in the past. What I
>need is a "SetVectorTextObject" function. Can anyone point me to such a
>function?
>
>(Since posting this question, I've decided that automating the printing
>of the Christmas cards is probably better implemented in VBA within the
>spreadsheet itself. So, please ignore the "Christmas card" discussion
>as it's irrelevant. But, I'd still like to know how to set vector text
>within a script. Thanks.)


Here's a function I wrote for the Contact Sheet Creator. You must
call the function with all of the values set. Beware word wrap in the
news readers.

Environment is set for all PSP scripts.
Font is the name of an active font in your computer str
TextSize differs between versions. Try a pixel size first. str
HPos, VPos are pixel locations used to place the text, str
Jus is an int denoting justification of the text.
AA is an int denoting Anti Alias
TextStr is a str that is to be printed.

def PlaceText( Environment, Font, TextSize, HPos, VPos, Jus, AA,
TextStr):
''' print the specified text
'''
#TextSize, Pos, Jus = int
#Font, Text = string
#Jus 0,1,2 = l,r,c

App.Do( Environment, 'Text', {
'CreateAs': App.Constants.CreateAs.Vector,
'Segments': [{
'Fill': {
'Color': (0,0,0),
'Pattern': None,
'Gradient': None,
'Texture': None
},
'Font': Font,
'Antialias': AA,
'PointSize': TextSize,
'Start': (HPos, VPos),
'Stroke': None,
'LineStyle': None,
'LineWidth':0,
'SetText': Jus,
},{
'Characters': TextStr
}],
'FinalApply': App.Constants.Boolean.true,
'GeneralSettings': {
'ExecutionMode':
App.Constants.ExecutionMode.Silent,
'AutoActionMode':
App.Constants.AutoActionMode.Match
}
},)


Believe it or not, using a function to do the printing saved a
considerable amount of code in the program.

Ron

Stuart

2006-12-06, 8:09 pm

What I'm asking is how to modify the text in an already existing vector
text object.

Is that possible using the text tool as you've both described?

Maybe I'm making this too hard. Maybe, if I want to edit an
already-existing vector text object, I should just delete the
already-existing one and create a new one...
Willy

2006-12-06, 8:09 pm

If you have placed vector text on an open image and you want to edit the
text you can right click on the vector sublayer that has your text then
select edit text.
W



"Stuart" <stuart@nospam.com> wrote in message news:456af554$1_1@cnews...
> What I'm asking is how to modify the text in an already existing vector
> text object.
>
> Is that possible using the text tool as you've both described?
>
> Maybe I'm making this too hard. Maybe, if I want to edit an
> already-existing vector text object, I should just delete the
> already-existing one and create a new one...



RonV

2006-12-06, 8:09 pm

On Mon, 27 Nov 2006 08:30:18 -0600, Stuart <stuart@nospam.com> wrote:

>What I'm asking is how to modify the text in an already existing vector
>text object.
>
>Is that possible using the text tool as you've both described?
>
>Maybe I'm making this too hard. Maybe, if I want to edit an
>already-existing vector text object, I should just delete the
>already-existing one and create a new one...


Record a script replacing the vector text with what you want.

Save it and edit it to do what you want. Note that the vector text
you replace must be in the exact same location each time you run the
script.


I just did it.

Ron


Stuart

2006-12-06, 8:09 pm

Makes sense. Thanks to both of you for your responses.
Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews