This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > August 2006 > scripting question - anyone?





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 scripting question - anyone?
Senor47+

2006-08-14, 6:55 pm

I've a script which save current picture with a new name ( after input -
e.g. "new" ) and switch the extension to jpg. Than it resizes this image to
a predefined size and save it with the same name + _two (e.g. new_two.jpg )
and finally resize yet again to a predefined size and save it with the same
name - but switch the extension to gif. (e.g. "new.gif")

Maybe this is a bit clearer:

Filename: "original.pspimage"
- resize and save as : new.jpg - this part is ok!
- resize and save as : new_two.jpg
- resize and save as : new.gif

Now the script gives all files the same name - regardless of what name I
give it in step one, on step 2 the name will always be "new_two.jpg"
Anyone knows if there is a way the script could pick up the filename
automatically from step 1 and just add/remove the "_new" part?


Fred Hiltz

2006-08-14, 6:55 pm

Senor47+ wrote:
> I've a script which save current picture with a new name...
>
> Now the script gives all files the same name - regardless of what
> name I give it in step one, on step 2 the name will always be
> "new_two.jpg" Anyone knows if there is a way the script could pick
> up
> the filename automatically from step 1 and just add/remove the
> "_new"
> part?


Several of us know, but without seeing your script, we cannot tell
where it goes wrong.

However, you may be fighting the wrong battle. PSP's own batch
processor already does the file name manipulation, file type
changes, and saving in the same or another folder. It will do this
for selected images or for all in a folder. You can run it once to
produce the GIF copies and once to produce the JPG copies.

BP will not do the resizing. For that, you record a script while
resizing one open image. Tell the batch processor to run that script
on each image as it works through those that you select.

For more, see Help > Contents > Automating Tasks > Processing Files
in Batches, and the following article, Renaming Files in Batches.
--
Fred Hiltz, fhiltz at yahoo dot com

Spandex Rutabaga

2006-08-14, 6:55 pm

Senor47+ wrote:
>
> I've a script which save current picture with a new name ( after input -
> e.g. "new" ) and switch the extension to jpg. Than it resizes this image to
> a predefined size and save it with the same name + _two (e.g. new_two.jpg )
> and finally resize yet again to a predefined size and save it with the same
> name - but switch the extension to gif. (e.g. "new.gif")


You shouldn't in general resize the image multiple times (though
there are exceptions). Usually you resize directly to the size
you want to avoid accumulation of interpolation errors.

> Maybe this is a bit clearer:
>
> Filename: "original.pspimage"
> - resize and save as : new.jpg - this part is ok!
> - resize and save as : new_two.jpg
> - resize and save as : new.gif
>
> Now the script gives all files the same name - regardless of what name I
> give it in step one, on step 2 the name will always be "new_two.jpg"
> Anyone knows if there is a way the script could pick up the filename
> automatically from step 1 and just add/remove the "_new" part?


Do what Fred said. When you record a script it records any file
name you use. To have it process a list of files or to generate
a collection of file names you would have to code that yourself
using Python operating system functions. Fortunately you don't
need to do that. You can instead use PSP's File > Batch Process
functionality. This lets you create new file names from old. You
will find it easier to have one script that does the first
resize, the Batch Process command saving JPEGs. Then a second
script can do the other resize (in one step) and the Batch Process
command can be set to save GIFs.
RonV

2006-08-14, 6:55 pm

On Mon, 14 Aug 2006 18:41:54 +0200, "Senor47+" <senior47@online.no>
wrote:

>I've a script which save current picture with a new name ( after input -
>e.g. "new" ) and switch the extension to jpg. Than it resizes this image to
>a predefined size and save it with the same name + _two (e.g. new_two.jpg )
>and finally resize yet again to a predefined size and save it with the same
>name - but switch the extension to gif. (e.g. "new.gif")
>
>Maybe this is a bit clearer:
>
>Filename: "original.pspimage"
>- resize and save as : new.jpg - this part is ok!
>- resize and save as : new_two.jpg
>- resize and save as : new.gif
>
>Now the script gives all files the same name - regardless of what name I
>give it in step one, on step 2 the name will always be "new_two.jpg"
>Anyone knows if there is a way the script could pick up the filename
>automatically from step 1 and just add/remove the "_new" part?
>


