【问题标题】:Add text contents to Photoshop layer via the comtypes library通过 comtypes 库将文本内容添加到 Photoshop 图层
【发布时间】:2019-08-02 23:02:32
【问题描述】:

我想在 psd 文件中添加一个文本层。我能够添加一个图层,但我不知道如何编写内容或在该图层中定位内容。 谁能告诉我?

我导入了 win32com,这就是我现在得到的。

import win32com.client

psApp = win32com.client.Dispatch("Photoshop.Application")

psApp.Open('file path')         # Opens a PSD file
doc = psApp.Application.ActiveDocument  # Get active document object

layers = doc.ArtLayers
newTextLayer = layers.add # add a layer
newTextLayer.kind = 2 # specify a text layer

newTextLayer.name = 'new' # name the layer

newTextLayer = 'text content' # this line is what I am struggling with.


doc.save
doc.close

编辑:我使用的是 python 3.6。和 Photoshop CC。

【问题讨论】:

    标签: python-3.x photoshop win32com


    【解决方案1】:

    我建议您使用 Markdown(或内部编辑器)格式化您的代码,以便其他读者更清楚地帮助您。见this link

    newTextLayer 基本上是从主要的TextItem 对象继承而来。这就是为什么要解决您的问题,您需要这样做:

    import win32com.client
    
    psApp = win32com.client.Dispatch("Photoshop.Application")
    
    psApp.Open('file path') # Opens a PSD file
    doc = psApp.Application.ActiveDocument # Get active document object
    
    layers = doc.ArtLayers
    newTextLayer = layers.add # add a layer
    
    newTextLayer.kind = 2 # specify a text layer
    newTextLayer.name = 'new' # name the layer
    
    newTextLayer.TextItem.Contents = 'text content'
    doc.save
    doc.close
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-10
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 2023-03-09
      • 2014-12-09
      • 1970-01-01
      相关资源
      最近更新 更多