How to Write Your Own Scripts

by Sigrid, Co-Owner of EZ Tagging



Part 6 - Some Final Remarks and How to Proceed

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


The Print Command

If at any time you want to know the value of one of your variables you can use the print command to give out the value in the script output palette
As an example I have added the print command to our script.



Here is how the script output showed it

The Script Output shows the value but if you have more than two variables it would be nice to know which one it shows, right? So here is how you can add some explanatory text to the print command:


Here is how the script output showed it

The blanks before the text make the print text better visible and the explanation makes it easier to read. As you can see, everything that has to be printed has to be either in quotation marks or be stored in a variable.


Asking PSP for Image Width and Height

You know how big your open image is. And of course PSP knows it as well. But the script doesn't know. But it can find out by asking PSP. If you know how to ask the right questions you will surely get an answer.

In the first part of this tutorial I gave you a link to Suzy Shook's Scripting Values Table. There you can find under the keyword "Height" or "Width" the command ReturnImageInfo. This is the command we need.

How about writing a whole new script that just gives us image height and width in a variable?

Open your script, save it with a new name and delete everything below the line def Do(Environment):

Add the command text like in this preview

(or just download the text I have prepared for your convenience from the link above)

Save and run the script.
Here is how your output palette should look like:

And this is, what you get if no image is open during the run of this new script:


Try and Except Routine

It is not good to get an error message while letting a script run. An easy way to prevent this is to let PSP look if there is an image open. If there is an image open then there has to be an Active Document with a name, a path and a directory.

Another nice feature of PSPScripts is the try - except-command, which does exactly what the name says:

It tries to use the commands you add inside it and if that is not possible it jumps to the except-part of the command.

Again I have saved a text file for you with a try - except-command for an open file and also several other convenient features, like a message box in the except-part that can be used somewhere else as well.

Simply add it to your ImageInfo.pspscript (or however you named it) and the ugly error-message should vanish, even if no picture is open when you run the script.


Just add the try - except-command in front of the ImageInfo-part and your script should run smoothly

Result without an open image:


Result with an open image:


How to Proceed

You now have the knowledge to record a script and add loops, conditions and variables to it to change it according to your needs. There are, of course, many other features that can be done with a PSP-Script. To learn them in self study, you should open many scripts and analyze them.

Don't hesitate to copy parts out of other people's scripts if they do exactly what you want your script to do. If you use that method you have to make sure that you know which of the different commands are script-commands, variables, or functions. Download, for example, the AddNameNew_se.pspscript that I have written or the AddNameFromFile_se.pspscript that I have written to find out how to add names to a tag or read names from a text file. Analyzing these scripts you can find out how functions are used in scripts. To download them, simply go back to the tutorial index and then download the materials of the "Add Name Script"-tutorial

Some script writers are kind enough to share code snipets like Suzy. And if you want to calculate something you can always refer to the Python language

If you have further questions or suggestions don't hesitate to contact me at sigrid@mypspx3.com.

~~~~~~~~~~~~~~~~

Back Back To Part 1

~~~~~~~~~~~~~~~~

EZ TAGGING

~~~~~~~~~~~~~~~~



This tutorial was written by Sigrid
Any similarities to other tutorials is merely a coincidence.
~All rights reserved - March 2009~