[GastForen Programmierung/Entwicklung AppleScript InDesignCSx - Textframes splitten

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

InDesignCSx - Textframes splitten

TMA
Beiträge gesamt: 404

4. Apr 2008, 14:44
Beitrag # 1 von 7
Bewertung:
(1705 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo zusammen,
Habe mehrere InDesignCS3-Dokumente.
In diesen sind mehrere Textboxen mit mehreren Zeilen an Text (Absätze) teilweise in verschiedenen Textgrößen pro Absatz.

Beispiel an einer textbox:
zeile 1 bla
zeile 2 fgjfghkfjghsdg
zeile 3 fgkjalfghja
...

Ich möchte nun die jeweilige Textbox aufsplitten, so das jeder Absatz in einer neuen Textbox steht.

Also bei einer Textbox mit 3 Absätzen möchte ich nachher 3 einzelne Textboxen haben mit jeweils einem Absatz drin. Das ganze natürlich Standgenau zur alten Textbox die es nachher nicht mehr geben soll.
Zudem sollen die neuen Bounds der Textboxen möglichst knapp beschnitten sein (fit to text oder so).

Wie mache ich das am besten oder hat jemand schon so ein code?
Ich meine die paragraphen auslesen ist kein Problem aber das es nachher Standgenau wieder aussehen soll. Da muss man bestimmt einiges mit den Bounds und der Schriftgröße berechnen, oder gehts einfacher?

Das ganze am besten lauffähig für CS2 und CS3.

Gruß und schönes Wochenende
TMA
X

InDesignCSx - Textframes splitten

Hans Haesler
  
Beiträge gesamt: 5826

4. Apr 2008, 20:55
Beitrag # 2 von 7
Beitrag ID: #422399
Bewertung:
(1704 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo TMA,

hier schon mal ein Script. Entwickelt unter CS2 und getestet mit drei einfachen Textrahmen, welche je fünf Absätze enthalten.
[edit: Das Beschränken auf die Auswahl habe ich nachträglich eingefügt.]
Code
tell document 1 of application "Adobe InDesign CS2" 
  activate
 
  try
    set allIDs to id of every item of selection ¬
      whose content type is text type
  on error
    display dialog "Es ist kein Textrahmen ausgewählt." buttons ¬
      "OK" default button 1 with icon 2
    error number -128
  end try
 
  repeat with i from 1 to count of allIDs
    set baseID to item i of allIDs
   
    set idList to {}
    set baseList to {}
   
    repeat 1 times
     
      tell text frame id baseID
        set nParas to count of paragraphs of parent story
        if nParas is 0 then exit repeat
      end tell
     
      repeat with k from 2 to nParas
        tell text frame id baseID
          tell parent story
            tell paragraph k
              set end of baseList to baseline of line 1
            end tell
          end tell
        end tell
       
        set newFrame to duplicate text frame id baseID
        set end of idList to id of newFrame
        tell newFrame
          tell parent story
            try
              delete (paragraphs (k + 1) thru -1)
            end try
            try
              delete (paragraphs 1 thru -2)
            end try
            if (count of characters) is greater than 1 then
              if contents of character -1 is return then
                delete character -1
              end if
            end if
          end tell
        end tell
      end repeat
     
      tell text frame id baseID
        set {y1, x1, y2, x2} to geometric bounds
        tell parent story
          try
            delete (paragraphs 2 thru -1)
          end try
          if contents of character -1 is return then
            delete character -1
          end if
          set y2 to (baseline of line -1) + 1
        end tell
        set geometric bounds to {y1, x1, y2, x2}
      end tell
     
      repeat with k from 1 to count of idList
        set curID to item k of idList
        tell text frame id curID
          set {y1, x1, y2, x2} to geometric bounds
          tell parent story
            set yDiff to (item k of baseList) - (baseline of line 1)
            set y2 to (baseline of line -1) + 1
          end tell
          set geometric bounds to {y1, x1, y2, x2}
        end tell
        move text frame id curID by {0, yDiff}
      end repeat
     
    end repeat
  end repeat
end tell

In dieser ersten Version ist nur ein Minimum an Fehlervorbeugung eingebaut. Es gibt bestimmt noch weitere Fallstricke vorauszusehen (z.B. Rahmen mit Übersatz, bei welchem die erste Zeile eines Absatzes nicht sichtbar ist).

Gruss, Hans


als Antwort auf: [#422398]

InDesignCSx - Textframes splitten

TMA
Beiträge gesamt: 404

7. Apr 2008, 05:39
Beitrag # 3 von 7
Beitrag ID: #422400
Bewertung:
(1704 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Hans,
schon mal besten Dank für das Script. Werde es gleich mal testen und schauen wie es so arbeitet.
Beschränkung auf eine Auswahl brauche ich nicht. Es soll vollautomatisch als Droplet dienen und eine Menge Dokumente bearbeiten. Dabei handelt es sich um einfache Dokumente. Visitenkarten, Briefbögen etc..
Deswegen gibt es fast keine Fallstricke. Ist alles recht einfach aufgebaut.

Danke und Gruß
TMA


als Antwort auf: [#422398]

InDesignCSx - Textframes splitten

TMA
Beiträge gesamt: 404

8. Apr 2008, 12:55
Beitrag # 4 von 7
Beitrag ID: #422401
Bewertung:
(1704 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Hans,
habs mal getestet. Unter CS2 läufts super. Bei CS3 kommt folgende Fehlermeldung:

Can't make «class pBas» of line 1 of «class strp» of «class txtf» id 571 of document 1 of application "Adobe InDesign CS3" into type number.

Und zwar zeigt er mir den Befehl "baseline" in dieser Zeile an (letzte repeat-Schleife):
Code
set yDiff to (item k of baseList) - (baseline of line 1) 


Im Log-Fenster hört er bei dieser Zeile auf:
get baseline of line 1 of parent story of text frame id 571 of document 1

Ich weis noch nicht warum er das nicht kann.

Gruß
TMA


als Antwort auf: [#422398]

InDesignCSx - Textframes splitten

Hans Haesler
  
Beiträge gesamt: 5826

8. Apr 2008, 14:27
Beitrag # 5 von 7
Beitrag ID: #422402
Bewertung:
(1704 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo TMA,

danke für die Rückmeldung. Wie gesagt, habe ich das Script nur mit CS2 getestet.

Ich werde im Laufe des Abends einen Versuch mit CS3 machen.

Gruss, Hans


als Antwort auf: [#422398]

InDesignCSx - Textframes splitten

Hans Haesler
  
Beiträge gesamt: 5826

8. Apr 2008, 19:04
Beitrag # 6 von 7
Beitrag ID: #422403
Bewertung:
(1704 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo TMA,

ich kann Deine Beobachtung bestätigen. Aber bei meinem ersten Versuch hatte ich zuvor eine andere Fehlermeldung: Weil nur ein Rahmen ausgewählt, war das Ergebnis der ID-Nummern eine Ganzzahl (anstelle der erwarteten Liste). Abhilfe: Die class testen und – falls notwendig – das Ergebnis in eine Liste umwandeln:
---
if class of allIDs is not list then set allIDs to {allIDs}
---

Dein gemeldetes Problem beim Feststellen der Position der Grundlinie zeigt, dass  CS3 offensichtlich wählerischer ist als CS2, wenn gleichzeitig eine mathematische Aktion verlangt wird. Abhilfe bringt entweder ein explizites get ...
---
set yDiff to (item k of baseList) - (get baseline of line 1)
---
... oder ein vorheriges Speichern des Wertes:
---
set topBaseLine to baseline of line 1
set yDiff to (item k of baseList) - topBaseLine
---

Hier das modifizierte Script, welches sowohl mit CS2 als auch mit CS3 funktionieren sollte:
Code
tell document 1 of application "Adobe InDesign CS3" 
  activate
 
  try
    set allIDs to id of every item of selection ¬
      whose content type is text type
    if class of allIDs is not list then set allIDs to {allIDs}
  on error
    display dialog "Es ist kein Textrahmen ausgewählt." buttons ¬
      "OK" default button 1 with icon 2
    error number -128
  end try
 
  repeat with i from 1 to count of allIDs
    set baseID to item i of allIDs
   
    set idList to {}
    set baseList to {}
   
    repeat 1 times
     
      tell text frame id baseID
        set nParas to count of paragraphs of parent story
        if nParas is 0 then exit repeat
      end tell
     
      repeat with k from 2 to nParas
        tell text frame id baseID
          tell parent story
            tell paragraph k
              set end of baseList to baseline of line 1
            end tell
          end tell
        end tell
       
        set newFrame to duplicate text frame id baseID
        set end of idList to id of newFrame
        tell newFrame
          tell parent story
            try
              delete (paragraphs (k + 1) thru -1)
            end try
            try
              delete (paragraphs 1 thru -2)
            end try
            if (count of characters) is greater than 1 then
              if contents of character -1 is return then
                delete character -1
              end if
            end if
          end tell
        end tell
      end repeat
     
      tell text frame id baseID
        set {y1, x1, y2, x2} to geometric bounds
        tell parent story
          try
            delete (paragraphs 2 thru -1)
          end try
          if contents of character -1 is return then
            delete character -1
          end if
          set y2 to (baseline of line -1) + 1
        end tell
        set geometric bounds to {y1, x1, y2, x2}
      end tell
     
      repeat with k from 1 to count of idList
        set curID to item k of idList
        tell text frame id curID
          set {y1, x1, y2, x2} to geometric bounds
          tell parent story
            set yDiff to (item k of baseList) - (get baseline of line 1)
            set y2 to (baseline of line -1) + 1
          end tell
          set geometric bounds to {y1, x1, y2, x2}
        end tell
        move text frame id curID by {0, yDiff}
      end repeat
     
    end repeat
  end repeat
end tell

Gruss, Hans


als Antwort auf: [#422398]

InDesignCSx - Textframes splitten

TMA
Beiträge gesamt: 404

9. Apr 2008, 06:47
Beitrag # 7 von 7
Beitrag ID: #422404
Bewertung:
(1704 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo Hans,
kleiner Befehl, grosse Wirkung. Mit "get baseline" läufts wunderbar.

Nochmals besten Dank für deine Bemühungen und Gruß
TMA


als Antwort auf: [#422398]
X