I assume you're wanting the information to do such programming.
First, go to the Corel site, click on 'Support' and do a site search
for a document called Scripting for Script Authors in the PSP section.

There are complete instructions on how to install it. This is the
PSP'ers guide to using the PSP script. It doesn't tell you how
Python, the script language, works.

For that, go to http://www.python.org/ and d/w, install Python as a
stand-alone program.

Start it, open the help file and study the 'Tutorial' section, there's
a ton of information about programming there. However, you'll need to
know how to use the Global Modules, too. There are many of these, and
all do different functions. The 'os.path' statement below loads a
module, then the split and splitext are called from it.

For example, to do what you asked about, you can do something like
this:
import os.path

FileLocation = App.ActiveDocument.Name #get the full file path
path, filename = os.path.split(FileLocation) #split into componets
Name,Ext = os.path.splitext(filename) # split into a name and ext

Name = Name + 'partTwo' # create a new filename
NewName = path + Name + Ext #make a pathname

.... and in the file save section, use the string variable NewName.

Naturally, you'll need to correctly indent the program lines to match
the section it's embedded into.

RonV

Senor47+

2006-08-14, 6:55 pm

underprocessable
Fred Hiltz

2006-08-14, 6:55 pm

Senor47+ wrote:
> "Spandex Rutabaga" wrote:

....
>
>
> I made the script with PSP record script tool, and thought it
> would be
> possible to modify it some way to work the way I want.
> Usually there are just 1 or 2 files at a time, so Batch process
> the
> way you - and Fred - said, will take longer time than doing it
> manually - as I do now.
> The script file is attached, ...


OK. Of course there are thousands of ways to write a program. I'd go
to the references that Ron just gave you, get the file name from the
user with a dialog, and plug that into the first FileSaveAs. Then
use Python string manipulations to create the remaining file names.

Be sure to handle the case where the user mistakenly names a
non-existent file. Be sure to handle over-writes of existing files,
too.

As for the time required to run the Batch Processor, don't forget
that you can record a script while running it once, then attach the
script to a toolbar icon. That makes one-click processing of
selected files or all files in a folder. Your call, once informed of
the options.
--
Fred Hiltz, fhiltz at yahoo dot com

Senor47+

2006-08-14, 6:55 pm


"RonV" <RonVick@Nospam.com> skrev i melding
news:b8e1e25ta872k1r2e8ahta77tq6pls9dri@4ax.com...
> On Mon, 14 Aug 2006 18:41:54 +0200, "Senor47+" <senior47@online.no>
> wrote:


> I assume you're wanting the information to do such programming.
> First, go to the Corel site, click on 'Support' and do a site search
> for a document called Scripting for Script Authors in the PSP section.
>
> There are complete instructions on how to install it. This is the
> PSP'ers guide to using the PSP script. It doesn't tell you how
> Python, the script language, works.
>
> For that, go to http://www.python.org/ and d/w, install Python as a
> stand-alone program.
>
> Start it, open the help file and study the 'Tutorial' section, there's
> a ton of information about programming there. However, you'll need to
> know how to use the Global Modules, too. There are many of these, and
> all do different functions. The 'os.path' statement below loads a
> module, then the split and splitext are called from it.
>
> For example, to do what you asked about, you can do something like
> this:
> import os.path
>
> FileLocation = App.ActiveDocument.Name #get the full file path
> path, filename = os.path.split(FileLocation) #split into componets
> Name,Ext = os.path.splitext(filename) # split into a name and ext
>
> Name = Name + 'partTwo' # create a new filename
> NewName = path + Name + Ext #make a pathname
>
> ... and in the file save section, use the string variable NewName.
>
> Naturally, you'll need to correctly indent the program lines to match
> the section it's embedded into.
>
> RonV
>


Problem solved - so fare!



Your suggestion and a close look at one of SuzShook scripts
(ss-SavingImages-01) gave me enough input to fix my script to work the way I
want! Thanks to both of you!



And thanks to Fred and Spandex for his input too, I appreciate it!



Svein


Sponsored Links


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