Monday, May 4, 2009

Turning a Tutorial Into a Script


This tutorial will show you how to make a script and then modify the script to allow a user to choose their own color, gradient or pattern. I am going to use my ric rac tutorial to show how a tutorial can easily be converted into a script.

Supplies:

Ric Rac Tutorial

1. Have my Ric Rac Tutorial available (either printed or open in a web browser).

2. Go to the script toolbar (or menu) and press the circle to start recording.

Toolbar

Menu

3. Follow the directions in the Ric Rac Tutorial. Do not worry if you make a mistake. If you make a mistake, just undo the action (Ctrl-Z).

4. Once you have finished the tutorial, save the script by going to the script toolbar (or menu) and pressing the disk icon.

A window will pop up asking you for a name (and location) to save the script. Make sure 'Remove Undone Commands' is checked and 'Save Dialog Positions' is unchecked. To make sure that your script will be identical to the one in this tutorial, make sure 'Save Materials' is checked. You now have a script that will make a ric rac in only one set of colors. If you save the script with 'Save Materials' unchecked, then the script will make a ric rac in your existing foreground and background colors.

5. Now we will edit the script so that the user can select colors. Open up the script editor by clicking the scroll button on the script toolbar.

A pop up window for the Script Editor will appear. Go to the bottom and click 'Text Editor.'

6. The text editor is Notepad. In Notepad, the script looks like this:

from JascApp import *

def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'Paint Shop Pro 9',
'Host Version': u'9.01'
}

