DoOperation IPLLayer - how to trim based on transparency?

Benutzeravatar
Herbert123
Mitglied
Beiträge: 2452
Registriert: Sa 12 Mai 2012 21:38

DoOperation IPLLayer - how to trim based on transparency?

Beitrag von Herbert123 »

Where do we find a list of operations that can be fed into DoOperation?

The example script in PL's script folder includes this one, which I assume can be easily adapted to trim the transparency of selected layers rather than scale them:

If Not doc Is Nothing Then
ExecuteOperationWithSelectedLayers doc, "Scale"
End If

Sub ExecuteOperationWithSelectedLayers(doc, operation)
Dim layer
Dim selectedLayers

Set selectedLayers = doc.SelectedLayers
If selectedLayers.Count > 0 Then
' If there is only 1 selected layer, execute the operation directly
If selectedLayers.Count = 1 Then
selectedLayers(0).DoOperation operation, "ShowDialog", true
Else
Dim dialogSettings

Set dialogSettings = selectedLayers(0).ShowOperationDialog(operation)
For Each layer In selectedLayers
layer.DoOperation operation, dialogSettings
Next
End If
End If
End Sub

"Scale" is the keyword here to call the scale dialog. Which keyword should we use instead to call the Change Layer Size dialog? And prevent the dialog from being displayed and direct it to use the Crop Size option?
/*---------------------------------------------*/
System: Win10 64bit - i7 920@3.6Ghz, p6t Deluxe v1, 48gb (6x8gb RipjawsX), Nvidia GTX1080 8GB, Revodrive X2 240gb, e-mu 1820, 2XSamsung SA850 (2560*1440) and 1XHP2408H 1920*1200 portrait
Martin Huber
Entwickler
Entwickler
Beiträge: 4298
Registriert: Di 19 Nov 2002 15:49

Re: DoOperation IPLLayer - how to trim based on transparency?

Beitrag von Martin Huber »

Herbert123 hat geschrieben: So 19 Jul 2026 20:12 Where do we find a list of operations that can be fed into DoOperation?
In the scripting documentation in the chapter "Operations".

The easiest way to trim a layer based on its transparency is using selections. The operation "MakeSelection" creates a rectangular selection/lasso containing the visible parts of the layer. This has to be cropped afterwards.

Sadly, there is no "CropSelection". I will add that.

In the meantime, you can replace "CropSelection" with an embedded action: Record an action and right-click the complete action or a single action-step and choose "Copy Base64". You can use that Base64 string in your script.

I've done that in the following Powershell script that will trim all selected layers:

Code: Alles auswählen

$pl = New-Object -ComObject PhotoLine.Application -Strict
$pl.Visible = $True
$doc = $pl.ActiveDocument
                            # Is there a document?
if ($doc -ne $null)
{
    $selectedLayers = $doc.SelectedLayers
    foreach ($activeLayer in $selectedLayers)
    {
        $activeLayer.DoOperation("MakeSelection")
        #$activeLayer = $activeLayer.DoOperation("CropSelection")
        $actionString = "UGhvdG8gTGluZSBBY3Rpb25zAAAAAQAAAAABAP+bAAAAD0xhc3NvQ3V0QWN0aW9uAAMAAAAAAAAA" +
                        "ABICAQAAAAEAAAAEAAAAAf//////////"
        $activeLayer.DoOperation("Action", "Data", $actionString)
    }
}
Benutzeravatar
Herbert123
Mitglied
Beiträge: 2452
Registriert: Sa 12 Mai 2012 21:38

Re: DoOperation IPLLayer - how to trim based on transparency?

Beitrag von Herbert123 »

Thank you! Apologies for the late reply, but I am away on holidays.
/*---------------------------------------------*/
System: Win10 64bit - i7 920@3.6Ghz, p6t Deluxe v1, 48gb (6x8gb RipjawsX), Nvidia GTX1080 8GB, Revodrive X2 240gb, e-mu 1820, 2XSamsung SA850 (2560*1440) and 1XHP2408H 1920*1200 portrait