Copy link to clipboard
Copied
Okay, it is my first Javascript, not true: it´s my second one.
Working on the first one I figured out how to apply different paragraph-stypes to the paragraphs in a selected text frame.
Now, I actually would like to do the previous step: to search for a particular word and to replace it in special form.
And, because I am a js-greenhorn, it doesn´t work, of course...
Here the code:
var doc = app.activeDocument;
var Auswahl = app.selection[0];
var AlleAbsaetze = Auswahl.paragraphs.everyItem();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
// Voreinstellung für das GREP
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
AlleAbsaetze.findGrepPreferences.findWhat = "Art\.\-Nr\.";
AlleAbsaetze.changeGrepPreferences.changeTo = "Art\.";
doc.changeGrep();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
The engine stops at row 15 and nothing happens.
I'm sure it's a stupid beginner's mistaker, but I do not know where.
The error-message is: "Object does not support the property or method 'findGrepPreferences'."
I suppose it´s not possible to assign the GREP-search-function neither to a paragraph nor to a text frame. Isn´t it?
Any idea?
Not a big issue .. change like below...
...var doc = app.activeDocument;
var Auswahl = app.selection[0];
var AlleAbsaetze = Auswahl.paragraphs.everyItem();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
// Voreinstellung für das GREP
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = fals
Copy link to clipboard
Copied
Not a big issue .. change like below...
var doc = app.activeDocument;
var Auswahl = app.selection[0];
var AlleAbsaetze = Auswahl.paragraphs.everyItem();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
// Voreinstellung für das GREP
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences.findWhat = "Art\.\-Nr\.";
app.changeGrepPreferences.changeTo = "Art\.";
AlleAbsaetze.changeGrep();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
Copy link to clipboard
Copied
It can be that easy... if one knows how it works.
thank you tpk1982
Copy link to clipboard
Copied
But:
The Indesign doc is like this, partially
Art.-Nr.
There is a space and a break (return) at the end of the line.
If I search for "Art\.\-Nr\.\s~b" there is no hit. Without the space (\s) it works (of course just if there is no space)
Copy link to clipboard
Copied
To check Art.-Nr., use square brackets..
for space issue, remove trailing space is useful.. but run first this then the code.. if you need to include this then the final code like..
var doc = app.activeDocument;
var Auswahl = app.selection[0];
var AlleAbsaetze = Auswahl.paragraphs.everyItem();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
// Voreinstellung für das GREP
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
app.findGrepPreferences.findWhat = "\s+$";
app.changeGrepPreferences.changeTo = "";
app.changeGrep();
app.findGrepPreferences.findWhat = "Art[.]-Nr[.]";
app.changeGrepPreferences.changeTo = "Art\.";
AlleAbsaetze.changeGrep();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
Copy link to clipboard
Copied
Okay, now it works. But why the conventional regex doesn´t???
The same with the artikel number. In one magazine it is like this: 00 0000, in the other one: Art. 000 000.
So I search for: "^(\d{2})(\s)(\d)(\d{3})";
And change to: "Art\.\s$1$3\s$4";
Without effect. Is something wrong here as well?
Copy link to clipboard
Copied
^ means the beginning of paragraph.. is it every number only start at beginning of paragraph?
also simply you can say..
^\d+\s+\d+
Copy link to clipboard
Copied
Right, each of them shold be at the beginning.
If I search with "^\d+\s+\d+" I can´t replace it like I want... I need the braces.
Copy link to clipboard
Copied
Hmm..for 00 0000.. use like below
So I search for: "^(\d{2})(\s)(\d{3})";
And change to: "Art. $1$2$3";
Copy link to clipboard
Copied
No, it found nothing. What could be wrong, hmmmm.....
Copy link to clipboard
Copied
please share the screen shot of your document..
Copy link to clipboard
Copied
the last two lines are different. I try to make a replacement for each eventuallity (with and without a space after the second digit)
Copy link to clipboard
Copied
Are using those in script or in indesign itself?
For indesign means..like below
for script means we need to add two slashes...
^(\\d{2})(\\s)(\\d{4})
Copy link to clipboard
Copied
in a script.
!!that was the problem!! thanks
Can you please tell me WHY we need two slashes? :S
Copy link to clipboard
Copied
I would like to know, again: why do the conventional regex not work? It was hard enough for me to learn it wothin two weeks, now it not very helpful!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now