def Do(Environment):
# EnableOptimizedScriptUndo
App.Do( Environment, 'EnableOptimizedScriptUndo', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# FileNew
App.Do( Environment, 'NewFile', {
'Width': 3600,
'Height': 150,
'ColorDepth': App.Constants.Colordepth.SixteenMillionColor,
'DimensionUnits': App.Constants.DimensionType.Pixels,
'ResolutionUnits': App.Constants.ResolutionUnits.PixelsPerIn,
'Resolution': 300,
'FillMaterial': {
'Color': (255,255,255),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'Transparent': True,
'LayerType': App.Constants.NewLayerType.Raster,
'ArtMediaTexture': {
'Category': u'Art Media',
'Name': u'Canvas coarse',
'EnableFill': False,
'FillColor': (255,255,255)
},
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': 0,
'Strict': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# Fill
App.Do( Environment, 'Fill', {
'BlendMode': App.Constants.BlendMode.Normal,
'MatchMode': App.Constants.MatchMode.None,
'Material': {
'Color': (80,235,236),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'UseForeground': True,
'Opacity': 100,
'Point': (1594.5,30.5),
'SampleMerged': False,
'Tolerance': 20,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# SelectAll
App.Do( Environment, 'SelectAll', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# Select Selection Borders
App.Do( Environment, 'SelectSelectionBorders', {
'Antialias': True,
'BordersType': App.Constants.BordersType.Inside,
'BorderWidth': 10,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# Fill
App.Do( Environment, 'Fill', {
'BlendMode': App.Constants.BlendMode.Normal,
'MatchMode': App.Constants.MatchMode.None,
'Material': {
'Color': (3,166,167),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'UseForeground': True,
'Opacity': 100,
'Point': (1830.5,10.5),
'SampleMerged': False,
'Tolerance': 20,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# ResizeCanvas
App.Do( Environment, 'ResizeCanvas', {
'AspectRatio': 24,
'FillColor': (192,117,0),
'HoriPlace': App.Constants.HorizontalType.Center,
'MaintainAspect': False,
'NewDimUnits': App.Constants.UnitsOfMeasure.Pixels,
'NewHeight': 300,
'NewWidth': 3580,
'PlaceBottom': 75,
'PlaceLeft': -10,
'PlaceRight': -10,
'PlaceTop': 75,
'VertPlace': App.Constants.VerticalType.Center,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# SelectInvert
App.Do( Environment, 'SelectInvert', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# Halftone
App.Do( Environment, 'Halftone', {
'BackgroundColor': (255,255,255),
'ColorScheme': App.Constants.ColorScheme.Greyscale,
'HalftonePattern': App.Constants.HalftonePattern.Round,
'Overlay': True,
'OverlayBlendMode': App.Constants.BlendMode.Overlay,
'OverlayOpacity': 48,
'PatternColor': (0,0,0),
'ScreenAngles': (130,162,90),
'Size': 15,
'TransparentBackground': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# SelectNone
App.Do( Environment, 'SelectNone', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

# Wave
App.Do( Environment, 'Wave', {
'HorizontalAmplitude': 0,
'HorizontalWavelength': 25,
'VerticalAmplitude': 20,
'VerticalWavelength': 12,
'EdgeMode': App.Constants.EdgeMode.Repeat,
'BackgroundColor': (255,255,255),
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
7. To make the script compatible with all versions of PSP, if the script was recorded PSP X or higher make sure that the first line of the script says 'from JascApp import *'.

from PSPApp import * ------> Change to ------> from JascApp import *

def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'Paint Shop Pro X',
'Host Version': u'10.03'
}
8. We are going to add the Material Picker code snippet to allow for the user to choose their own color, gradient or pattern. The code will make a pop up box on the screen that says, "Choose a color, gradient or pattern." It will have an OK button for the user to click. After the user clicks OK, the Materials palette will display. This is the code snippet:

Result = App.Do(Environment,'MsgBox',{
'Buttons':App.Constants.MsgButtons.OK,
'Icon':App.Constants.MsgIcons.Info,
'Text':'Choose a color, gradient or pattern.',
})
MyFill = App.Do(Environment,'GetMaterial',{
'IsPrimary':App.Constants.Boolean.true,
'GeneralSettings': {
'ExecutionMode':App.Constants.ExecutionMode.Interactive
}
})

The code is placed before the fill command, like this:

# SelectDocument
App.Do( Environment, 'SelectDocument', {
'SelectedImage': 0,
'Strict': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
Result = App.Do(Environment,'MsgBox',{
'Buttons':App.Constants.MsgButtons.OK,
'Icon':App.Constants.MsgIcons.Info,
'Text':'Choose a color, gradient or pattern.',
})
MyFill = App.Do(Environment,'GetMaterial',{
'IsPrimary':App.Constants.Boolean.true,
'GeneralSettings': {
'ExecutionMode':App.Constants.ExecutionMode.Interactive
}
})

# Fill
App.Do( Environment, 'Fill', {
'BlendMode': App.Constants.BlendMode.Normal,
'MatchMode': App.Constants.MatchMode.None,
'Material': {
'Color': (80,235,236),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'UseForeground': True,
'Opacity': 100,
'Point': (1594.5,30.5),
'SampleMerged': False,
'Tolerance': 20,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
9. Next, we change the Fill command to accept the user's Material by removing all the Material information and replacing it with the variable (MyFill) holding the information from the user's selection from the Materials palette.

# Fill
App.Do( Environment, 'Fill', {
'BlendMode': App.Constants.BlendMode.Normal,
'MatchMode': App.Constants.MatchMode.None,
'Material': MyFill,
'UseForeground': True,
'Opacity': 100,
'Point': (1594.5,30.5),
'SampleMerged': False,
'Tolerance': 20,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
10. Repeat this change for the second color selection.

# Select Selection Borders
App.Do( Environment, 'SelectSelectionBorders', {
'Antialias': True,
'BordersType': App.Constants.BordersType.Inside,
'BorderWidth': 10,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})

Result = App.Do(Environment,'MsgBox',{
'Buttons':App.Constants.MsgButtons.OK,
'Icon':App.Constants.MsgIcons.Info,
'Text':'Choose a color, gradient or pattern.',
})
MyFill = App.Do(Environment,'GetMaterial',{
'IsPrimary':App.Constants.Boolean.true,
'GeneralSettings': {
'ExecutionMode':App.Constants.ExecutionMode.Interactive
}
})

# Fill
App.Do( Environment, 'Fill', {
'BlendMode': App.Constants.BlendMode.Normal,
'MatchMode': App.Constants.MatchMode.None,
'Material': MyFill,
'UseForeground': True,
'Opacity': 100,
'Point': (1830.5,10.5),
'SampleMerged': False,
'Tolerance': 20,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
11. To finish off the customization, add a window that will tell the user that the script is complete. At the very end of the script add the following snippet of code:
    Result = App.Do(Environment,'MsgBox',{
'Buttons':App.Constants.MsgButtons.OK,
'Icon':App.Constants.MsgIcons.Info,
'Text':'The script is now complete./n'
'Thank you for using my script.',

You can modify the phrase however you like. I have indicated below what you can change.

Result = App.Do(Environment,'MsgBox',{
'Buttons':App.Constants.MsgButtons.OK,
'Icon':App.Constants.MsgIcons.Info,
'Text':'The script is now complete./n' <----- You can change anything
'Thank you for using my script.',
<----- between the single quotes.
Your modified script is now complete. As blogger appears to enjoy removing the indents in my code, you may download my final version of the script to compare to your own. Please note that spacing and the number of spaces (meaning the indentation) in the code is critical. If you have the wrong number of spaces on the left side of your code, then the script will not run.

Tattoos Picture Page 1 Tattoos Picture Page 2 Tattoos Picture Page 3 Tattoos Picture Page 4 Tattoos Picture Page 5 Tattoos Picture Page 6 Tattoos Picture Page 7 Tattoos Picture Page 8 Tattoos Picture Page 9 Tattoos Picture Page 10 Tattoos Picture Page 11 Tattoos Picture Page 12 Tattoos Picture Page 13 Tattoos Picture Page 14 Tattoos Picture Page 15 Tattoos Picture Page 16 Tattoos Picture Page 17 Tattoos Picture Page 18 Tattoos Picture Page 19 Tattoos Picture Page 20 Tattoos Picture Page 21 Tattoos Picture Page 22 Tattoos Picture Page 23 Tattoos Picture Page 24 Tattoos Picture Page 25 Tattoos Picture Page 26 Tattoos Picture Page 27 Tattoos Picture Page 28 Tattoos Picture Page 29 Tattoos Picture Page 30 Tattoos Picture Page 31 Tattoos Picture Page 32 Tattoos Picture Page 33 Tattoos Picture Page 34 Tattoos Picture Page 35 Tattoos Picture Page 36 Tattoos Picture Page 37 Tattoos Picture Page 38 Tattoos Picture Page 39 Tattoos Picture Page 40 Tattoos Picture Page 41 Tattoos Picture Page 42 Tattoos Picture Page 43 Tattoos Picture Page 44 Tattoos Picture Page 45 Tattoos Picture Page 46 Tattoos Picture Page 47 Tattoos Picture Page 48 Tattoos Picture Page 49 Tattoos Picture Page 50 Tattoos Picture Page 51 Tattoos Picture Page 52 Tattoos Picture Page 53 Tattoos Picture Page 54 Tattoos Picture Page 55 Tattoos Picture Page 56 Tattoos Picture Page 57 Tattoos Picture Page 58 Tattoos Picture Page 59 Tattoos Picture Page 60 Tattoos Picture Page 61 Tattoos Picture Page 62 Tattoos Picture Page 63 Tattoos Picture Page 64 Tattoos Picture Page 65 Tattoos Picture Page 66 Tattoos Picture Page 67 Tattoos Picture Page 68 Tattoos Picture Page 69 Tattoos Picture Page 70 Tattoos Picture Page 71 Tattoos Picture Page 72 Tattoos Picture Page 73 Tattoos Picture Page 74 Tattoos Picture Page 75 Tattoos Picture Page 76 Tattoos Picture Page 77 Tattoos Picture Page 78 Tattoos Picture Page 79 Tattoos Picture Page 80 Tattoos Picture Page 81 Tattoos Picture Page 82 Tattoos Picture Page 83 Tattoos Picture Page 84 Tattoos Picture Page 85 Tattoos Picture Page 86 Tattoos Picture Page 87 Tattoos Picture Page 88 Tattoos Picture Page 89 Tattoos Picture Page 90 Tattoos Picture Page 91 Tattoos Picture Page 92 Tattoos Picture Page 93 Tattoos Picture Page 94 Tattoos Picture Page 95 Tattoos Picture Page 96 Tattoos Picture Page 97 Tattoos Picture Page 98 Tattoos Picture Page 99 Tattoos Picture Page 100 Tattoos Picture Page 101 Tattoos Picture Page 102 Tattoos Picture Page 103 Tattoos Picture Page 104 Tattoos Picture Page 105 Tattoos Picture Page 106 Tattoos Picture Page 107 Tattoos Picture Page 108 Tattoos Picture Page 109 Tattoos Picture Page 110 Tattoos Picture Page 111 Tattoos Picture Page 112 Tattoos Picture Page 113 Tattoos Picture Page 114 Tattoos Picture Page 115 Tattoos Picture Page 116 Tattoos Picture Page 117 Tattoos Picture Page 118 Tattoos Picture Page 119 Tattoos Picture Page 120
Luxury Villa and Home Page 1 Luxury Villa and Home Page 2 Luxury Villa and Home Page 3 Luxury Villa and Home Page 4 Luxury Villa and Home Page 5 Luxury Villa and Home Page 6 Luxury Villa and Home Page 7 Luxury Villa and Home Page 8 Luxury Villa and Home Page 9 Luxury Villa and Home Page 10 Luxury Villa and Home Page 11 Luxury Villa and Home Page 12 Luxury Villa and Home Page 13 Luxury Villa and Home Page 14 Luxury Villa and Home Page 15 Luxury Villa and Home Page 16 Luxury Villa and Home Page 17 Luxury Villa and Home Page 18 Luxury Villa and Home Page 19 Luxury Villa and Home Page 20 Luxury Villa and Home Page 21 Luxury Villa and Home Page 22 Luxury Villa and Home Page 23 Luxury Villa and Home Page 24 Luxury Villa and Home Page 25 Luxury Villa and Home Page 26 Luxury Villa and Home Page 27 Luxury Villa and Home Page 28 Luxury Villa and Home Page 29 Luxury Villa and Home Page 30 Luxury Villa and Home Page 31 Luxury Villa and Home Page 32 Luxury Villa and Home Page 33 Luxury Villa and Home Page 34 Luxury Villa and Home Page 35 Luxury Villa and Home Page 36 Luxury Villa and Home Page 37 Luxury Villa and Home Page 38 Luxury Villa and Home Page 39 Luxury Villa and Home Page 40 Luxury Villa and Home Page 41 Luxury Villa and Home Page 42 Luxury Villa and Home Page 43 Luxury Villa and Home Page 44 Luxury Villa and Home Page 45 Luxury Villa and Home Page 46 Luxury Villa and Home Page 47 Luxury Villa and Home Page 48 Luxury Villa and Home Page 49 Luxury Villa and Home Page 50 Luxury Villa and Home Page 51 Luxury Villa and Home Page 52 Luxury Villa and Home Page 53 Luxury Villa and Home Page 54 Luxury Villa and Home Page 55 Luxury Villa and Home Page 56 Luxury Villa and Home Page 57 Luxury Villa and Home Page 58 Luxury Villa and Home Page 59 Luxury Villa and Home Page 60 Luxury Villa and Home Page 61 Luxury Villa and Home Page 62 Luxury Villa and Home Page 63 Luxury Villa and Home Page 64 Luxury Villa and Home Page 65 Luxury Villa and Home Page 66 Luxury Villa and Home Page 67 Luxury Villa and Home Page 68 Luxury Villa and Home Page 69 Luxury Villa and Home Page 70 Luxury Villa and Home Page 71 Luxury Villa and Home Page 72 Luxury Villa and Home Page 73 Luxury Villa and Home Page 74 Luxury Villa and Home Page 75 Luxury Villa and Home Page 76 Luxury Villa and Home Page 77 Luxury Villa and Home Page 78 Luxury Villa and Home Page 79 Luxury Villa and Home Page 80 Luxury Villa and Home Page 81 Luxury Villa and Home Page 82 Luxury Villa and Home Page 83 Luxury Villa and Home Page 84 Luxury Villa and Home Page 85 Luxury Villa and Home Page 86 Luxury Villa and Home Page 87 Luxury Villa and Home Page 88 Luxury Villa and Home Page 89 Luxury Villa and Home Page 90 Luxury Villa and Home Page 91 Luxury Villa and Home Page 92 Luxury Villa and Home Page 93 Luxury Villa and Home Page 94 Luxury Villa and Home Page 95 Luxury Villa and Home Page 96 Luxury Villa and Home Page 97 Luxury Villa and Home Page 98 Luxury Villa and Home Page 99
Famous People Page 1 Famous People Page 2 Famous People Page 3 Famous People Page 4 Famous People Page 5 Famous People Page 6 Famous People Page 7 Famous People Page 8 Famous People Page 9 Famous People Page 10 Famous People Page 11 Famous People Page 12 Famous People Page 13 Famous People Page 14 Famous People Page 15 Famous People Page 16 Famous People Page 17 Famous People Page 18 Famous People Page 19 Famous People Page 20 Famous People Page 21 Famous People Page 22 Famous People Page 23 Famous People Page 24 Famous People Page 25 Famous People Page 26 Famous People Page 27 Famous People Page 28 Famous People Page 29 Famous People Page 30 Famous People Page 31 Famous People Page 32 Famous People Page 33 Famous People Page 34 Famous People Page 35 Famous People Page 36 Famous People Page 37 Famous People Page 38 Famous People Page 39 Famous People Page 40 Famous People Page 41 Famous People Page 42 Famous People Page 43 Famous People Page 44 Famous People Page 45 Famous People Page 46 Famous People Page 47 Famous People Page 48 Famous People Page 49 Famous People Page 50 Famous People Page 51 Famous People Page 52 Famous People Page 53 Famous People Page 54 Famous People Page 55 Famous People Page 56 Famous People Page 57 Famous People Page 58 Famous People Page 59 Famous People Page 60 Famous People Page 61 Famous People Page 62 Famous People Page 63 Famous People Page 64 Famous People Page 65 Famous People Page 66 Famous People Page 67 Famous People Page 68 Famous People Page 69 Famous People Page 70 Famous People Page 71 Famous People Page 72 Famous People Page 73 Famous People Page 74 Famous People Page 75 Famous People Page 76 Famous People Page 77 Famous People Page 78 Famous People Page 79 Famous People Page 80 Famous People Page 81 Famous People Page 82 Famous People Page 83 Famous People Page 84 Famous People Page 85 Famous People Page 86 Famous People Page 87 Famous People Page 88 Famous People Page 89 Famous People Page 90 Famous People Page 91 Famous People Page 92 Famous People Page 93 Famous People Page 94 Famous People Page 95 Famous People Page 96 Famous People Page 97 Famous People Page 98 Famous People Page 99 Famous People Page 100 Famous People Page 101 Famous People Page 102 Famous People Page 103 Famous People Page 104 Famous People Page 105 Famous People Page 106 Famous People Page 107 Famous People Page 108 Famous People Page 109 Famous People Page 110 Famous People Page 111 Famous People Page 112 Famous People Page 113 Famous People Page 114 Famous People Page 115 Famous People Page 116 Famous People Page 117 Famous People Page 118 Famous People Page 119 Famous People Page 120