The method used to allow a user to choose two colors for a paintbrush can also be used for any of the other brushes in Paint Shop Pro. This tutorial is an expansion of the
Script Customization Tutorial for Paintbrush, Airbrush and Pen Tool. It is a good idea to be familiar with that tutorial before attempting this tutorial.
1. For this tutorial, I am going to use my
Multi-colored Tinsel Tutorial as the example because it is short. So, first, perform the steps in that tutorial, except set the foreground and background materials to a color so that editting of the scripts will be easy. My script looks like this:
from JascApp import *
def ScriptProperties():
return {
'Author': u'Spencer Aloysius',
'Copyright': u'Humbug Graphics Galore',
'Description': u'Creates tinsel when used with metallic glitter patterns.',
'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': 300,
'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)
}
})
# PaintBrush
App.Do( Environment, 'PaintBrush', {
'BrushTip': {
'Shape': App.Constants.BrushShape.Rectangular,
'CustomBrush': None,
'Size': 200,
'Hardness': 25,
'Step': 30,
'Density': 100,
'Thickness': 5,
'Rotation': 60,
'BrushVariance': {
'SizeVariance': App.Constants.VarianceMethod.None,
'SizeJitter': 8,
'OpacityVariance': App.Constants.VarianceMethod.None,
'OpacityJitter': 0,
'DensityVariance': App.Constants.VarianceMethod.None,
'DensityJitter': 0,
'ThicknessVariance': App.Constants.VarianceMethod.None,
'ThicknessJitter': 0,
'RotationVariance': App.Constants.VarianceMethod.None,
'RotationJitter': 100,
'ColorBlendVariance': App.Constants.VarianceMethod.None,
'ColorBlendJitter': 49,
'HueVariance': App.Constants.VarianceMethod.None,
'HueJitter': 0,
'SaturationVariance': App.Constants.VarianceMethod.None,
'SaturationJitter': 0,
'LightnessVariance': App.Constants.VarianceMethod.None,
'LightnessJitter': 0,
'PositionJitter': 23,
'UseScaledPositionJitter': False,
'ImpressionsPerStep': 1,
'FadeRate': 100
}
},
'Brush': {
'Opacity': 100,
'ContinuousPaint': False,
'WetLookPaint': False,
'BlendMode': App.Constants.BlendMode.Normal
},
'PrimaryMaterial': App.Constants.MaterialRef.Foreground,
'ForegroundMaterial': {
'Color': (192,192,255),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'BackgroundMaterial': {
'Color': (0,0,0),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'Stroke': [
(App.Constants.PathEntryInterpretation.Absolute,(87.5,133.5),0)
],
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'RandomSeed': 76538406,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
# PaintBrush
App.Do( Environment, 'PaintBrush', {
'BrushTip': {
'Shape': App.Constants.BrushShape.Rectangular,
'CustomBrush': None,
'Size': 200,
'Hardness': 25,
'Step': 30,
'Density': 100,
'Thickness': 5,
'Rotation': 60,
'BrushVariance': {
'SizeVariance': App.Constants.VarianceMethod.None,
'SizeJitter': 8,
'OpacityVariance': App.Constants.VarianceMethod.None,
'OpacityJitter': 0,
'DensityVariance': App.Constants.VarianceMethod.None,
'DensityJitter': 0,
'ThicknessVariance': App.Constants.VarianceMethod.None,
'ThicknessJitter': 0,
'RotationVariance': App.Constants.VarianceMethod.None,
'RotationJitter': 100,
'ColorBlendVariance': App.Constants.VarianceMethod.None,
'ColorBlendJitter': 49,
'HueVariance': App.Constants.VarianceMethod.None,
'HueJitter': 0,
'SaturationVariance': App.Constants.VarianceMethod.None,
'SaturationJitter': 0,
'LightnessVariance': App.Constants.VarianceMethod.None,
'LightnessJitter': 0,
'PositionJitter': 23,
'UseScaledPositionJitter': False,
'ImpressionsPerStep': 1,
'FadeRate': 100
}
},
'Brush': {
'Opacity': 100,
'ContinuousPaint': False,
'WetLookPaint': False,
'BlendMode': App.Constants.BlendMode.Normal
},
'PrimaryMaterial': App.Constants.MaterialRef.Foreground,
'ForegroundMaterial': {
'Color': (192,192,255),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'BackgroundMaterial': {
'Color': (0,0,0),
'Pattern': None,
'Gradient': None,
'Texture': None,
'Art': None
},
'Stroke': [
(App.Constants.PathEntryInterpretation.Absolute,(87.5,133.5),0),
(App.Constants.PathEntryInterpretation.Absolute,(3537.5,141.5),0)
],
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'RandomSeed': 76546953,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
2. Before the Paintbrush command, add the code snippet to ask the user to choose a color twice like so:
# MsgBox
Result = App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Info,
'Text': 'Choose a color, pattern or gradient.',
})
MyFill = App.Do(Environment,'GetMaterial',{
'IsPrimary':App.Constants.Boolean.true,
'GeneralSettings': {
'ExecutionMode':App.Constants.ExecutionMode.Interactive
}
})
# MsgBox
Result = App.Do( Environment, 'MsgBox', {
'Buttons': App.Constants.MsgButtons.OK,
'Icon': App.Constants.MsgIcons.Info,
'Text': 'Choose a color, pattern or gradient.',
})
MyFill2 = App.Do(Environment,'GetMaterial',{
'IsPrimary':App.Constants.Boolean.false,
'GeneralSettings': {
'ExecutionMode':App.Constants.ExecutionMode.Interactive
}
})
This sets a color, pattern or gradient for the foreground and the background in the Materials palette.
3. Now, edit the Paintbrush command to accept both choices made by the user by changing the ForegroundMaterial to MyFill and the BackgroundMaterial to MyFill2.
# PaintBrush
App.Do( Environment, 'PaintBrush', {
'BrushTip': {
'Shape': App.Constants.BrushShape.Rectangular,
'CustomBrush': None,
'Size': 200,
'Hardness': 25,
'Step': 30,
'Density': 100,
'Thickness': 5,
'Rotation': 60,
'BrushVariance': {
'SizeVariance': App.Constants.VarianceMethod.None,
'SizeJitter': 8,
'OpacityVariance': App.Constants.VarianceMethod.None,
'OpacityJitter': 0,
'DensityVariance': App.Constants.VarianceMethod.None,
'DensityJitter': 0,
'ThicknessVariance': App.Constants.VarianceMethod.None,
'ThicknessJitter': 0,
'RotationVariance': App.Constants.VarianceMethod.None,
'RotationJitter': 100,
'ColorBlendVariance': App.Constants.VarianceMethod.None,
'ColorBlendJitter': 49,
'HueVariance': App.Constants.VarianceMethod.None,
'HueJitter': 0,
'SaturationVariance': App.Constants.VarianceMethod.None,
'SaturationJitter': 0,
'LightnessVariance': App.Constants.VarianceMethod.None,
'LightnessJitter': 0,
'PositionJitter': 23,
'UseScaledPositionJitter': False,
'ImpressionsPerStep': 1,
'FadeRate': 100
}
},
'Brush': {
'Opacity': 100,
'ContinuousPaint': False,
'WetLookPaint': False,
'BlendMode': App.Constants.BlendMode.Normal
},
'PrimaryMaterial': App.Constants.MaterialRef.Foreground,
'ForegroundMaterial': MyFill,
'BackgroundMaterial': MyFill2,
'Stroke': [
(App.Constants.PathEntryInterpretation.Absolute,(87.5,133.5),0)
],
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'RandomSeed': 76538406,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((9,0,1),1)
}
})
Every Paintbrush command in the script needs to be editted. In this case, that means changing the ForegroundMaterial and BackgroundMaterial twice.
Now the script will allow the user to pick two colors for the paintbrush. I have provided
my copy of the script so that you can compare your result to mine.