Copy link to clipboard
Copied
Hi everybody!
It is a tiny little mess I can't solve this problem:
In an InDesign document somebody created the paragraph-style "Menge" (amount). It's the style for the number of pieces in a table. And this somebody put the name in QUOTES!!! I don´t know why.
Now I want to search for this and other styles and change the font. Unfortunately I didn´t found a way yet.
I tried it like this:
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName("\"Menge\"");
alert(myStyle.isValid);
... and like this:
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName('"Menge"'); //
alert(myStyle.isValid);
... or like that:
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName('^"Menge^"'); //
alert(myStyle.isValid);
If I change the name to another, without quotes, it will be found.
To change that name is not an option, because I get the dokuments every time from somebody who is working with them.
Is there any way to deal with that?
cmoke73 It seems a quite tricky to get in one line.
So I would suggest don't get stuck there.
Try this:
...var myDoc = app.documents[0];
var groupStyleName = 'Formatgruppe 1';
var myStyleName = '"Menge"';
var myStyle = findGroupStyle(groupStyleName, myStyleName);
if(myStyle != null){
alert(myStyle.name);
}
else{
alert("Style does not exists !!!");
}
///////////////////////////////////
function findGroupStyle(groupStyleName, myStyleName){
for(var gp = 0; gp < myDoc.paragraphStyleGroups.item(gro
Copy link to clipboard
Copied
Hello,
try this to find style in document
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item('"Menge"');
alert(myStyle.isValid);
Copy link to clipboard
Copied
Hi.
I forgot, that was the fourth trial.
but thanks
And if I do this:
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName(""Menge"");
... the word "Menge" becomes part of the code and on the left side and the right side are two/two quoted nothings.
Copy link to clipboard
Copied
you have to put style name in single quotes and your style name is "Menge"
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item('"Menge"');
alert(myStyle.isValid);
Copy link to clipboard
Copied
cmoke73 It seems a quite tricky to get in one line.
So I would suggest don't get stuck there.
Try this:
var myDoc = app.documents[0];
var groupStyleName = 'Formatgruppe 1';
var myStyleName = '"Menge"';
var myStyle = findGroupStyle(groupStyleName, myStyleName);
if(myStyle != null){
alert(myStyle.name);
}
else{
alert("Style does not exists !!!");
}
///////////////////////////////////
function findGroupStyle(groupStyleName, myStyleName){
for(var gp = 0; gp < myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles.length; gp++){
if(myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp].name == myStyleName){
return myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp];
}
}
return null;
}
Best
Sunil
Copy link to clipboard
Copied
Hi Sunil.
I cannot explain to myself why, but your way is the right one. Although the parameters are the same: The same double-quoted word set in single quotes.
That´s the modified script how I wanted to use:
var myDoc = app.documents[0];
var groupStyleName = 'Formatgruppe 1';
var myStyleName = '"Menge"';
var myStyle = findGroupStyle(groupStyleName, myStyleName);
///////////////////////////////////
function findGroupStyle(groupStyleName, myStyleName){
for(var gp = 0; gp < myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles.length; gp++){
if(myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp].name == myStyleName){
myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp].appliedFont = "Helvetica LT Std Bold Condensed";
//return myDoc.paragraphStyleGroups.item(groupStyleName).paragraphStyles[gp];
}
}
return null;
}
Copy link to clipboard
Copied
cmoke73 wrote
Hi Sunil.
I cannot explain to myself why, but your way is the right one. …
Hi Andreas,
the explanation is that there is a bug with InDesign CC 2018.1 and below regarding itemByName() or item() when used with styles and quotes with the style names. That bug seems to be fixed with InDesign CC 2019. At least with my installed prerelease version 14.0.3.422.
Sunil is not using the said methods but instead he compares the value of a style name with the given string of the name.
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe.
Ok, I see. So looking forward having the newest version. Whenever...
By the way, my version is InDesign 2017.0 buid 12.0.0.81. (Mac)
Thank you all.
The problem is clearly solved, I think.
Copy link to clipboard
Copied
The issue is not only with styles.
In principle it's with itemByName("String"). Or item("String").
See this code and run it on different versions of InDesign.
Best CC 2019 vs all others.
var itemName = '"Name"';
var doc = app.documents.add();
doc.rectangles.add({ name : itemName , geometricBounds : [0,0,100,100] });
var result = doc.pageItems.itemByName(itemName).isValid;
var message = app.version +" "+ itemName +": "+ result ;
$.writeln( message );
alert( message );
/*
Some results with different versions of InDesign:
13.1.1.110 "Name": false
14.0.3.422 "Name": true
*/
Regards,
Uwe
Copy link to clipboard
Copied
Hi payalm68947498 ,
I don't think the quotes are straight quotes.
Without seeing the document you could hunt for a part of the known name like Menge and assume a unknown number of characters before and after this core. One could do this with a RegExp or a simple name.match("Menge") when looping the allParagraphStyles array.
Regards,
Uwe
Copy link to clipboard
Copied
Laubender wrote
I don't think the quotes are straight quotes.
Uwe, I can confirm the OP's problem is indeed because of the straight double quotes with this short script. It is a problem with straight quotes. If the following shows 'True', 'True' for you, rather than 'True', 'False', we have to zoom in on Version and OS.
styleName = 'Menge';
theStyle = app.activeDocument.paragraphStyles.add({name:styleName});
recallStyle = app.activeDocument.paragraphStyles.itemByName(styleName);
alert (styleName+': '+recallStyle.isValid);styleName = '"Malesche"';
theStyle = app.activeDocument.paragraphStyles.add({name:styleName});
recallStyle = app.activeDocument.paragraphStyles.itemByName(styleName);
alert (styleName+': '+recallStyle.isValid);
The double quotes here *are* plain ASCII U+0022.
Copy link to clipboard
Copied
Hi Jongware,
I get a true for both alerts with InDesign CC 2019 version 14.0.3.422 ( prerelease ) on Windows 10.
Language version: German
Different thing with InDesign CS6 version 8.1 on Windows 10 on the same machine.
The first alert is true, the second one is false.
Also with CC 2018.1 on the same machine: The first alert is true, the second one is false.
Double checked with all versions tested that the quotes in the style name is plain Unicode 0022.
Regards,
Uwe
Copy link to clipboard
Copied
No, if you tried it you should have found that does not work either. When given a name, item() behaves the same as itemByName(); when given a number, it behaves like paragraphStyles[index].
For me, this
stname = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles[0].name;
alert (stname);
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item(stname);
alert(myStyle.isValid);
shows "Menge" (correct) and yet next 'false'. No difference between "item" and "itemByName".
By the way, it also cannot find names such as
("Menge"
"Menge")
("Menge")
Menge with a single " somewhere inside!
No problems with single quotes. It seems using the double quote anywhere in a style name is not such a good idea after all.
Copy link to clipboard
Copied
yes, i´m afraid it is like you said.
Sometimes I´m between two chairs: ID-users, who didn´t know what they do and the little bugs made by Adobe or for lack of interest not programmed functions. But it is not so tragic, only a pity
Thank you all
Copy link to clipboard
Copied
by the way:
- stname = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles[0].name;
- alert (stname);
- var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.item(stname);
- alert(myStyle.isValid);
It's a cool idea to prove that InDesign beats itself
checkmated
Copy link to clipboard
Copied
I'm not that good at scripting. But what about the idea to search with a regular expression-function (RegExp). Is that possible?
Copy link to clipboard
Copied
Hi cmoke73 ,
yes. You can find a style or a style group where you are looking for one part of a name.
But first I suggest you'll see into the exact name of that style group and how it is exactly composed of glyphs.
Maybe there are some unusual glyphs used for the quotation marks ( or whatever the ones are ).
Run the following code that will add a new text frame to the first page of your document.
The contents of the frame are all names for all style groups in the root of your paragraph styles panel.
The language for the text is set to "No Language".
var doc = app.documents[0];
var newTextFrame = doc.pages[0].textFrames.add
(
{
geometricBounds : [0,0,100,100] ,
parentStory : { appliedLanguage : doc.languages[0] } ,
contents : doc.paragraphStyleGroups.everyItem().name.join("\r")
}
);
After that inspect the glyphs that make the quotes.
Here a sample screenshot from the result I did with a document that uses some strange kind of quotes in the names:
As you can see from my Story Editor Window and compare this with the look of the names in my paragraph styles panel some look similar enough, but in fact are not. Otherwise I could not have created the style group.
The third and the first one listed look quite the same.
But apparently they are not!
Test my code snippet and come back if you found the right unicode value(s) for the two quotes.
FWIW: Both quotation marks could be different and could be composed of one or two glyphs.
If so list the unicode values for every single glyph surrounding Menge.
Regards,
Uwe
EDIT: Removed one line of the code that was not necessary.
Copy link to clipboard
Copied
Hi Laubender.
Many thanks for your effort! Your detailed explanation is very helpful as well.
A little remark: the name is not the name of a group but for a paragraph-style IN a group. But it doesn´t really make a difference.
The Unicode for the opening quote is 0x201E and for the closing one it is 0x201C.
Copy link to clipboard
Copied
The DOUBLE LOW-9 QUOTATION MARK ( 201E ) and the LEFT DOUBLE QUOTATION MARK ( 201C ).
Just like in my sample with paragraph two of my screenshot.
You'll be able to find the name directly.
var myDoc = app.documents[0];
var myStyle = myDoc.paragraphStyleGroups.item('Formatgruppe 1').paragraphStyles.itemByName('„Menge“');
alert(myStyle.isValid);
Regards,
Uwe
Copy link to clipboard
Copied
Unfortunately I´m not able.
It was one of my first attempts.
Copy link to clipboard
Copied
Then make a document with the style available for download.
Best use Dropbox for this and post a download link of the document.
You could remove every contents from the document.
Or apply the style to some dummy text and copy the text frame to a new document and supply that for download.
Regards,
Uwe
Find more inspiration, events, and resources on the new Adobe Community
Explore Now