0

I want to change the Color of "Ortsname" in JavaScript, im using:

var relieflackEbene = myDoc.layers.itemByName('Relieflack');

to select the Layer "Relieflack" but when using

relieflackEbene.pageItems.firstItem().strokeColor = "Relieflack";

actually i dont want to use "firstItem()" because it might not be the first item on that Layer. But it is changing the color of the Textbox, not the color of the Text inside it.

InDesign Layer

Any hints?

Yierith
  • 141
  • 1
  • 5

2 Answers2

1

following code should change stroke color of text "Ortsname".

for (var i=0, len=relieflackEbene.pageItems.length; i < len ; i++) {
  if (relieflackEbene.pageItems[i].parentStory.contents === "Ortsname") {
    relieflackEbene.pageItems[i].parentStory.strokeColor = "Relieflack"
  }
};

if you want change at all texts of textframes in the layer, try this

relieflackEbene.pageItems.everyItem().texts.everyItem().strokeColor = "Relieflack";
milligramme
  • 404
  • 3
  • 9
0

Or you could use changeText method unless it's too wide:

var main = function() {
 var doc = app.properties.activeDocument,
 ftp = app.findTextPreferences.properties,
 ctp = app.changeTextPreferences.properties,
 color;
 if ( !doc ) return;
 
 color= doc.swatches.itemByName ( "Relieflack" );
 
 if ( !color.isValid ) {
  alert("Color \"Relieflack\" is required.");
  return;
 }

 app.findTextPreferences = app.changeTextPreferences = null;
 
 app.findTextPreferences.properties = {
  findWhat:"Ortsname",
 };

 app.changeTextPreferences.properties = {
  strokeColor:color,
 };

 doc.changeText();
 
 app.findTextPreferences.properties = ftp;
 app.changeTextPreferences.properties = ctp;
}

var u;

app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );
Loic
  • 2,173
  • 10
  • 13