Larger versions of images can be seen by clicking on the image. Also, thank you for your kind and encouraging comments. I love reading the comments. If you use my any of freebies, I would be overjoyed with a comment containing a link to your item. I love seeing any of my freebies in use.
Sunday, August 3, 2008
Parts of a Script
The first line in a script 'from JascApp import *' allows for communication between the script and PSP. It is essential. When the wrong module is loaded (PSPApp, for example), then the script cannot function. The next word in the script is 'def' which defines a function. In this case, it is the ScriptProperties function which provides information such as the author of the script, copyright, and a description of the script.
The name of a function appears after the word def. The second function in any script is the Do function. Most of the work of the script occurs inside the Do function.
All scripts are called with the App.Do method. App refers to a variable name inside of JascApp. Do is the function. App.Do passes the Environment argument, the Command name (circled in blue) and a dictionary to PSP to perform a command.
The dictionary is composed of keys which can be used to summon information from the dictionary and values which is the information needed to perform the command.
Finally, there are pound or number (#) signs which are used to designate comments. Anything with a pound sign to the left is a comment and is ignored by the script and PSP. Comments are used to for notations in the script so that the script author can tell future users what is happening in the script.
The following is a complex script which I broke down for Deb of DeeBe Designs. It details the script modifications seen in a lot of my script tutorials.
Circled is the Fill Variable. Once the GetMaterial command has been executed, it contains all the information for Material in a dictionary which has the keys: Color, Gradient, Pattern, Texture and Art.
In the Custom Colors in Effects tutorial, the script snippet uses a while loop. There are several elements in the code snippet which are explained here. First, the user is asked to choose a color so that the Fill variable is set prior to execution of the loop. Every action in the loop is indented inside the loop. I recommend at least 3 spaces and the first line of new App.Do function calls should be indented the same amount. The while loop sets two variables: Fill and MyColor.
If the Fill variable is unset, then if the user clicks cancel in the Materials palette, MyColor can end up with a null value which will cause PSP to cycle endlessly in a loop. The only to stop the loop is to abort the program. In the while loop, we ask the user to choose a color if they happen to choose a gradient or pattern. The while loop forces the user to choose a color instead of a different option. So, as long as there is not a color, the loop will cycle. Once the user chooses a color, we call the color out of the Fill dictionary and place the color inside the MyColor variable.
This example shows how the MyColor variable is set and then used in the Blinds Effect.
However, if a color choice is forced and then the resulting variable is used in Fill or any other command which accepts a material, such a preset shape, then it is important to use the correct variable. If a dictionary is improperly defined, the App.Do method will send the incorrect information to PSP and the script will not work correctly.
For example, the FlowerFill variable is being used to store all the information resulting from the GetMaterial command. The FlowerFill variable can be used by itself as the data for the Fill key in the Preset Shape command.
However, if the color information is placed in a new variable, FlowerColor, the variable FlowerColor cannot be used as the entire data for the Fill key. That is because FlowerColor is a tuple and Fill requires a dictionary. FlowerColor can only substitute as data for the Color key inside the dictionary.