loonghao / photoshop-python-api

Python API for Photoshop.
https://loonghao.github.io/photoshop-python-api/
MIT License
643 stars 74 forks source link

"deleteAndFillSelection" #363

Open MichaelB82 opened 1 month ago

MichaelB82 commented 1 month ago

I want to write same function for "deleteAndFillSelection" -- can anybody help me ?

def content_aware_fill(ps, doc, left, top, right, bottom, hull_points):

Deselect any current selections

doc.selection.deselect()

# Define the selection area
if hull_points is not None:
    doc.selection.select(hull_points)
else:
    left, top, right, bottom = int(left), int(top), int(right), int(bottom)
    selection_points = ((left, top), (right, top), (right, bottom), (left, bottom))
    doc.selection.select(selection_points)

# Perform Content-Aware Fill
desc12 = ps.ActionDescriptor()

# Fill method using content-aware
idFl = ps.app.charIDToTypeID("Fl  ")
idUsng = ps.app.charIDToTypeID("Usng")
idFlCn = ps.app.charIDToTypeID("FlCn")
idcontentAware = ps.app.stringIDToTypeID("contentAware")
desc12.putEnumerated(idUsng, idFlCn, idcontentAware)

# Set opacity to 100%
idOpct = ps.app.charIDToTypeID("Opct")
idPrc = ps.app.charIDToTypeID("#Prc")
desc12.putUnitDouble(idOpct, idPrc, 100.0)

# Set blending mode to Normal
idMd = ps.app.charIDToTypeID("Md  ")
idBlnM = ps.app.charIDToTypeID("BlnM")
idNrml = ps.app.charIDToTypeID("Nrml")
desc12.putEnumerated(idMd, idBlnM, idNrml)

# Execute the action
ps.app.executeAction(idFl, desc12, ps.DialogModes.DisplayNoDialogs)

# Deselect after filling
doc.selection.deselect()