This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > July 2007 > Reading text files in a PSP script





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 Reading text files in a PSP script
Shipyard

2007-07-27, 6:23 pm

(I've already posted this on the PSPUG, but there doesn't seem to be
very much activity over there.)

I have adapted a built-in script (EXIFCaptioning) to add Exif
information to an image the way I want it. That works fine.

Now I want to add some other information which is stored in a text file.
The Python code for reading the file works OK on its own outside of PSP,
just using a Python interpreter, but when I include it in the script the
script does not work at all, and there are no error messages. Single-
stepping tells me nothing useful either, except that nothing following
the added code gets executed.

Can someone here identify the problem? I'd be most grateful.

I'm running PSP-XI on XP SP2.

Here's the added code. As I said, this piece of code works fine when run
by an external Python 2.5 interpreter. The text file contains a single
line.

fn='c:/photos/2007-07-26/2007-07-26.1683.0.jpg.exif.txt'
f=open(fn,'r')
flines=f.readlines()
f.close()
for eachline in flines:
tline=eachline

The code is embedded after the section which begins with "# first
extract the EXIF data - if we can't find any just return without
changing the image".

(I should add that I've tried running it from both Restricted and
Trusted folders. Same problem.)



SuzShook

2007-07-27, 6:23 pm

I'm not sure what you're trying to do here, but I've tried your code in a
trusted script and it works just fine. I also added a print line after your
code, and that works fine, too. What you left out is what you are doing
with the data you are reading in from the external text line - if you have
not added anything but those 6 lines, then the script will probably end
without "doing anything". What code follows your added lines? Where
exactly did you place your code? You really haven't told us enough so we can
help you. But I can tell you the code works perfectly when inserted into
that script - it opens the text file and reads the lines - but you have to
do something with those lines....! Add a print statement to your lines, and
you will see that it works - even add another print statement after those
lines, and that works, too:

fn='c:/photos/2007-07-26/2007-07-26.1683.0.jpg.exif.txt'
f=open(fn,'r')
flines=f.readlines()
f.close()
for eachline in flines:
tline=eachline
print tline
print " now after the added code"

Shipyard wrote:
> (I've already posted this on the PSPUG, but there doesn't seem to be
> very much activity over there.)
>
> I have adapted a built-in script (EXIFCaptioning) to add Exif
> information to an image the way I want it. That works fine.
>
> Now I want to add some other information which is stored in a text
> file. The Python code for reading the file works OK on its own
> outside of PSP, just using a Python interpreter, but when I include
> it in the script the script does not work at all, and there are no
> error messages. Single- stepping tells me nothing useful either,
> except that nothing following the added code gets executed.
>
> Can someone here identify the problem? I'd be most grateful.
>
> I'm running PSP-XI on XP SP2.
>
> Here's the added code. As I said, this piece of code works fine when
> run by an external Python 2.5 interpreter. The text file contains a
> single line.
>
> fn='c:/photos/2007-07-26/2007-07-26.1683.0.jpg.exif.txt'
> f=open(fn,'r')
> flines=f.readlines()
> f.close()
> for eachline in flines:
> tline=eachline
>
> The code is embedded after the section which begins with "# first
> extract the EXIF data - if we can't find any just return without
> changing the image".
>
> (I should add that I've tried running it from both Restricted and
> Trusted folders. Same problem.)



Spandex Rutabaga

2007-07-27, 6:23 pm

Shipyard wrote:
>
> (I've already posted this on the PSPUG, but there doesn't seem to be
> very much activity over there.)
>
> I have adapted a built-in script (EXIFCaptioning) to add Exif
> information to an image the way I want it. That works fine.


Not everyone has this script so you are leaving at least some
people in the dark about specifics.

> Now I want to add some other information which is stored in a text file.
> The Python code for reading the file works OK on its own outside of PSP,
> just using a Python interpreter, but when I include it in the script the
> script does not work at all, and there are no error messages. Single-
> stepping tells me nothing useful either, except that nothing following
> the added code gets executed.
>
> Can someone here identify the problem? I'd be most grateful.


