[英]move layer in Photoshop with python win32com.client
我一直在使用移動圖層功能,在 python 中編寫 photoshop 腳本。 層最終在其他層集內部而不是在它們之后,等等。
在 Photoshop 的 Javascript 中執行此操作的本機命令是:
layer.move(relativeObject, insertionLocation)
其中 insertionLocation 可以是:
ElementPlacement.INSIDE、ElementPlacement.PLACEATBEGINNING、ElementPlacement.PLACEATEND、ElementPlacement.PLACEBEFORE 或 ElementPlacement.PLACEAFTER
我當前的代碼如下所示:
@staticmethod
def moveLayer(layer, relativeLayer = None, placement = 3):
if placement == PHAPS.ElementPlacementPLACEATEND:
layers = PHAPS.app().ActiveDocument.layers
relativeLayer = layers[len(layers) - 1]
placement = PHAPS.ElementPlacementPLACEAFTER
elif placement == PHAPS.ElementPlacementPLACEATBEGINNING:
relativeLayer = PHAPS.app().ActiveDocument.layers[0]
placement = PHAPS.ElementPlacementPLACEBEFORE
layer.Move(relativeLayer, placement)
這是我對常量值的猜測,這顯然是錯誤的:
ElementPlacementPLACEATBEGINNING = 1
ElementPlacementINSIDE = 2
ElementPlacementPLACEBEFORE = 3
ElementPlacementPLACEAFTER = 4
ElementPlacementPLACEATEND = 5
我已經嘗試對這些常量的原始值進行跟蹤,但 Photoshop 可以很好地隱藏它們。 我也嘗試過 Action Manager 代碼,但我發現它有點難以理解。
有誰知道使用 python 在 photoshop 中移動圖層的可靠方法? 首選 Action Manager 代碼,但不是必需的。
您好,您可以使用這些方法代替 .Move()
def MoveAfter(self, RelativeObject=defaultNamedNotOptArg):
'Move the PageItem in behind object'
return self._oleobj_.InvokeTypes(1299596641, LCID, 1, (24, 0), ((9, 1),),RelativeObject
)
def MoveBefore(self, RelativeObject=defaultNamedNotOptArg):
'Move the PageItem in front of object'
return self._oleobj_.InvokeTypes(1299596642, LCID, 1, (24, 0), ((9, 1),),RelativeObject
)
def MoveToBeginning(self, Container=defaultNamedNotOptArg):
'Move the PageItem to beginning of container'
return self._oleobj_.InvokeTypes(1299596646, LCID, 1, (24, 0), ((9, 1),),Container
)
def MoveToEnd(self, Container=defaultNamedNotOptArg):
'Move the PageItem to end of container'
return self._oleobj_.InvokeTypes(1299596645, LCID, 1, (24, 0), ((9, 1),),Container
在哪里:
例子
from win32com.client import Dispatch
app = Dispatch("Photoshop.Application")
doc = app.Open(r"hereTheProjectPath.psd")
layerRefA = doc.ArtLayers.Add()
layerRefA.MoveToEnd(doc)
layerRefB = doc.ArtLayers.Add()
layerRefB.MoveAfter(layerRefA)
您可以在這里找到所有這些常量值https://github.com/lohriialo/photoshop-scripting-python/blob/master/api_reference/photoshop_2020.py#L243
psPlaceInside =0 # from enum PsElementPlacement
psPlaceAtBeginning =1 # from enum PsElementPlacement
psPlaceAtEnd =2 # from enum PsElementPlacement
psPlaceBefore =3 # from enum PsElementPlacement
psPlaceAfter =4 # from enum PsElementPlacement
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.