Bonsoir à tous

J'ai récupérer un script python permettant d'ouvrir Photoshop et d'effectuer des actions depuis Python
(lien :http://techarttiki.blogspot.fr/2008/...th-python.html)

Je l'ai adapté pour mes besoins.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
import win32com.client
import os
import sys
 
 
 
psApp = win32com.client.Dispatch('Photoshop.Application')
 
psdFile= "S:\\test\\CLEAN\\bg_000_02.psd"
jpgFile="S:\\test\\jpg_convert\\CLEAN\\bg_000_02.jpg"
 
options = win32com.client.Dispatch('Photoshop.ExportOptionsSaveForWeb')
options.Format = 1   # JPG
doc = psApp.Open(psdFile)
layerSets = doc.LayerSets
 
exportTypes = {'perso','cadre'}
if (len(layerSets) > 0):           
 
	for layerSet in layerSets:
		lsName = layerSet.name.lower()
 
		if (lsName in exportTypes):
			layerSet.Visible = False
 
 
	doc = psApp.Open(psdFile)
	doc.Export(ExportIn=jpgFile, ExportAs=2, Options=options)
	print 'exporting:'+ jpgFile
 
 
 
	doc.Close(2)
Cependant lorsque j'essaie de le transformer en fonction :
j'ai l'erreur suivante

[B]line 7 <module> psd_to_jpg
NameError:'name in 'psd_to_jpg' is not defined'[B]

je vois bien que le problème dépasse mes connaissances en programmation
Merci à vous


#code avec appel de fonction

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
import win32com.client
import os
import sys
 
 
psd_to_jpg()
 
def psd_to_jpg():
 
	psApp = win32com.client.Dispatch('Photoshop.Application')
 
	psdFile= "S:\\test\\CLEAN\\bg_000_02.psd"
	jpgFile="S:\\test\\jpg_convert\\CLEAN\\bg_000_02.jpg"
 
	options = win32com.client.Dispatch('Photoshop.ExportOptionsSaveForWeb')
	options.Format = 1   # JPG
	doc = psApp.Open(psdFile)
	layerSets = doc.LayerSets
 
	exportTypes = {'perso','cadre'}
 
	if (len(layerSets) > 0):
 
		# Loop through each LayerSet (aka Group)
		for layerSet in layerSets:
			lsName = layerSet.Name.lower()
 
			if (lsName in exportTypes):
				layerSet.Visible = False 
 
 
		doc = psApp.Open(psdFile)
		doc.Export(ExportIn=jpgFile, ExportAs=2, Options=options)
 
 
 
		doc.Close(2)
	return