You could probably help yourself the most by attaching the problem
script to a post so people can see what is happening in it. By
keeping it secret you are forcing people to speculate instead of
analyzing the script.

> Here's the added code. As I said, this piece of code works fine when run
> by an external Python 2.5 interpreter. The text file contains a single
> line.
>
> fn='c:/photos/2007-07-26/2007-07-26.1683.0.jpg.exif.txt'
> f=open(fn,'r')
> flines=f.readlines()
> f.close()
> for eachline in flines:
> tline=eachline
>
> The code is embedded after the section which begins with "# first
> extract the EXIF data - if we can't find any just return without
> changing the image".


There is probably something wrong with how you are using the results
of the above inserted code. You haven't said anything about how you
are using this information. Many programming problems involve some
small silly mistake or forgetting about the occurrence some
particular circumstance. Unfortunately, it's impossible to tell if
that's the case here since you are keeping the specifics of what
you are doing to yourself.
Shipyard

2007-07-27, 6:23 pm

In article <46a8b8af_1@cnews>, suzshook@roadrunner.com says...
> I've tried your code in a
> trusted script and it works just fine


Thanks for looking, Suz.

I should have posted the whole script, which I will now do.

As shown below, the script will work on any image containing Exif
information. If I uncomment lines 35 to 44, it won't work at all (I mean
no text gets displayed). That's the fundamental problem. Note that I
don't need to uncomment line 180 to make it not work.

from PSPApp import *
import string
import PSPUtils

# 2007.07.26 Adapted from the EXIFCaptioning script in PSP-XI

def ScriptProperties():
return {
'Author': u'Corel Corporation',
'Copyright': u'Copyright (c) 2002-2006 Corel Corporation. All
rights reserved.',
'Description': "Put EXIF camera and exposure information at the
bottom of the image.",
'Host': u'Paint Shop Pro 9',
'Host Version': u'9.00',
}

def Do(Environment):

if PSPUtils.RequireADoc( Environment ) ==
App.Constants.Boolean.false:
return

# first extract the EXIF data - if we can't find any just return
without changing the image
ImageInfo = App.Do( Environment, 'ReturnImageInfo',
{'GeneralSettings': {'Version': ((9,0,0),1) }} )
if ImageInfo['ExifMake'] == '' or ImageInfo['ExifModel'] == '' or \
ImageInfo['ExifFNumber' ] == '' or ImageInfo['ExifExposureTime']
== '':
App.Do(Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Stop,
'Text': PSPUtils.NoEXIFData,
'GeneralSettings': {'Version': ((9,0,0),1) }
})
return

fid = App.ActiveDocument.Title

'''
# fn=fid + '.exif.txt'
fn='c:/photos/2007-07-26/2007-07-26.1683.0.jpg.exif.txt'
f=open(fn,'r')
flines=f.readlines()
f.close()
for eachline in flines:
tline=eachline
# tline=eachline.strip()
'''

# ISO value is not always present
if ImageInfo['ExifISOSpeed'] == '': isost = ''
else: isost = ' iso' + ImageInfo['ExifISOSpeed'].strip()

if ImageInfo['ExifOriginalSubSecond'] == '00': osst = ''
else: osst = '.' + ImageInfo['ExifOriginalSubSecond'].rstrip
('0').strip()

# save any existing selection
SelSaver = PSPUtils.SaveSelection( Environment, App.TargetDocument )

# assemble the camera string by concatenating the camera make and
model. Some camera
# manufacturers have the barbaric practice of CAPITALIZING
everything in their make and model
# strings, so convert it to initial caps only for a more civilized
appearance
# CaptionTextCamera = unicode(string.capwords( ImageInfo['ExifMake']
+ ' ' + ImageInfo[ 'ExifModel' ] ))
# CaptionTextCamera = unicode(string.capwords( ImageInfo
['ExifModel'] + ' ' + ImageInfo[ 'ExifOriginalDate' ] ))
# CaptionTextCamera = unicode(string.capwords( ImageInfo
['ExifModel']

