Copy link to clipboard
Copied
Hi experts,
My script like this:
var cDoc = app.activeDocument;
myPara = cDoc.ParagraphStyle.name.match(/\(Note\)/,g);
if (myPara.isValid){
myPara.remove();
}
else exit;
aim to remove paragraph style which name match (Note).
how can I make it work?
thanks
regard
John
Hi John,
check your variable named: myPara.
This would hold the result of the match if everything would be ok in that code line.
However it is not:
There is no property ParagraphStyle for a document.
Also check the regular expression. Best test something like that before with a string you are familiar with:
var s = "Before (Note) After";
s.match( /\(Note\)/,g); // will give an error: g is undefined.
You have to write g as a string. Sorry, I have to correct myself. See corrected code below:
Also note, tha
...Copy link to clipboard
Copied
hi John ,
you can remove paragraph style like this,
var cDoc = app.activeDocument;
myPara = cDoc.paragraphStyles.item("Note");
if (myPara.isValid){
myPara.remove();
}
else exit;
Copy link to clipboard
Copied
Hi John,
check your variable named: myPara.
This would hold the result of the match if everything would be ok in that code line.
However it is not:
There is no property ParagraphStyle for a document.
Also check the regular expression. Best test something like that before with a string you are familiar with:
var s = "Before (Note) After";
s.match( /\(Note\)/,g); // will give an error: g is undefined.
You have to write g as a string. Sorry, I have to correct myself. See corrected code below:
Also note, that there could be more instances than one paragraph style name that could match.
If you want to check all paragraph styles loop the allParagraphStyles array of the document so that you can also see into paragraph styles in style groups.
Something like that should be robust enough:
var doc = app.activeDocument;
var paraStyles = doc.allParagraphStyles; // Returns an array;
// Array to store the ids of all matches:
var idsOfStylesToRemove = [];
// Loop the array to check every paragraph style name in the document:
for( var n=0; n<paraStyles.length; n++ )
{
if( paraStyles
.name.match( /\(Note\)/g ) )//EDITED { idsOfStylesToRemove[ idsOfStylesToRemove.length++ ] = paraStyles
.id }; };
// Loop the results and remove every style there:
for( var n=0; n<idsOfStylesToRemove.length; n++ )
{ doc.paragraphStyles.itemByID( idsOfStylesToRemove
).remove() };
Regards,
Uwe
Copy link to clipboard
Copied
Thank you Uwe
thank you so much.
John
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more