[GastForen Programmierung/Entwicklung JavaScript Illustrator: Legacy Text

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

Illustrator: Legacy Text

funkturmmitte
Beiträge gesamt: 117

15. Aug 2019, 11:13
Beitrag # 1 von 6
Bewertung:
(4557 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo!
Vielleicht kann mir hier jemand weiterhelfen?
Ich hab keine Ahnung von Javascript mich davon aber nicht entmutigen lassen und versucht mit einem Script meinen Workflow zu verbessern.

Ziel des Script ist es alte Dateien für die Übersetzung vorzubereiten.

Dazu will ich:
• alle Ebenen entsperren
• alle Hilfslinien löschen
• alten Text aktualisieren (legacy Text)
• Absatzmarken entfernen und durch ein Leerzeichen ersetzen
• Auswahl zentrieren und zoomen

Ich habe einige andere Scripte genommen, zusammengesetzt und soweit klappt es (für meine Verhältnisse) auch ganz gut.
Es scheitert jedoch am alten Text.
Diesen Teil des Scriptes konnte ich bislang nicht so modifizieren, dass er das macht was ich will.

Vielleicht hat hier jemand eine Idee wie sich mein Vorhaben umsetzten lässt. Ich wäre für jeden Hinweis dankbar.

Hier ist der Code:
Code
/ 
// BAUSTELLE! Das aktualisieren von altem Text klappt noch nicht.
//
// Unlock all layers (and their sublayers)
processLayersRecursive(app.activeDocument.layers);

// Process all layers under variable "parent" (including sublayers on all levels).
function processLayersRecursive(parent){
for (var iLayer = 0; iLayer < parent.length; iLayer++){
var curLayer = parent[iLayer];
// Unlock the current layer
if (curLayer.locked){
curLayer.locked = false;
}
processLayersRecursive(curLayer.layers);
}
}
// Remove all guides
var doc = app.activeDocument;
for (var i = doc.pathItems.length-1; i >= 0; i--) {
var p = doc.pathItems[i];
if (p.guides == true) {
p.remove();
}
}
doc.selectObjectsOnActiveArtboard();
// ----------------------------------------------------------------------------- zweiter Teil
// script.name = legacyTextConvertToNative.jsx;
// script.description = converts Legacy Text to Native from all layers, except from 2 layers, hard codes below.
// script.required = 2 layers named the sames as the names shown below in skipLayer1 & 2
// script.parent = CarlosCanto // 7/23/11;
// script.elegant = false;

// var skipLayer1 = "Layer 3"; // replace with your own layer name
// var skipLayer2 = "Layer 1"; // replace with your own layer name

for (i=0; i<doc.layers.length; i++)
{
var ilayer = doc.layers[i];
// if (ilayer.name!=skipLayer1 && ilayer.name!=skipLayer2)
{
for (j=0; j<ilayer.groupItems.length; j++)
{
var igroup = ilayer.groupItems[j];
for (k=igroup.legacyTextItems.length-1; k>=0; k--)
{
var ilegacy = igroup.legacyTextItems[k];
ilegacy.convertToNative();
}
}
}
}
// ----------------------------------------------------------------------------- dritter Teil
// Absatzmarken entfernen
// https://forums.adobe.com/thread/2597426
var active_doc = app.activeDocument;
var search_string = /\r/g; // g for global search, remove i to make a case sensitive search
var replace_string = ' '; // pour "\n"
var text_frames = active_doc.textFrames;
var this_text_frame, this_text_frame;
if (text_frames.length > 0) {
for (var i = 0 ; i < text_frames.length; i++) {
this_text_frame = text_frames[i];
new_string = this_text_frame.contents.replace(search_string, replace_string);
this_text_frame.contents = new_string;
}
}
// ------------------------------------------------------------------------------ dritter Teil
/////////////////////////////////////////////////////////////////
//Zoom and Center to Selection v2. -- CS, CS2
//>=--------------------------------------
//
// Zooms active view to selected object(s).
//
// New in v.2:
// If nothing is selected; sets view to 100% at current location.
//
// Simple but REALLY cool!
//
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////

if ( documents.length > 0)
{
if(activeDocument.selection.length >0){
mySelection = activeDocument.selection;
//if object is a (collection of) object(s) not a text field.
if (mySelection instanceof Array) {
//initialize vars
initBounds = mySelection[0].visibleBounds;
ul_x = initBounds[0];
ul_y = initBounds[1];
lr_x = initBounds[2];
lr_y = initBounds[3];
//check rest of group if any
for (i=1; i<mySelection.length; i++) {
groupBounds = mySelection[i].visibleBounds;
if (groupBounds[0]<ul_x){ul_x=groupBounds[0]}
if (groupBounds[1]>ul_y){ul_y=groupBounds[1]}
if (groupBounds[2]>lr_x){lr_x=groupBounds[2]}
if (groupBounds[3]<lr_y){lr_y=groupBounds[3]}
}


}

//get x,y/x,y Matrix for 100% view

activeDocument.views[0].zoom = 1;
ScreenSize = activeDocument.views[0].bounds;
ScreenWidth= ScreenSize[2] - ScreenSize[0];
ScreenHeight=ScreenSize[1] - ScreenSize[3];
screenProportion =ScreenHeight/ScreenWidth;

//Determine upperLeft position of object(s)
cntrPos = [ul_x,ul_y];

//mySelection[0].position;
//cntrPos[0] += (mySelection[0].width /2);
//cntrPos[1] -= (mySelection[0].height /2);
//offset by half width and height
mySelWidth=(lr_x-ul_x);
mySelHeight=(ul_y-lr_y);
cntrPos[0] = ul_x + (mySelWidth/2);
cntrPos[1] = ul_y - (mySelHeight/2);
//alert("ul point is "+cntrPos);
//center to screen to the object
activeDocument.views[0].centerPoint = cntrPos;
//alert("objWidth="+mySelection[0].width+", actualWidth="+ActualWidth);
//alert("objHeight="+mySelection[0].height+", actualHeight="+ActualHeight);

//set zoom for height and width
zoomFactorW = ScreenWidth/mySelWidth;
zoomFactorH = ScreenHeight/mySelHeight;
//alert("zoomFactorW = "+zoomFactorW+"\r zoomFactorH = "+zoomFactorH);

//decide which proportion is larger...
if((mySelWidth*screenProportion) >= mySelHeight){
zF = zoomFactorW;
//alert("zoomFactorW = "+zoomFactorW);
}else{
zF = zoomFactorH;
//alert("zoomFactorH = "+zoomFactorH);
}

//and scale to that proportion minus a little bit.
activeDocument.views[0].zoom = zF *.85;

}else{
//alert("Please select an object on the page.");
activeDocument.activeView.zoom=1;
}
}


Gruß
Oliver
X

Illustrator: Legacy Text

funkturmmitte
Beiträge gesamt: 117

19. Aug 2019, 15:34
Beitrag # 2 von 6
Beitrag ID: #571502
Bewertung:
(4476 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Die Lösung war einfacher als gedacht und bestand aus einer Zeile Code.

Code
// Unlock all layers (and their sublayers)   
processLayersRecursive(app.activeDocument.layers);

// Process all layers under variable "parent" (including sublayers on all levels).
function processLayersRecursive(parent){
for (var iLayer = 0; iLayer < parent.length; iLayer++){
var curLayer = parent[iLayer];
// Unlock the current layer
if (curLayer.locked){
curLayer.locked = false;
}
processLayersRecursive(curLayer.layers);
}
}
// Remove all guides
var doc = app.activeDocument;
for (var i = doc.pathItems.length-1; i >= 0; i--) {
var p = doc.pathItems[i];
if (p.guides == true) {
p.remove();
}
}
doc.selectObjectsOnActiveArtboard();
// ---------------------------------------------------------------------------- zweiter Teil
// alten Text aktualisieren
doc.legacyTextItems.convertToNative();
// ----------------------------------------------------------------------------- dritter Teil
// Absatzmarken entfernen
var active_doc = app.activeDocument;
var search_string = /\r/g; // g for global search, remove i to make a case sensitive search
var replace_string = ' '; // pour "\n"
var text_frames = active_doc.textFrames;
var this_text_frame, this_text_frame;
if (text_frames.length > 0) {
for (var i = 0 ; i < text_frames.length; i++) {
this_text_frame = text_frames[i];
new_string = this_text_frame.contents.replace(search_string, replace_string);
this_text_frame.contents = new_string;
}
}
// ------------------------------------------------------------------------------ dritter Teil
/////////////////////////////////////////////////////////////////
//Zoom and Center to Selection v2. -- CS, CS2
//>=--------------------------------------
//
// Zooms active view to selected object(s).
//
// New in v.2:
// If nothing is selected; sets view to 100% at current location.
//
// Simple but REALLY cool!
//
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////

if ( documents.length > 0)
{
if(activeDocument.selection.length >0){
mySelection = activeDocument.selection;
//if object is a (collection of) object(s) not a text field.
if (mySelection instanceof Array) {
//initialize vars
initBounds = mySelection[0].visibleBounds;
ul_x = initBounds[0];
ul_y = initBounds[1];
lr_x = initBounds[2];
lr_y = initBounds[3];
//check rest of group if any
for (i=1; i<mySelection.length; i++) {
groupBounds = mySelection[i].visibleBounds;
if (groupBounds[0]<ul_x){ul_x=groupBounds[0]}
if (groupBounds[1]>ul_y){ul_y=groupBounds[1]}
if (groupBounds[2]>lr_x){lr_x=groupBounds[2]}
if (groupBounds[3]<lr_y){lr_y=groupBounds[3]}
}


}

//get x,y/x,y Matrix for 100% view

activeDocument.views[0].zoom = 1;
ScreenSize = activeDocument.views[0].bounds;
ScreenWidth= ScreenSize[2] - ScreenSize[0];
ScreenHeight=ScreenSize[1] - ScreenSize[3];
screenProportion =ScreenHeight/ScreenWidth;

//Determine upperLeft position of object(s)
cntrPos = [ul_x,ul_y];

//mySelection[0].position;
//cntrPos[0] += (mySelection[0].width /2);
//cntrPos[1] -= (mySelection[0].height /2);
//offset by half width and height
mySelWidth=(lr_x-ul_x);
mySelHeight=(ul_y-lr_y);
cntrPos[0] = ul_x + (mySelWidth/2);
cntrPos[1] = ul_y - (mySelHeight/2);
//alert("ul point is "+cntrPos);
//center to screen to the object
activeDocument.views[0].centerPoint = cntrPos;
//alert("objWidth="+mySelection[0].width+", actualWidth="+ActualWidth);
//alert("objHeight="+mySelection[0].height+", actualHeight="+ActualHeight);

//set zoom for height and width
zoomFactorW = ScreenWidth/mySelWidth;
zoomFactorH = ScreenHeight/mySelHeight;
//alert("zoomFactorW = "+zoomFactorW+"\r zoomFactorH = "+zoomFactorH);

//decide which proportion is larger...
if((mySelWidth*screenProportion) >= mySelHeight){
zF = zoomFactorW;
//alert("zoomFactorW = "+zoomFactorW);
}else{
zF = zoomFactorH;
//alert("zoomFactorH = "+zoomFactorH);
}

//and scale to that proportion minus a little bit.
activeDocument.views[0].zoom = zF *.85;

}else{
//alert("Please select an object on the page.");
activeDocument.activeView.zoom=1;
}
}



als Antwort auf: [#571482]

Illustrator: Legacy Text

pixxxelschubser
Beiträge gesamt: 1708

19. Aug 2019, 15:58
Beitrag # 3 von 6
Beitrag ID: #571503
Bewertung:
(4471 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
eine kleine Anmerkung:
Anstatt der zeitraubenden Schleife durch alle pathItems könntest du den folgenden Einzeiler austesten.
Code
app.executeMenuCommand ('clearguide'); 



als Antwort auf: [#571502]

Illustrator: Legacy Text

funkturmmitte
Beiträge gesamt: 117

19. Aug 2019, 16:16
Beitrag # 4 von 6
Beitrag ID: #571504
Bewertung:
(4464 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Danke.
Das macht das ganze schon etwas schlanker.

Jetzt habe ich grade beim Testen gemerkt, dass nicht alles entsperrt wird.

Mit
Code
app.executeMenuCommand ('unlockAll'); 

werden auch noch alle gesperrten Objekte entsperrt.


als Antwort auf: [#571503]
(Dieser Beitrag wurde von funkturmmitte am 19. Aug 2019, 16:29 geändert)

Illustrator: Legacy Text

pixxxelschubser
Beiträge gesamt: 1708

19. Aug 2019, 20:21
Beitrag # 5 von 6
Beitrag ID: #571507
Bewertung:
(4447 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Schlanker - das ist so eine Definitionsfrage. Manche Programmierer sehen das Aufrufen eines Menübefehls nicht als „saubere“ Programmierung an. Da bei Illustrator allerdings (durch die Vielzahl an Objekten) die Schleife durch alle Objekte spürbar länger dauern kann, nehme ich das bei Illustrator gerne in Kauf.

Deine Entsperrschleife habe ich jetzt nicht getestet. Aber kann es sein, dass du hier nur die Toplevel-Layer sowie die erste Hierarchie der Sublayer entsperrst? Dem Anschein nach bleiben tiefer verschachtelte Layer und auch die Objekte selbst vollkommen unberücksichtigt???

Der Menübefehl hingegen arbeitet dokumentenweit.


als Antwort auf: [#571504]

Illustrator: Legacy Text

funkturmmitte
Beiträge gesamt: 117

20. Aug 2019, 10:04
Beitrag # 6 von 6
Beitrag ID: #571510
Bewertung:
(4404 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Ja, da scheinst Du recht zu haben.
Jedoch ist der Befehl
Code
app.executeMenuCommand ('unlockAll'); 

anscheinend nur für das entsperren gesperrter Objekte zuständig.
Ebenen und Unterebenen erwische ich damit nicht.
Das Menü Kommando "alle Ebenen entsperren" aus der Ebenen Palette konnte ich bisher jedoch leider nicht finden - damit dürfte es ja am zuverlässigsten gehen...


als Antwort auf: [#571507]
X