CaptionTextCamera = unicode \
(
ImageInfo['ExifOriginalDate'].replace(':','.',2).strip()
+ osst
+ isost
+ ' ' + 'f' + ImageInfo['ExifFNumber'].rstrip('0').rstrip('.').strip
()
+ ' ' + ImageInfo['ExifExposureTime'].rstrip(' second').strip()
+ ' ' + ImageInfo['ExifFocalLength'].rstrip('0 mm').rstrip
('.').strip() + 'mm'
+ ' ' + fid.lower().strip()
+ ' ' + string.capwords(ImageInfo['ExifModel'])
)

# now assemble exposure information by using the aperture and
exposure
# Aperture = float(ImageInfo['ExifFNumber'])
# CaptionTextExposure = PSPUtils.ExposureMsg % (Aperture, ImageInfo
['ExifExposureTime'].strip())

# first we create a raster layer at 50% opacity as a backdrop for
the caption
# for now the raster layer is empty - we'll fill it in later
# the new layer becomes the active layer
App.Do( Environment, 'NewRasterLayer', {
'General': {
# 'Opacity': 50,
'Opacity': 0,
'Name': PSPUtils.CaptionBackground,
'IsVisible': App.Constants.Boolean.true,
},
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'Version': ((9,0,0),1)
}
})

# create a layer group. This will place the raster layer in the
group
# the group is the active layer on completion
App.Do( Environment, 'NewLayerGroup', {
'General': {
'Opacity': 100,
'Name': PSPUtils.EXIFCaption,
},
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'Version': ((9,0,0),1)
}
})

# select the raster layer so that the vector layer gets created
above it
App.Do( Environment, 'SelectLayer', {
'Path': (0,0,[1],App.Constants.Boolean.false),
'GeneralSettings': {'Version': ((9,0,0),1) }
})

# now create a vector layer to put text on - creating the layer will
make it active
App.Do( Environment, 'NewVectorLayer', {
'General': {
'Opacity': 100,
'Name': PSPUtils.EXIFText,
},
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'Version': ((9,0,0),1)
}
})

# Figure out how big the text should be by examining the overall
image size. We'll do a rough
# scale based on 1000 pixels. We won't paint text less than 16
point in any event.
ImageMaxDimension = max(App.TargetDocument.Width,
App.TargetDocument.Height)
TextScaleFactor = max(0.25, float(ImageMaxDimension) / 1000.0)
TextSize = int(16.0 * TextScaleFactor)

# now place the text - use right justification at the lower right
corner of the image.
# we are placing 16 pixel text, so to leave some room for leading we
place the first
# line of text 24 pixels up from the bottom, and the second will be
only 4 pixels up
# from the bottom.
# since we use a black backdrop for the text, make the text color
white.
# TextPlacementLine1 = (App.TargetDocument.Width - 4 *
TextScaleFactor, App.TargetDocument.Height - (24 * TextScaleFactor))
TextPlacementLine1 = (App.TargetDocument.Width - 5 *
TextScaleFactor, App.TargetDocument.Height - (7 * TextScaleFactor))
App.Do( Environment, 'TextEx', {
'Visibility': True,
'CreateAs': App.Constants.CreateAs.Vector,
'TextFlow': App.Constants.TextFlow.HorizontalDown,
'TextType': App.Constants.TextType.TextBase,
'AutoKern': False,
# 'Font': PSPUtils.CaptionFontName,

'Font': u'Comic Sans MS',
'Italic': False,
# 'Bold': True,
'Bold': False,
'AntialiasStyle': App.Constants.AntialiasEx.Smooth,
'Fill': {
'Color': (100,250,250),
# 'Color': (255,255,255),
# 'Color': (0,0,0),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None,
'Identity': u'Material'
},
'Stroke': {
'Color': (100,250,250),
# 'Color': (255,255,255),
# 'Color': (0,0,0),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None,
'Identity': u'Material'
},
'LineWidth': 0,

'PointSize': TextSize,
'Start': TextPlacementLine1,
# 'Stroke': None,
# 'LineStyle': None,
# 'LineWidth':0,
'SetText': App.Constants.Justify.Right,
# 'Characters': tline,
'Characters': CaptionTextCamera,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,0),1)
}
})

