使用python win32com.client在Photoshop中移动图层

使用python win32com.client在Photoshop中移动图层,python,python-3.x,photoshop,photoshop-script,Python,Python 3.x,Photoshop,Photoshop Script,我一直在使用移动层函数,用python编写photoshop脚本,玩得很开心。层结束于其他层集内部,而不是在它们之后,等等 在Photoshop的Javascript中执行此操作的本机命令是: layer.move(relativeObject, insertionLocation) 插入位置可以是: ElementPlacement.INSIDE、ElementPlacement.PlaceAtStart、ElementPlacement.PLACEATEND、ElementPlacemen

我一直在使用移动层函数,用python编写photoshop脚本,玩得很开心。层结束于其他层集内部,而不是在它们之后,等等

在Photoshop的Javascript中执行此操作的本机命令是:

layer.move(relativeObject, insertionLocation)
插入位置可以是:

ElementPlacement.INSIDE、ElementPlacement.PlaceAtStart、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中移动图层的可靠方法吗?首选操作管理器代码,但不是必需的。

您好,您可以使用这些方法代替.Move()

其中:

  • RelativeObject=是相对层引用
  • 容器=是存放层的文档
范例

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)

你可以在这里找到所有你想要的常量值

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)
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