Apply random colour from swatch group to letters individually

Benutzeravatar
shijan
Mitglied
Beiträge: 2012
Registriert: Mo 23 Dez 2019 15:21
Wohnort: Ukraine

Apply random colour from swatch group to letters individually

Beitrag von shijan »

Moved discussion about this script from betaforum.
On other forum i find a script for Illustrator that allow to apply random colour from swatch group to letters individually. So i asked maybe same script could be somehow adjusted for PhotoLine as well. Here is reply from Martin Huber
Martin Huber hat geschrieben: Mi 17 Jun 2026 17:42
shijan hat geschrieben: Mo 15 Jun 2026 16:42 As for colored letters (Apply random colour from swatch group to letters individually), on other forum i find a script for Illustrator that can do this. So maybe same script could be somehow adjusted for PhotoLine as well?
This is an AppleScript that colorizes each letter:

Code: Alles auswählen

tell application "PhotoLine"
	try
		set doc to front document
	on error
		set doc to missing value
	end try
	if doc is not missing value then
		set activeLayer to active layer of doc
		# Is there an active layer and the active layer is a text layer?
		if (activeLayer is not missing value) and (type of activeLayer is LTText) then
			# RGB colors that will be randomly set.
			# Each value in the list is a list of RGB values in the range of 0 to 1
			set colorList to {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}
			# iterate over the complete text inside the text layer
			# textRange[0]: start index of text, textRange[1]: number of characters
			set textRange to text range of activeLayer
			set actIndex to textRange's item 1
			set endIndex to actIndex + (textRange's item 2)
			repeat until actIndex ≥ endIndex
				# set randomIndex to (random number from 1 to (count colorList))
				set text attribute "Color" of activeLayer in range {actIndex, 1} to (some item of colorList)
				set actIndex to actIndex + 1
			end repeat
		else
			alert title "Note" message "The active layer has to be a text layer." first button "OK"
		end if
	end if
end tell
And this is a PowerShell script doing the same:

Code: Alles auswählen

$pl = New-Object -ComObject PhotoLine.Application -Strict
$pl.Visible = $True
$doc = $pl.ActiveDocument
                            # Is there a document?
if ($null -ne $doc)
{
    $activeLayer = $doc.ActiveLayer
    # Is there an active layer and the active layer is a text layer?
    if (($null -ne $activeLayer) -and ($activeLayer.Type -eq 4))
    {
        # RGB colors that will be randomly set
        $colors = @(@(1, 0, 0),#red
                    @(0, 1, 0),#green
                    @(0, 0, 1)#blue
                    )
 	    # iterate over the complete text inside the text layer
	    # $textRange[0]: start index of text, $textRange[1]: number of characters
        $textRange = $activeLayer.TextRange
        $actIndex = $textRange[0]
        $endIndex = $textRange[0] + $textRange[1]
        for ($actIndex = $textRange[0]; $actIndex -lt $endIndex; $actIndex++)
        {
            $randomIndex = Get-Random -Minimum 0 -Maximum $colors.Count
            $activeLayer.SetAttribute(@($actIndex, 1), "Color", $colors[$randomIndex])
        }
    }
    else
    {
        $pl.Alert("Attention", "The active layer has to be a text layer!", "OK")
    }
}
This script only reads RGB values from set colorList. It is possible somehow read automatically colors from specific Color palette, if simply enter palette name?
Screen Shot 2026-06-17 at 8.53.57 PM.jpg
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.
PhotoLine UI Icons Customization Project: https://www.pl32.com/forum3/viewtopic.php?f=3&t=6302