# we have the text down, but we want to put a backdrop behind it
so that the text remains
# visible. How big do we make the backdrop? Who knows, so we just
ask the vector layer how
# big it is
Result = App.Do( Environment, 'ReturnLayerProperties',
{'GeneralSettings': {'Version': ((9,0,0),1) }} )
TextRectangle = Result[ 'LayerRect' ]
FillStartPoint = ( TextRectangle[0][0] - (4 * TextScaleFactor),
TextRectangle[0][1] - (4 * TextScaleFactor) )
FillEndPoint = ( App.TargetDocument.Width, App.TargetDocument.Height
)

# select the raster layer - it is immediately below the vector layer
App.Do( Environment, 'SelectLayer', {
'Path': (0,-1,[],App.Constants.Boolean.false),
'GeneralSettings': {'Version': ((9,0,0),1) }
})

# make a selection around the bounding box of the text. Once we
have a selection we'll fill it
App.Do( Environment, 'Selection', {
'General': {
'Mode': App.Constants.SelectionOperation.Replace,
'Antialias': App.Constants.Boolean.true,
'Feather': 0
},
'SelectionShape': App.Constants.SelectionShape.Rectangle,
'Start': FillStartPoint,
'End': FillEndPoint,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'Version': ((9,0,0),1)
}
})

# now do a flood fill, making sure the point we click on is inside
of our selection
# use a dark grey for the fill so that we can see the text on top of
it
App.Do( Environment, 'Fill', {
'BlendMode': 0,
'MatchMode': 1,
'Material': {
'Color': (32,32,32),
'Pattern': None,
'Gradient': None,
'Texture': None
},
'Opacity': 100,
'Point': (FillStartPoint[0] + 1, FillStartPoint[1] + 1),
'Tolerance': 20,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'Version': ((9,0,0),1)
}
})

# restore the original selectoin
SelSaver.RestoreSelection()

# All done!

SuzShook

2007-07-27, 6:23 pm

Please attach the script to a post - it is far too difficult to deal with a
whole script, and get line numbers correct, with all the text wrapping that
occurs with posting inline. Thanks. Suz

