Code:
Dim fso, datei,Namen()
Dim appref,quellbild,zielbild,strtRulerUnits, strtTypeUnits
Dim dpi,anzseiten, anz, Spalten, karte_y, karte_x,zaehler,Rand,dateipfad
Dim speichern, Speicherpfad, schliessen, Schnittlinie
'****Eingaben*******
dpi = 300 'DPI für Zieldatei
Rand=50 'Oberer Rand in Pixel
dateipfad="namen.txt" 'Dateipfad zur Textdatei mit den Namen
Schnittlinie="j" 'Schnittlinien hinzufügen? "j" oder "n"
speichern="j" 'speichern der erstellten Dateien? "j" oder "n"
Speicherpfad="c:\" 'Speicherpfad für erstellte Dateien
schliessen="n" 'Erstellte Dateien schliessen? "j"oder "n"
'*******************
Set appref = CreateObject("Photoshop.Application")
strtRulerUnits = appRef.Preferences.RulerUnits
strtTypeUnits = appRef.Preferences.TypeUnits
appRef.Preferences.RulerUnits = 1
appRef.Preferences.TypeUnits = 1
NamenEinlesen
Set strokecolor = CreateObject("Photoshop.SolidColor")
With strokecolor
.CMYK.Cyan = 0
.CMYK.Magenta = 0
.CMYK.Yellow = 0
.CMYK.Black = 100
End With
If appref.Documents.Count=0 Then
MsgBox "Erst eine Datei öffnen! Danach Script erneut ausführen."
WScript.Quit
End If
Set quellbild = appRef.ActiveDocument
neuesblatt
multi = quellbild.Height / quellbild.Width
karte_x = quellbild.Width
karte_y = quellbild.Height
If karte_x > 21 / 2.54 * dpi OR karte_y * 2 > 29.7 / 2.54 * dpi Then
MsgBox "Die Karte ist zu groß für A4!"
WScript.quit
End If
deltx = 0
delty = Rand
erstes = True
Spalten = 21 / 2.54 * dpi \ (karte_x - 1)
For i = 0 To zaehler
appref.ActiveDocument = quellbild
quellbild.ArtLayers(1).TextItem.Contents = Namen(i)
quellbild.Selection.SelectAll
quellbild.Selection.Copy True
appref.ActiveDocument = zielbild
Select Case Spalten
Case 2
zielbild.Selection.Select Array( _
Array(zielbild.Width / 2 - karte_x + deltx, delty), _
Array(zielbild.Width / 2 + deltx, delty), _
Array(zielbild.Width / 2 + deltx, karte_y + delty), _
Array(zielbild.Width / 2 - karte_x + deltx, karte_y + delty))
Case 1
zielbild.Selection.Select Array( _
Array(zielbild.Width / 2 - karte_x / 2 + deltx, delty), _
Array(zielbild.Width / 2 + karte_x / 2 + deltx, delty), _
Array(zielbild.Width / 2 + karte_x / 2 + deltx, karte_y + delty), _
Array(zielbild.Width / 2 - karte_x / 2 + deltx, karte_y + delty))
Case Else
zielbild.Selection.Select Array( _
Array(zielbild.Width / 2 - karte_x * Spalten / 2 + deltx, delty), _
Array(zielbild.Width / 2 - karte_x * (Spalten - 2) / 2 + deltx, delty), _
Array(zielbild.Width / 2 - karte_x * (Spalten - 2) / 2 + deltx, karte_y + delty), _
Array(zielbild.Width / 2 - karte_x * Spalten / 2 + deltx, karte_y + delty))
End Select
If Schnittlinie="j" Then zielbild.Selection.Stroke strokecolor,1, 3
delty = delty + karte_y
zielbild.Paste
zielbild.ArtLayers(1).Merge
If delty + karte_y > zielbild.Height AND deltx + 2 * karte_x > zielbild.Width AND i<>zaehler Then
If speichern="j" Then
zielbild.saveas Speicherpfad & zielbild.name
If schliessen="j" Then zielbild.close
End If
neuesblatt
deltx = 0
delty = Rand
Else
If delty + karte_y > zielbild.Height Then
delty = Rand
deltx = karte_x + deltx
End If
End If
Next
If speichern="j" Then
zielbild.saveas Speicherpfad & zielbild.name
If schliessen="j" Then zielbild.close
End If
appref.Preferences.RulerUnits = strtRulerUnits
appref.Preferences.TypeUnits = strtTypeUnits
Sub neuesblatt()
anzseiten = anzseiten + 1
Set zielbild = appref.Documents.Add(21 / 2.54 * dpi, 29.7 / 2.54 * dpi, dpi, "Tischkarten Seite " & anzseiten & ".psd")
End Sub
Sub NamenEinlesen()
zaehler=0
anzseiten=0
Set fso = CreateObject("Scripting.FileSystemObject")
Set datei = fso.opentextfile(dateipfad,1)
Do While Not datei.AtEndOfStream
Redim Preserve Namen(zaehler)
Namen(zaehler)=datei.readline
zaehler=zaehler+1
Loop
zaehler=zaehler-1
datei.close
End Sub
Im Anhang nochmal die vbs- und eine Bsp.Datei