2011-08-04 13 views
1

rb-appscriptを使用してPSDをPNG形式で書き出すスクリプトを作成しました。それは大丈夫だと思いますが、私はそれをpy-appscriptで取り除くことはできません。ここでpy-appscriptを使用してPSDをPNG形式でエクスポートするにはどうすればよいですか?

はRubyのコードです:

#!/usr/bin/env ruby 

require 'rubygems' 
require 'optparse' 
require 'appscript' 

ps = Appscript.app('Adobe Photoshop CS5.app') 
finder = Appscript.app("Finder.app") 

path = "/Users/nbaker/Desktop/" 
ps.activate 
ps.open(MacTypes::Alias.path("#{path}guy.psd")) 

layerSets = ps.current_document.layer_sets.get 

# iterate through all layers and hide them 
ps.current_document.layers.get.each do |layer| 
    layer.visible.set false 
end 

layerSets.each do |layerSet| 
    layerSet.visible.set false 
end 

# iterate through all layerSets, make them visible, and create a PNG for them 
layerSets.each do |layerSet| 
    name = layerSet.name.get 
    layerSet.visible.set true 
    ps.current_document.get.export(:in => "#{path}#{name}.png", :as => :save_for_web, 
          :with_options => {:web_format => :PNG, :png_eight => false}) 
    layerSet.visible.set false 
end 

そして、ここでは明らかに非等価なPythonコードです:

from appscript import * 
from mactypes import * 

# fire up photoshop 
ps = app("Adobe Photoshop CS5.app") 
ps.activate() 

# open the file for editing 
path = "/Users/nbaker/Desktop/" 
f = Alias(path + "guy.psd") 
ps.open(f) 

layerSets = ps.current_document.layer_sets() 

# iterate through all layers and hide them 
for layer in ps.current_document.layers(): 
    layer.visible.set(False) 

#... and layerSets 
for layerSet in layerSets: 
    layerSet.visible.set(False) 

# iterate through all layerSets, make them visible, and create a PNG for them 
for layerSet in layerSets: 
    name = layerSet.name() 
    layerSet.Visible = True 
    ps.current_document.get().export(in_=Alias(path + name + ".png"), as_=k.save_for_web, 
       with_options={"web_format":k.PNG, "png_eight":False}) 

動作しませんPythonスクリプトの一部だけが保存しています。

接続が無効...一般的なPhotoshopエラーが発生しました。この機能は、このバージョンのPhotoshopでは使用できない可能性があります...一部のデータを期待したタイプにすることはできません...

私はrubyスクリプトだけで暮らすことができますが、私たちの他のスクリプトはすべてPython、だから、これをPythonで手放すことができればいいと思う。事前にインターネットに感謝します。

答えて

1

バート、

私はあなたのためのソリューションを持っていると思う - 数ヶ月後にもかかわらず。私はPythonのnoobですので、これは決してエレガントではありません。

私はあなたのスクリプトを試してみましたが、それも私のためにクラッシュし続けました。しかし、輸出呼び出しで「エイリアス」を除去することで、それはOKのようです:

from appscript import * 
from mactypes import * 

# fire up photoshop 
ps = app("Adobe Photoshop CS5.1.app") 
ps.activate() 

# open the file for editing 
path = "/Users/ian/Desktop/" 
f = Alias(path + "Screen Shot 2011-10-13 at 11.48.51 AM.psd") 
ps.open(f) 

layerSets = ps.current_document.layer_sets() 

# no need to iterate 
ps.current_document.layers.visible.set(False) 
ps.current_document.layer_sets.visible.set(False) 

# iterate through all layerSets, make them visible, and create a PNG for them 
for l in layerSets: 
    name = l.name() 
    # print l.name() 
    l.visible.set(True) 
    # make its layers visible too 
    l.layers.visible.set(True) 
    # f = open(path + name + ".png", "w").close() 

    ps.current_document.get().export(in_=(path + name + ".png"), as_=k.save_for_web, 
       with_options={"web_format":k.PNG, "png_eight":False}) 

私はあなたが彼らの可視性を切り替えるには、すべての層を反復処理することを、あまりにも、気づきました。実際には一度にすべてのコマンドを発行することができます.Apple Eventsを発行し続ける必要がないので、私の理解はより速いということです。

私のスクリプトのロジックは正しくありません(レイヤーをオンまたはオフにすることに関して)が、そのアイデアを得ることができます。

イアン

関連する問題