Shipyard wrote:
> In article <46a8b8af_1@cnews>, suzshook@roadrunner.com says...
>
> Thanks for looking, Suz.
>
> I should have posted the whole script, which I will now do.
>
> As shown below, the script will work on any image containing Exif
> information. If I uncomment lines 35 to 44, it won't work at all (I
> mean no text gets displayed). That's the fundamental problem. Note
> that I don't need to uncomment line 180 to make it not work.
>
> from PSPApp import *
> import string
> import PSPUtils
>
> # 2007.07.26 Adapted from the EXIFCaptioning script in PSP-XI
>
> def ScriptProperties():
> return {
> 'Author': u'Corel Corporation',
> 'Copyright': u'Copyright (c) 2002-2006 Corel Corporation. All
> rights reserved.',
> 'Description': "Put EXIF camera and exposure information at the
> bottom of the image.",
> 'Host': u'Paint Shop Pro 9',
> 'Host Version': u'9.00',
> }
>
> def Do(Environment):
>
> if PSPUtils.RequireADoc( Environment ) ==
> App.Constants.Boolean.false:
> return
>
> # first extract the EXIF data - if we can't find any just return
> without changing the image
> ImageInfo = App.Do( Environment, 'ReturnImageInfo',
> {'GeneralSettings': {'Version': ((9,0,0),1) }} )
> if ImageInfo['ExifMake'] == '' or ImageInfo['ExifModel'] == '' or \
> ImageInfo['ExifFNumber' ] == '' or ImageInfo['ExifExposureTime']
> == '':
> App.Do(Environment, 'MsgBox', {
> 'Buttons': App.Constants.MsgButtons.OK,
> 'Icon': App.Constants.MsgIcons.Stop,
> 'Text': PSPUtils.NoEXIFData,
> 'GeneralSettings': {'Version': ((9,0,0),1) }
> })
> return
>
> fid = App.ActiveDocument.Title
>
> '''
> # fn=fid + '.exif.txt'
> fn='c:/photos/2007-07-26/2007-07-26.1683.0.jpg.exif.txt'
> f=open(fn,'r')
> flines=f.readlines()
> f.close()
> for eachline in flines:
> tline=eachline
> # tline=eachline.strip()
> '''
>
> # ISO value is not always present
> if ImageInfo['ExifISOSpeed'] == '': isost = ''
> else: isost = ' iso' + ImageInfo['ExifISOSpeed'].strip()
>
> if ImageInfo['ExifOriginalSubSecond'] == '00': osst = ''
> else: osst = '.' + ImageInfo['ExifOriginalSubSecond'].rstrip
> ('0').strip()
>
> # save any existing selection
> SelSaver = PSPUtils.SaveSelection( Environment, App.TargetDocument
> )
>
> # assemble the camera string by concatenating the camera make and
> model. Some camera
> # manufacturers have the barbaric practice of CAPITALIZING
> everything in their make and model
> # strings, so convert it to initial caps only for a more civilized
> appearance
> # CaptionTextCamera = unicode(string.capwords(
> ImageInfo['ExifMake'] + ' ' + ImageInfo[ 'ExifModel' ] ))
> # CaptionTextCamera = unicode(string.capwords( ImageInfo
> ['ExifModel'] + ' ' + ImageInfo[ 'ExifOriginalDate' ] ))
> # CaptionTextCamera = unicode(string.capwords( ImageInfo
> ['ExifModel']
>
> CaptionTextCamera = unicode \
> (
> ImageInfo['ExifOriginalDate'].replace(':','.',2).strip()
> + osst
> + isost
> + ' ' + 'f' +
> ImageInfo['ExifFNumber'].rstrip('0').rstrip('.').strip ()
> + ' ' + ImageInfo['ExifExposureTime'].rstrip(' second').strip()
> + ' ' + ImageInfo['ExifFocalLength'].rstrip('0 mm').rstrip
> ('.').strip() + 'mm'
> + ' ' + fid.lower().strip()
> + ' ' + string.capwords(ImageInfo['ExifModel'])
> )
>
> # now assemble exposure information by using the aperture and
> exposure
> # Aperture = float(ImageInfo['ExifFNumber'])
> # CaptionTextExposure = PSPUtils.ExposureMsg % (Aperture, ImageInfo
> ['ExifExposureTime'].strip())
>
> # first we create a raster layer at 50% opacity as a backdrop for
> the caption
> # for now the raster layer is empty - we'll fill it in later
> # the new layer becomes the active layer
> App.Do( Environment, 'NewRasterLayer', {
> 'General': {
> # 'Opacity': 50,
> 'Opacity': 0,
> 'Name': PSPUtils.CaptionBackground,
> 'IsVisible': App.Constants.Boolean.true,
> },
> 'GeneralSettings': {
> 'ExecutionMode': App.Constants.ExecutionMode.Silent,
> 'Version': ((9,0,0),1)
> }
> })
>
> # create a layer group. This will place the raster layer in the
> group
> # the group is the active layer on completion
> App.Do( Environment, 'NewLayerGroup', {
> 'General': {
> 'Opacity': 100,
> 'Name': PSPUtils.EXIFCaption,
> },
> 'GeneralSettings': {
> 'ExecutionMode': App.Constants.ExecutionMode.Silent,
> 'Version': ((9,0,0),1)
> }
> })
>
> # select the raster layer so that the vector layer gets created
> above it
> App.Do( Environment, 'SelectLayer', {
> 'Path': (0,0,[1],App.Constants.Boolean.false),
> 'GeneralSettings': {'Version': ((9,0,0),1) }
> })
>
> # now create a vector layer to put text on - creating the layer
> will make it active
> App.Do( Environment, 'NewVectorLayer', {
> 'General': {
> 'Opacity': 100,
> 'Name': PSPUtils.EXIFText,
> },
> 'GeneralSettings': {
> 'ExecutionMode': App.Constants.ExecutionMode.Silent,
> 'Version': ((9,0,0),1)
> }
> })
>
> # Figure out how big the text should be by examining the overall
> image size. We'll do a rough
> # scale based on 1000 pixels. We won't paint text less than 16
> point in any event.
> ImageMaxDimension = max(App.TargetDocument.Width,
> App.TargetDocument.Height)
> TextScaleFactor = max(0.25, float(ImageMaxDimension) / 1000.0)
> TextSize = int(16.0 * TextScaleFactor)
>
> # now place the text - use right justification at the lower right
> corner of the image.
> # we are placing 16 pixel text, so to leave some room for leading
> we place the first
> # line of text 24 pixels up from the bottom, and the second will be
> only 4 pixels up
> # from the bottom.
> # since we use a black backdrop for the text, make the text color
> white.
> # TextPlacementLine1 = (App.TargetDocument.Width - 4 *
> TextScaleFactor, App.TargetDocument.Height - (24 * TextScaleFactor))
> TextPlacementLine1 = (App.TargetDocument.Width - 5 *
> TextScaleFactor, App.TargetDocument.Height - (7 * TextScaleFactor))
> App.Do( Environment, 'TextEx', {
> 'Visibility': True,
> 'CreateAs': App.Constants.CreateAs.Vector,
> 'TextFlow': App.Constants.TextFlow.HorizontalDown,
> 'TextType': App.Constants.TextType.TextBase,
> 'AutoKern': False,
> # 'Font': PSPUtils.CaptionFontName,
>
> 'Font': u'Comic Sans MS',
> 'Italic': False,
> # 'Bold': True,
> 'Bold': False,
> 'AntialiasStyle': App.Constants.AntialiasEx.Smooth,
> 'Fill': {
> 'Color': (100,250,250),
> # 'Color': (255,255,255),
> # 'Color': (0,0,0),
> 'Pattern': None,
> 'Gradient': None,
> 'Texture': None,
> 'Art': None,
> 'Identity': u'Material'
> },
> 'Stroke': {
> 'Color': (100,250,250),
> # 'Color': (255,255,255),
> # 'Color': (0,0,0),
> 'Pattern': None,
> 'Gradient': None,
> 'Texture': None,
> 'Art': None,
> 'Identity': u'Material'
> },
> 'LineWidth': 0,
>
> 'PointSize': TextSize,
> 'Start': TextPlacementLine1,
> # 'Stroke': None,
> # 'LineStyle': None,
> # 'LineWidth':0,
> 'SetText': App.Constants.Justify.Right,
> # 'Characters': tline,
> 'Characters': CaptionTextCamera,
> 'GeneralSettings': {
> 'ExecutionMode': App.Constants.ExecutionMode.Silent,
> 'AutoActionMode': App.Constants.AutoActionMode.Match,
> 'Version': ((9,0,0),1)
> }
> })
>
> # we have the text down, but we want to put a backdrop behind
> it so that the text remains
> # visible. How big do we make the backdrop? Who knows, so we just
> ask the vector layer how
> # big it is
> Result = App.Do( Environment, 'ReturnLayerProperties',
> {'GeneralSettings': {'Version': ((9,0,0),1) }} )
> TextRectangle = Result[ 'LayerRect' ]
> FillStartPoint = ( TextRectangle[0][0] - (4 * TextScaleFactor),
> TextRectangle[0][1] - (4 * TextScaleFactor) )
> FillEndPoint = ( App.TargetDocument.Width,
> App.TargetDocument.Height )
>
> # select the raster layer - it is immediately below the vector
> layer App.Do( Environment, 'SelectLayer', {
> 'Path': (0,-1,[],App.Constants.Boolean.false),
> 'GeneralSettings': {'Version': ((9,0,0),1) }
> })
>
> # make a selection around the bounding box of the text. Once we
> have a selection we'll fill it
> App.Do( Environment, 'Selection', {
> 'General': {
> 'Mode': App.Constants.SelectionOperation.Replace,
> 'Antialias': App.Constants.Boolean.true,
> 'Feather': 0
> },
> 'SelectionShape': App.Constants.SelectionShape.Rectangle,
> 'Start': FillStartPoint,
> 'End': FillEndPoint,
> 'GeneralSettings': {
> 'ExecutionMode': App.Constants.ExecutionMode.Silent,
> 'Version': ((9,0,0),1)
> }
> })
>
> # now do a flood fill, making sure the point we click on is inside
> of our selection
> # use a dark grey for the fill so that we can see the text on top
> of it
> App.Do( Environment, 'Fill', {
> 'BlendMode': 0,
> 'MatchMode': 1,
> 'Material': {
> 'Color': (32,32,32),
> 'Pattern': None,
> 'Gradient': None,
> 'Texture': None
> },
> 'Opacity': 100,
> 'Point': (FillStartPoint[0] + 1, FillStartPoint[1] + 1),
> 'Tolerance': 20,
> 'GeneralSettings': {
> 'ExecutionMode': App.Constants.ExecutionMode.Silent,
> 'Version': ((9,0,0),1)
> }
> })
>
> # restore the original selectoin
> SelSaver.RestoreSelection()
>
> # All done!



