2011-08-04 6 views
1

rb-appscript를 사용하여 PSD를 PNG로 내보내는 스크립트를 작성했습니다. 멋지다. 멋쟁이지만, 나는 애호가로 풀어 낼 수 없다.py-appscript를 사용하여 PSD를 PNG로 내보내려면 어떻게해야합니까?

다음은 루비 코드입니다 :

#!/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 

그리고 여기에 분명히 비등가 파이썬 코드입니다 :

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

작동하지 않습니다 파이썬 스크립트의 유일한 부분은 절약입니다. 다른 내보내기 옵션과 내용을 시도하는 데 여러 가지 오류가 발생했습니다.

연결이 잘못되었습니다 ... 일반 Photoshop 오류가 발생했습니다. 이 기능은이 버전의 포토샵에서 사용할 수 없습니다 ... 일부 데이터를 예상되는 유형으로 만들 수 없습니다 ...

저는 루비 스크립트만으로도 살 수 있지만 다른 모든 스크립트는 파이썬으로되어 있습니다. 그래서 파이썬에서 이것을 풀 수있는 것이 좋을 것입니다. 인터넷에 미리 감사드립니다. 나중에 몇 개월이라도 -

답변

1

버트,

는 나는 당신을위한 해결책을 가지고 생각합니다. 저는 파이썬 놈입니다. 그래서 이것은 결코 우아하지 않습니다.

스크립트를 사용해 보았을 때 계속 저 또한 충돌했습니다. 그러나 수출의 통화에서 "별칭"을 제거하여, 확인을 것 같다 :

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 이벤트를 계속 발행 할 필요가 없으므로 이해가 더 빠릅니다.

내 스크립트의 논리가 올바르지 않습니다 (레이어를 켜고 끄는 것과 관련하여). 그러나 아이디어를 얻습니다.

이안

관련 문제