Connect failed: Connection timed out

[GastForen Programmierung/Entwicklung AppleScript pdf Auszüge in Indesign platzieren

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Themen
Beiträge
Moderatoren
Letzter Beitrag

pdf Auszüge in Indesign platzieren

jekyll
Beiträge gesamt: 2047

8. Dez 2017, 13:01
Beitrag # 16 von 23
Beitrag ID: #561327
Bewertung:
(5052 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Hans,
Antwort auf: Also: Hoffentlich kommt mir jemand zuvor ... ;-).

Ich.
Hab´s doch geschafft.

Danke trotzdem!!


als Antwort auf: [#561201]
X

pdf Auszüge in Indesign platzieren

Hans Haesler
  
Beiträge gesamt: 5826

8. Dez 2017, 13:32
Beitrag # 17 von 23
Beitrag ID: #561330
Bewertung:
(5047 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Sándor,

gut, dass Du es geschafft hast.

Ich hatte es auch versucht, musste dann aber wegen eines Auftrags-Scripts abbrechen.

Heute, gegen Ende Vormittag, habe ich mich nochmals dahinter gesetzt.
Aber jetzt ist es ja nicht mehr notwendig.

Gruss, Hans


als Antwort auf: [#561327]

pdf Auszüge in Indesign platzieren

Hans Haesler
  
Beiträge gesamt: 5826

10. Dez 2017, 11:53
Beitrag # 18 von 23
Beitrag ID: #561367
Bewertung:
(4858 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Sándor,

ich habe jetzt doch meine Version fertiggestellt. Weil ich vielleicht so etwas mal brauchen könnte.

Das Script setzt voraus (ohne es zu prüfen), dass alle PDF-Dokumente dieselbe Seitengrösse und Orientierung aufweisen.

Zum Herausfinden der Abmessungen wird zu Beginn ein temporärer Bildrahmen erzeugt und die erste Seite der ersten PDF-Datei geladen. Dann wird der Rahmen an den Inhalt angepasst und aus den 'geometric bounds' die Breite und die Höhe errechnet. Diese Methode ist präziser als das Umrechnen der in der Datei gespeicherten Pixelwerte.

Code
set filmBreite to 455 
set filmHoehe to 560
set randOben to 1
set randLinks to 1
set abstand to 1
set ctr to 0

set pdfFolder to choose folder
tell application "Finder"
set pdfDoks to every file of pdfFolder whose name ends with ".pdf"
end tell

set firstDok to (item 1 of pdfDoks as alias)

tell application "Adobe InDesign CC 2017"
set page number of PDF place preferences to 1
set indd to make new document
tell indd
tell document preferences
set properties to {facing pages:false, page width:filmBreite, page height:filmHoehe}
end tell
tell page 1
set tmpRect to make rectangle with properties {geometric bounds:{200, 150, 300, 250}}
end tell
set stroke color of tmpRect to item 1 of swatches
place firstDok on tmpRect
fit tmpRect given frame to content
set {y1, x1, y2, x2} to geometric bounds of tmpRect
set dokHoehe to y2 - y1
set dokBreite to x2 - x1
delete tmpRect
end tell
end tell

set form to check(filmBreite, filmHoehe, randLinks, randOben, dokBreite, dokHoehe, abstand)
set {qBr, qHoe, qErg} to {item 1 of form, item 2 of form, item 3 of form}

set y1 to randOben
set x1 to randLinks
set y2 to randOben + dokHoehe
set x2 to randLinks + dokBreite
set posList to {}

repeat with h from 1 to qHoe
repeat with b from 1 to qBr
set end of posList to {y1, x1, y2, x2}
set x1 to x2 + abstand
set x2 to x1 + dokBreite
end repeat
set y1 to y2 + abstand
set y2 to y1 + dokHoehe
set x1 to randLinks
set x2 to x1 + dokBreite
end repeat

tell application "Adobe InDesign CC 2017"
activate
set aktInddSeite to 1
repeat with n in pdfDoks
set pdfSeitenZahl to (do shell script "/usr/bin/mdls " & quoted form of POSIX path of (n as alias) ¬
& " | /usr/bin/awk '/kMDItemNumberOfPages/{print $3}'") as integer

repeat with p from 1 to pdfSeitenZahl
set page number of PDF place preferences to p
set ctr to ctr + 1
set curPos to item ctr of posList

tell indd
set reEck to make rectangle at page aktInddSeite with properties {geometric bounds:curPos}
set stroke color of reEck to item 1 of swatches
place alias (n as string) on reEck

if p is less than pdfSeitenZahl then
if ctr mod qErg is 0 then
make new page at end
set aktInddSeite to aktInddSeite + 1
set ctr to 0
end if
end if

end tell
end repeat
end repeat

tell window 1
set active page to page 1 of indd
end tell

display dialog "Fertig." buttons "OK" default button 1 with icon 1 giving up after 1
end tell

on check(filmBreite, filmHoehe, randLinks, randOben, dokBreite, dokHoehe, abstand)
set dokBreite to (dokBreite - randLinks) + abstand
set dokHoehe to (dokHoehe - randOben) + abstand
set qBr to round (filmBreite / dokBreite) rounding down
if qBr is less than 1 then
display dialog "Die Film-Breite ist zu gering." buttons "OK" default button 1 with icon 0
error number -128
end if
set qHoe to round (filmHoehe / dokHoehe) rounding down
if qHoe is less than 1 then
display dialog "Die Film-Höhe ist zu gering." buttons "OK" default button 1 with icon 0
error number -128
end if
set qErg to qBr * qHoe
return {qBr, qHoe, qErg}
end check

Wenn die PDF-Dateien unterschiedliche Seitengrössen und/oder Orientierungen haben (wie jene fünf in Deinem Testordner) ist es kaum möglich, die Seiten schön geordnet zu laden. Okay, man könnte für jede neue PDF-Datei eine neue Seite einfügen.

Mein Vorschlag: Für jede PDF-Datei eine separate InDesign-Datei erzeugen. Der Code dazu im nächsten Beitrag.

Gruss, Hans


als Antwort auf: [#561327]

pdf Auszüge in Indesign platzieren

Hans Haesler
  
Beiträge gesamt: 5826

10. Dez 2017, 11:54
Beitrag # 19 von 23
Beitrag ID: #561368
Bewertung:
(4857 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Und hier der Code, welcher für jede PDF-Datei ein eigenes InDesign-Dokument erzeugt.

Code
set filmBreite to 455 
set filmHoehe to 560
set randOben to 1
set randLinks to 1
set abstand to 1

set pdfFolder to choose folder
tell application "Finder"
set pdfDoks to every file of pdfFolder whose name ends with ".pdf"
set ordPfad to pdfFolder as Unicode text
end tell

tell application "Adobe InDesign CC 2017"
activate

repeat with n in pdfDoks
set aktInddSeite to 1
set pdfSeitenZahl to (do shell script "/usr/bin/mdls " & quoted form of POSIX path of (n as alias) ¬
& " | /usr/bin/awk '/kMDItemNumberOfPages/{print $3}'") as integer

set page number of PDF place preferences to 1
set indd to make new document
tell indd
tell document preferences
set properties to {facing pages:false, page width:filmBreite, page height:filmHoehe}
end tell
tell page 1
set tmpRect to make rectangle with properties {geometric bounds:{200, 150, 300, 250}}
end tell
set stroke color of tmpRect to item 1 of swatches
place alias (n as string) on tmpRect
fit tmpRect given frame to content
set {y1, x1, y2, x2} to geometric bounds of tmpRect
set dokHoehe to y2 - y1
set dokBreite to x2 - x1
delete tmpRect
end tell

set form to my check(filmBreite, filmHoehe, randLinks, randOben, dokBreite, dokHoehe, abstand)
set {qBr, qHoe, qErg} to {item 1 of form, item 2 of form, item 3 of form}

set y1 to randOben
set x1 to randLinks
set y2 to randOben + dokHoehe
set x2 to randLinks + dokBreite
set posList to {}
set ctr to 0

repeat with h from 1 to qHoe
repeat with b from 1 to qBr
set end of posList to {y1, x1, y2, x2}
set x1 to x2 + abstand
set x2 to x1 + dokBreite
end repeat
set y1 to y2 + abstand
set y2 to y1 + dokHoehe
set x1 to randLinks
set x2 to x1 + dokBreite
end repeat

repeat with p from 1 to pdfSeitenZahl
set page number of PDF place preferences to p
set ctr to ctr + 1
set curPos to item ctr of posList

tell indd
set reEck to make rectangle at page aktInddSeite with properties {geometric bounds:curPos}
set stroke color of reEck to item 1 of swatches
place alias (n as string) on reEck

if p is less than pdfSeitenZahl then
if ctr mod qErg is 0 then
make new page at end
set aktInddSeite to aktInddSeite + 1
set ctr to 0
end if
end if

end tell
end repeat

set dokName to my getName(n)
set dokPfad to ordPfad & dokName & ".indd"
save indd to dokPfad
close indd

end repeat

display dialog "Fertig." buttons "OK" default button 1 with icon 1 giving up after 1
end tell

on check(filmBreite, filmHoehe, randLinks, randOben, dokBreite, dokHoehe, abstand)
set dokBreite to (dokBreite - randLinks) + abstand
set dokHoehe to (dokHoehe - randOben) + abstand
set qBr to round (filmBreite / dokBreite) rounding down
if qBr is less than 1 then
display dialog "Die Film-Breite ist zu gering." buttons "OK" default button 1 with icon 0
error number -128
end if
set qHoe to round (filmHoehe / dokHoehe) rounding down
if qHoe is less than 1 then
display dialog "Die Film-Höhe ist zu gering." buttons "OK" default button 1 with icon 0
error number -128
end if
set qErg to qBr * qHoe
return {qBr, qHoe, qErg}
end check

on getName(n)
tell application "Finder"
set dokName to text 1 thru -5 of (get name of file (n as string))
return dokName
end tell
end getName

Gruss, Hans


als Antwort auf: [#561367]

pdf Auszüge in Indesign platzieren

jekyll
Beiträge gesamt: 2047

10. Dez 2017, 14:08
Beitrag # 20 von 23
Beitrag ID: #561370
Bewertung:
(4825 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Hans,

hier ist meine. der machst mit meine pdfs doch erstaunlich gut ;)
Habe auch noch eine tiff mit hinzu gefügt :) leider ist der tiff Shell langsamer als das von pdf.

Code
property filmBreite : 455 
property filmHoehe : 560
property abstand : 3
set mm to 2.835

set ordner to choose folder
tell application "Finder"
set pdfDoks to every file of ordner whose name ends with ".pdf"
set tifDoks to every file of ordner whose name ends with ".tif"
set doks to pdfDoks & tifDoks
end tell

tell application "Adobe InDesign CC 2017"
set indd to make new document
tell indd to tell document preferences to set properties to {facing pages:false, page width:filmBreite, page height:filmHoehe}
end tell
set {x1, y1, x2, y2, z, aktInddSeiten} to {1, 1, 1, 1, 1, 1}
repeat with n in doks
if ".pdf" is (items -1 thru -4 of (n as string)) as text then
set pdfSeitenZahl to (do shell script "/usr/bin/mdls " & quoted form of POSIX path of (n as alias) & " | /usr/bin/awk '/kMDItemNumberOfPages/{print $3}'") as integer
set userLocale to user locale of (get system info)
set {dokHoehe, dokBreite} to words of (do shell script "mdls -name kMDItemPageHeight -name kMDItemPageWidth -raw '" & POSIX path of (n as alias) & "'| LC_NUMERIC=" & userLocale & " xargs -0 -I _pt awk 'BEGIN {printf \"%.1f \",_pt/(72/25.385)}'")
{dokHoehe as real, dokBreite as real}
repeat with i from 1 to pdfSeitenZahl
tell application "Adobe InDesign CC 2017" to set page number of PDF place preferences to i
set {x1, y1, x2, y2, aktInddSeiten} to my check(z, n, i, x1, y1, x2, y2, aktInddSeiten, dokBreite, dokHoehe)
end repeat
else
set {dokBreitePx, dokHoehePx} to words of (do shell script "sips -g pixelHeight -g pixelWidth " & quoted form of POSIX path of (n as alias) & " | awk '/pixel/ {print $NF}'")
set reso to words of (do shell script "sips -g dpiHeight " & quoted form of POSIX path of (n as alias) & " | awk '/dpi/ {printf \"%.0f \", $NF}'")
set resoMM to (reso as real) / 25.4
set {dokHoehe, dokBreite} to {dokBreitePx / resoMM, dokHoehePx / resoMM}
set {x1, y1, x2, y2, aktInddSeiten} to my check(z, n, i, x1, y1, x2, y2, aktInddSeiten, dokBreite, dokHoehe)
end if
set z to z + 1
end repeat

on check(z, n, i, x1, y1, x2, y2, aktInddSeiten, dokBreite, dokHoehe)
set altSeiten to aktInddSeiten
if filmBreite is greater than dokBreite and filmHoehe is greater than dokHoehe then
if z is 1 and i is 1 then
set x1 to 1
set y1 to 1
set x2 to x1 + dokBreite
set y2 to y1 + dokHoehe
set aktInddSeiten to 1
else
if filmBreite is greater than (x2 + abstand + dokBreite) then
if i is 1 then
if filmHoehe is greater than (y2 + abstand + dokHoehe) then
set x1 to x2 + abstand
set x2 to x1 + dokBreite
set y1 to y2 - dokHoehe
set y2 to y1 + dokHoehe
else
set x1 to 1
set y1 to 1
set x2 to x1 + dokBreite
set y2 to y1 + dokHoehe
set aktInddSeiten to aktInddSeiten + 1
end if
else
set x1 to x2 + abstand
set x2 to x1 + dokBreite
end if
else if filmHoehe is greater than (y2 + abstand + dokHoehe) then
set x1 to 1
set x2 to x1 + dokBreite
set y1 to y2 + abstand
set y2 to y1 + dokHoehe
else if (y2 + abstand + dokHoehe) is greater than filmHoehe then
set x1 to 1
set y1 to 1
set x2 to x1 + dokBreite
set y2 to y1 + dokHoehe
set aktInddSeiten to aktInddSeiten + 1
end if
end if
tell application "Adobe InDesign CC 2017"
tell active document
if altSeiten is less than aktInddSeiten then
tell document preferences to set properties to {pages per document:aktInddSeiten}
end if
set reEck to make rectangle at page aktInddSeiten with properties {geometric bounds:{y1, x1, y2, x2}}
set stroke color of reEck to item 1 of swatches
place alias (n as string) on reEck
end tell
end tell
end if
return {x1, y1, x2, y2, aktInddSeiten}
end check



als Antwort auf: [#561368]
(Dieser Beitrag wurde von jekyll am 10. Dez 2017, 14:09 geändert)

pdf Auszüge in Indesign platzieren

Hans Haesler
  
Beiträge gesamt: 5826

10. Dez 2017, 21:52
Beitrag # 21 von 23
Beitrag ID: #561372
Bewertung:
(4745 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Sándor,

Antwort auf: (...) der machst mit meine pdfs doch erstaunlich gut ;)

Stimmt! Viel Respekt!

Antwort auf: (...) leider ist der tiff Shell langsamer als das von pdf

Ein Grund mehr, zum Erfahren der Abmessungen nicht 'do shell script' einzusetzen.
Sondern die Lösung, welche in meinen beiden Scripts verwendet wird.

Abgesehen davon: Eine TIFF-Datei verursacht beim Aufruf des 'check'-Handlers
eine Fehlermeldung weil die Variable i nicht definiert ist.

Gruss, Hans


als Antwort auf: [#561370]

pdf Auszüge in Indesign platzieren

jekyll
Beiträge gesamt: 2047

10. Dez 2017, 23:02
Beitrag # 22 von 23
Beitrag ID: #561373
Bewertung:
(4726 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Hans,
Antwort auf: Viel Respekt!

Danke.

Antwort auf: Sondern die Lösung, welche in meinen beiden Scripts verwendet wird.

Nun ich war darauf fixiert die reinkommenden Daten an den korrekten Stelle zu platzieren.
Hab´s von Dir :)

Ich denke eher darüber nach zuerst von alle Dateien die Maße und Menge in einem Händler raus zu finden um die dann möglichst den Film ausfüllend zu platzieren.
Habe gedanklich schon eine Vorstellung wie ich das angehen sollte. Als erste die grössten Daten aufm Bogen "zu legen" dann mit den kleineren "auf füllen".
Ich höre aber gerne andere Lösungsvorschläge an ;)

Antwort auf: Eine TIFF-Datei verursacht beim Aufruf des 'check'-Handlers
eine Fehlermeldung weil die Variable i nicht definiert ist.

Du hast aber recht.
In meine tests gins gut, weil ich pdfs zusammen mit tif getestet habe, hätte ich die tifs als erste abgearbeitet wäre es mir aufgefallen.
Danke.


als Antwort auf: [#561372]

pdf Auszüge in Indesign platzieren

Hans Haesler
  
Beiträge gesamt: 5826

11. Dez 2017, 11:00
Beitrag # 23 von 23
Beitrag ID: #561376
Bewertung:
(4611 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Sándor,

Zitat Hab´s von Dir :)

Ja, das war am Anfang. Aber später habe ich versucht, präzisere Abmessungen zu bekommen.

Doch auch mit einem erweiterten Wert ...

Code
set mm to 2.834645669291 

... kam nicht das heraus, was man beim Anpassen des Rahmens an den Inhalt bekommt.

Deshalb die Idee, die erste Seite in einen temporären Bildrahmen zu laden und die Breizte und Höhe so festzustellen.
So kann man auf 'do shell script' und das anschliessende Umrechnen verzichten.

Zitat Ich höre aber gerne andere Lösungsvorschläge an ;)

Nun, ich stand schon mehr als einmal vor einer ähnlichen Aufgabe. Aber ohne eine Lösung zu finden.
Deshalb überlasse ich Dir gerne den Vortritt. Du hast ja ein gewisses Talent für solche Sachen :-)

Gruss, Hans


als Antwort auf: [#561373]
X