Shipyard

2007-07-27, 6:23 pm

Sorry, Suz. I'm a novice at this Newsgroup caper. Is this useable?


Spandex Rutabaga

2007-07-27, 6:23 pm


Shipyard wrote:
>
> Sorry, Suz. I'm a novice at this Newsgroup caper. Is this useable?
>
> ------------------------------------------------------------------------
> Name: aaCapt.PspScript
> aaCapt.PspScript Type: Jasc PSP Script (application/x-unknown-content-type-PaintShopPro9.Script)
> Encoding: Base64


You have something in the script which says:

for eachline in flines:
tline=eachline

This is a loop. It supposedly fills the variable tline with the
contents of the variable eachline on each pass through the loop.
You don't use tline anywhere else in the script. There is one
further reference to it (in the TextEx command) but it is
commented out. I have a feeling you want the TextEx command
to be part of the loop but I don't think it is given how you've
structured the script. I might be wrong in all this but maybe
it will give you an idea of what to check. It may also help to
explain in detail what the intended behavior of the script is,
i.e. exactly how the output should look and what it is supposed
to contain. We know in general what you want to do but a
specific description will help.
SuzShook

2007-07-27, 6:23 pm

underprocessable
Shipyard

2007-07-28, 6:19 am

Than you very much, Suz. I now have a working script.

