Donations Welcome

I am currently saving toward a new version of Paint Shop Pro. If you wish to help me out, then please donate.

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.

Saturday, August 2, 2008

Checking Program Version in Scripts

One of the problems with scripts is that Paint Shop Pro is not completely backwards compatible.  Between PSP X and X1, Corel changed the names of brushes, gradients and preset shapes.  Therefore, a script which works in X1 and X2 may not work correctly in 9 and X.  It is possible to have the script check for the program version and then switch between the old name for a brush, gradient or preset shape and the new name using an if statement.  The GetVersionInfo command returns the following keys: BuildType, MinorVersion, MajorVersion, MicroVersion, BuildNumber, VersionString and Program.

The following code snippet will provide the version of the program and place it in the variable 'version'.

   VersionInfo = App.Do(Environment, 'GetVersionInfo')
   version = VersionInfo['MajorVersion']

Insert the snippet after Do(Environment) at the beginning of the script.

def Do(Environment):

The variable 'version' can then be used to set variables for use in the script.  For example, to switch between custom brushes.

   if version == 9:
      brush = u'Marble2'
   elif version == 10:
      brush = u'Marble2'
   elif version == 11:
      brush = u'Corel_01_029'
   else:
      brush = u'Corel_01_029'

Then, replace the CustomBrush string in the brush command with the 'brush' variable.

    # PaintBrush
    App.Do( Environment, 'PaintBrush', {
            'BrushTip': {
                'Shape': App.Constants.BrushShape.Custom, 
                'CustomBrush': brush, 
                'Size': 500, 
                'Hardness': 100, 
                'Step': 32, 
                'Density': 100, 
                'Thickness': 100, 
                'Rotation': 0, 
                'BrushVariance': {
                    'SizeVariance': App.Constants.VarianceMethod.Pressure, 
                    'SizeJitter': 0, 
                    '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': 0, 
                    'ColorBlendVariance': App.Constants.VarianceMethod.None, 
                    'ColorBlendJitter': 0, 
                    'HueVariance': App.Constants.VarianceMethod.None, 
                    'HueJitter': 0, 
                    'SaturationVariance': App.Constants.VarianceMethod.None, 
                    'SaturationJitter': 0, 
                    'LightnessVariance': App.Constants.VarianceMethod.None, 
                    'LightnessJitter': 0, 
                    'PositionJitter': 0, 
                    'UseScaledPositionJitter': False, 
                    'ImpressionsPerStep': 1, 
                    'FadeRate': 100
                    }
                }, 
            'Brush': {
                'Opacity': 87, 
                'ContinuousPaint': True, 
                'WetLookPaint': True, 
                'BlendMode': App.Constants.BlendMode.Multiply
                }, 
            'PrimaryMaterial': App.Constants.MaterialRef.Foreground, 
            'ForegroundMaterial': {
                'Color': (128,128,128), 
                'Pattern': None, 
                'Gradient': None, 
                'Texture': None, 
                'Art': None
                },
            'BackgroundMaterial': {
                'Color': (128,128,128), 
                'Pattern': None, 
                'Gradient': None, 
                'Texture': None, 
                'Art': None
                }, 
            'Stroke': [
                (App.Constants.PathEntryInterpretation.Absolute,(880.5,1680.5),0),
                (App.Constants.PathEntryInterpretation.Absolute,(880.5,1680.5),188)
            ], 
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'RandomSeed': 77296609, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((12,0,1),1)
                }
            })

No comments:

Post a Comment