Use Foreground Color In ColorChanger

Moderator: Kathy_9

Pahrump
Posts: 2
Joined: Sat Jan 30, 2021 4:12 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Location: Pahrump NV

Use Foreground Color In ColorChanger

Post by Pahrump »

I am trying to write a script that:
opens an image that is essentially a monochromatic chip or sample
crops a rectangle from that image
resizes the canvas around the rectangle
pastes a saved image into the canvas
uses the eyedropper to set the foreground color to the color of the rectangle
changes the color of the pasted-in image to the color of the rectangle (foreground color set by the eyedropper)
saves and closes the image

The problem I am having is I don't know how to change the script that I have saved after going through these steps so that the color changer uses the color from the eyedropper. I need it to be variable. But all that happens is the color of the very first image used when I recorded the script is used again and again.

I assume that this line needs to be changed, but I don't know to what:

'Color': (220,224,16),

Here is the entire script:

from PSPApp import *

def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'',
'Host': u'PaintShop Pro',
'Host Version': u'23.00'
}

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

# Crop
App.Do( Environment, 'Crop', {
'CropRect': ((479,50), 197, 250),
'Mode': App.Constants.CropMode.Custom,
'Units': App.Constants.CropUnits.Inches,
'SelectedArea': False,
'PrintWidth': -1,
'PrintHeight': -1,
'CropAsNewImage': False,
'RotationAngle': -0,
'AutoFit': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((23,0,0),1)
}
})

# ResizeCanvas
App.Do( Environment, 'ResizeCanvas', {
'AspectRatio': 0.788,
'FillColor': (255,255,255),
'HoriPlace': App.Constants.HorizontalType.Custom,
'MaintainAspect': False,
'NewDimUnits': App.Constants.UnitsOfMeasure.Pixels,
'NewHeight': 800,
'NewWidth': 800,
'PlaceBottom': 275,
'PlaceLeft': 553,
'PlaceRight': 50,
'PlaceTop': 275,
'VertPlace': App.Constants.VerticalType.Center,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((23,0,0),1)
}
})

# PasteAsNewSelection
App.Do( Environment, 'PasteAsNewSelection', {
'Offset': (-129,30),
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((23,0,0),1)
}
})

# Eyedropper
App.Do( Environment, 'Eyedropper', {
'Point': (624.5,379.5),
'SampleSize': 0,
'Material': App.Constants.MaterialRef.Foreground,
'ActiveLayerOnly': False,
'SampleColor': 0,
'CopyStyleAndFill': False,
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((23,0,0),1)
}
})

# Color Changer
App.Do( Environment, 'ColorChanger', {
'Color': (220,224,16),
'Tolerance': 35,
'Antialias': 5,
'PointList': [(303.5,357.5)],
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Default,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((23,0,0),1)
}
})

# ColorChangerFixup
App.Do( Environment, 'ColorChangerFixup', {
'GeneralSettings': {
'ExecutionMode': App.Constants.ExecutionMode.Silent,
'AutoActionMode': App.Constants.AutoActionMode.Match,
'Version': ((23,0,0),1)
}
})

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

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

Thank you for any help
cosmicDread
Posts: 42
Joined: Fri Aug 26, 2016 7:10 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: MSI MPG Z390 Gaming PRO
processor: Intel Core i9-9900K
ram: 32 GB
Video Card: GeForce GTX 1080 Ti
Hard_Drive_Capacity: 6 TB
Monitor/Display Make & Model: Acer Predator X34
Corel programs: PaintShop X5, X6, X8, X9, '18, '19, '20
Location: Lake Havasu City, Arizona, USA

Re: Use Foreground Color In ColorChanger

Post by cosmicDread »

Pahrump,

From my experience, I've used the GetMaterial command to get the eyedropper color which is placed in the foreground color.

Code: Select all

    # Get color from Eyedropper which is in the foreground (IsPrimary: 1):
    material_dict = App.Do(Environment, 'GetMaterial', {
            'IsPrimary': 1,
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Silent,
                'AutoActionMode': App.Constants.AutoActionMode.Match,
                'Version': ((23,0,0),1)
            }
        })
    
    # The color is RGB:
    color = material_dict['Color']

    # Color Changer
    App.Do( Environment, 'ColorChanger', {
            'Color': color,
            'Tolerance': 35,
            'Antialias': 5,
            'PointList': [(303.5,357.5)],
            'GeneralSettings': {
            'ExecutionMode': App.Constants.ExecutionMode.Default,
            'AutoActionMode': App.Constants.AutoActionMode.Match,
            'Version': ((23,0,0),1)
        }
    })
Eyedropper to Color Changer.zip
:idea:
Charles
You do not have the required permissions to view the files attached to this post.
When the majority of the people on Earth are wanting the Galactic Federation to show themselves, then they will.
Pahrump
Posts: 2
Joined: Sat Jan 30, 2021 4:12 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
Location: Pahrump NV

Re: Use Foreground Color In ColorChanger

Post by Pahrump »

Thank you, that worked. I'd like to buy you a coffee if we can figure out how to communicate.
cosmicDread
Posts: 42
Joined: Fri Aug 26, 2016 7:10 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: MSI MPG Z390 Gaming PRO
processor: Intel Core i9-9900K
ram: 32 GB
Video Card: GeForce GTX 1080 Ti
Hard_Drive_Capacity: 6 TB
Monitor/Display Make & Model: Acer Predator X34
Corel programs: PaintShop X5, X6, X8, X9, '18, '19, '20
Location: Lake Havasu City, Arizona, USA

Re: Use Foreground Color In ColorChanger

Post by cosmicDread »

It was my pleasure. I'm glad it works.
When the majority of the people on Earth are wanting the Galactic Federation to show themselves, then they will.