But I still don't know what was wrong with the previous attempt. As I
said, it ran fine here with the code commented out, and not at all with
it included. I guess I'll never know, and please don't waste time on it.
I'm happy now. Thanks again.

In article <46a9163b_1@cnews>, suzshook@roadrunner.com says...
> In that script, you've made a lot of changes, and the script fails for me
> several times, until I put back the code you removed from the original
> (lines 14-21 in the original script)


I didn't remove anything at lines 14-21. The code you've "put back" is
not in the original script I got with PSP XI (attached).

Spandex: Thanks for your time. I know it's a loop, but the file contains
only one line, as I said in my post. Call it quick and dirty. I know
tline was commented out; the point was that the script didn't work at
all with the read code added, even with the original text.


SuzShook

2007-07-28, 6:22 pm

Interesting, Shipyard. I just looked at the PSP XI version of the script,
and you are right - the format is a bit changed. I was running it in PSP X.
I don't know what the problem was either, but I'm glad it works now, though.
Suz

Shipyard wrote:
> Than you very much, Suz. I now have a working script.
>
> But I still don't know what was wrong with the previous attempt. As I
> said, it ran fine here with the code commented out, and not at all
> with it included. I guess I'll never know, and please don't waste
> time on it. I'm happy now. Thanks again.
>
> In article <46a9163b_1@cnews>, suzshook@roadrunner.com says...
>
> I didn't remove anything at lines 14-21. The code you've "put back" is
> not in the original script I got with PSP XI (attached).
>
> Spandex: Thanks for your time. I know it's a loop, but the file
> contains only one line, as I said in my post. Call it quick and
> dirty. I know tline was commented out; the point was that the script
> didn't work at all with the read code added, even with the original
> text.



Shipyard

2007-07-30, 6:25 pm

Following on from this, I've fiddled around with the script until I'm
happy with what it does, and tried writing a few more simple scripts.

Usually I can get scripts to work eventually, but it's often a long
uphill struggle in the dark involving trial-and-error, because PSP-XI
doesn't seem to want to display any messages indicating what went wrong.
The script just doesn't work, and PSP says nothing.

The only error message I've seen is something like "Script cannot be
loaded". That's even less useful than "Tilt".

Is there a way to cajole PSP into displaying informative messages? It
would make life a lot easier.

I have tried single-stepping, by the way. That doesn't help much either,
beyond indicating roughly how far the script got before failing
silently.
SuzShook

2007-07-30, 6:25 pm

underprocessable
Shipyard

2007-07-30, 6:25 pm

In article <46ac8287_1@cnews>, suzshook@roadrunner.com says...
> ScriptWndFilterLevel ...


Thanks again, Suz. How do you come by such useful information?

I have the following PSP documentation, apart from the rudimentary User
Guide:

Scripting Howto.pdf (but this is for version X)
SampleScripts.pdf (plus some sample scripts, again for version X)
PSPPXICommandAPI (folder of HTML files, for version XI)

I also have a book, namely PaintShopProX for Photographers, which barely
mentions scripting, and Core Python Programming, which doesn't mention
PSP (I wouldn't expect it to).

Could you -- obviously an expert -- please recommend some useful sources
of detailed information dealing with scripting in PSP? I get the
impression that Corel hasn't applied much effort in this department, and
I know of no books dealing with it. And the API documents are almost
impenetrable to me, and I'm a programmer (and technical author) by
trade.

For example, your post led me to the API entry on ScriptWndFilterLevel.
It includes this: "so that application output can be suppressed in favor
of script output". Say what? There's no way I could've divined what that
means if you hadn't prepared the ground, or indeed how to use it from
the "description" in the "API".

The Motto of the Technical Author: "Sometimes we write; sometimes we
wrong."
SuzShook

2007-07-30, 6:25 pm

As far as I know, there's nothing which is specifically PSP/Scripting other
than the docs you mention. I have several Python books - I'm self-taught in
this area, so my knowledge has come slowly and after much searching and
experimentation. My favorite Python book is Chris Fehily's Python, a Visual
Quickstart Guide. I use it all the time as a reference. I have written a
few courses in PSP Scripting - trying to take the mystery out of something
so useful. They're given at LVS, and are currently self-study, if you'd be
interested. Suz

Shipyard wrote:
> In article <46ac8287_1@cnews>, suzshook@roadrunner.com says...
>
> Thanks again, Suz. How do you come by such useful information?
>
> I have the following PSP documentation, apart from the rudimentary
> User Guide:
>
> Scripting Howto.pdf (but this is for version X)
> SampleScripts.pdf (plus some sample scripts, again for version X)
> PSPPXICommandAPI (folder of HTML files, for version XI)
>
> I also have a book, namely PaintShopProX for Photographers, which
> barely mentions scripting, and Core Python Programming, which doesn't
> mention PSP (I wouldn't expect it to).
>
> Could you -- obviously an expert -- please recommend some useful
> sources of detailed information dealing with scripting in PSP? I get
> the impression that Corel hasn't applied much effort in this
> department, and I know of no books dealing with it. And the API
> documents are almost impenetrable to me, and I'm a programmer (and
> technical author) by trade.
>
> For example, your post led me to the API entry on
> ScriptWndFilterLevel. It includes this: "so that application output
> can be suppressed in favor of script output". Say what? There's no
> way I could've divined what that means if you hadn't prepared the
> ground, or indeed how to use it from the "description" in the "API".
>
> The Motto of the Technical Author: "Sometimes we write; sometimes we
> wrong."



Sponsored Links


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