Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

delete and substitute another paragraph styles...

Explorer ,
Jul 20, 2008 Jul 20, 2008
Hi everyone,

We need script for delete unwanted paragraph styles & character styles in InDesignCS2. While deleting also want to replace some styles for it. So can anyone help me for this. Thanks.

Thiyagu
TOPICS
Scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2008 Jul 20, 2008
If You are sure of the Styles names and existence this might suffice (name2 is the style replacing the the one named name1):

var myDocument = app.activeDocument;
myDocument.paragraphStyles.item("name1").remove("name2")

Same with characterStyles.

But You probably should set up clauses to verify the existence of the various Styles to avoid errors and thats where Im unfortunately out of my depth; hopefully someone else can help You there.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2008 Jul 21, 2008
You also need to check nested styles and "based on" styles. This can be pretty tricky.

Peter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2008 Jul 22, 2008
Thanks christoph,

It is working nicely. We need this same for CS3. But the same script is not worked out. Because it shows an object error. I have checked the syntax for CS3 in the scripting guide, i am unable to find it. Please help me to this. Thanks once again.

Thiyagu
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2008 Jul 22, 2008
The object error probably is caused by what Peter Kahrel mentioned, the Styles referring to one another, or one or more of the Styles having different names or being missing.
The Script should therefore incorporated if-clauses to verify that the Styles exist and have the exact names You use in the Script before running the remove-operation.
But Peter is far more experienced (his book on automating Indesign with JavaScript goes way over my head) and maybe he could provide You with the better lines of Script.

var myDocument = app.activeDocument;
if (myDocument.characterStyles.item("name1") != null) {
if (myDocument.characterStyles.item("name2") != null) {
myDocument.characterStyles.item("name1").remove("name2")
}}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2008 Jul 22, 2008
oooh sorry its working in CS3.

But Problem is while running the script, if the defined style in script is not there in the file it shows error like "Unterminated comment". In some of the documents few of the styles are missed out. But script should execute even the style is not present in the document. Please help me to this. Thanks once again.

Thiyagu
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2008 Jul 22, 2008
No, the Script cannot continue when one of the styles is missing (to the best of my knowledge) unless You include the conditional clauses (or some other construction to the effect).
If You include those the Script will only remove/replace Styles that it verified exist, thus avoiding errors.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2008 Jul 22, 2008
Hi christoph,

var myDocument = app.activeDocument;
if (myDocument.characterStyles.item("name1") != null) {
if (myDocument.characterStyles.item("name2") != null) {
myDocument.characterStyles.item("name1").remove("name2")
}}

This working fine yaar. Thank you so much. I have completed my script with your help.

Thiyagu
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2008 Jul 22, 2008
Youre welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2010 Feb 05, 2010

I have modified this script so I can delete & replace paragraph styles...

var myDocument = app.activeDocument;

if (myDocument.paragraphStyles.item("SBS Step i") != null) {

if (myDocument.paragraphStyleGroups.item("MainStyles"). paragraphStyles.item("SBS Step i2") != null) {

myDocument.paragraphStyles.item("SBS Step i").remove("SBS Step i2")

}}

It is working find but, not if the "SBS Step i2" styles is inside a Group. How can we specify if a paragraph is from a group when removed.

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 05, 2010 Feb 05, 2010

Try this:

myDocument.paragraphStyles.item("SBS Step i").remove(myDocument.paragraphStyleGroups.item("MainStyles"). paragraphStyles.item("SBS Step i2"));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2010 Feb 05, 2010

Kaysan, thanks that works....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 20, 2010 Aug 20, 2010

I found this script hoping it would help me out. We recently updated the template to one of our books so the paragraph & character style names line up with other projects. I added two lines to the script in the format shown and ran the script and it worked. "Great!" I thought. But when I made a comprehensive list (the script is 47 lines long), it suddenly gives me error messages and won't even get through one line of the script! I have confirmed that both the old and new style names are present in the document and match exactly. Can anyone help me understand what I'm doing wrong? I've attached the warning message and a few lines of the script. I am working in CS4. Thanks,


Matt

var myDocument = app.activeDocument;
myDocument.paragraphStyles.item("Body - Recipe Head").remove("STORY HEAD");
myDocument.paragraphStyles.item("Body - Recipe Head 2 line").remove("STORY HEAD 2LINE");
myDocument.paragraphStyles.item("Body-Recipe Head 3 lines").remove("STORY HEAD 3LINE");
myDocument.paragraphStyles.item("Body - Indent").remove("STORY BODY");


(continues this pattern for other styles)

Screen shot 2010-08-20 at 12.02.40 PM.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 20, 2010 Aug 20, 2010

Try to reference paragraph style as Object instead of String:

myDocument.paragraphStyles.item("Body - Recipe Head").remove(myDocument.paragraphStyles.item("STORY HEAD"));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 20, 2010 Aug 20, 2010

/* IT SHOULD READ AS BELOW, REPEAT FOR EACH STYLE YOU WILL REPLACE */

var myDocument = app.activeDocument ;


myDocument.paragraphStyles.item( "Body - Recipe Head" ).remove ( myDocument.paragraphStyles.item( "STORY HEAD" ) ) ;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 20, 2010 Aug 20, 2010

Herr Meuller, I tried that but I am still getting the same warning message. I tried it with and without the spaces you included in your example. What am I doing wrong?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 20, 2010 Aug 20, 2010
LATEST

OK, I just tried this again in another document and it worked fine. Not sure what was going on with the document I was trying the first time, but it seems to be OK. I'll report back and let you know if I have any problems. Thank you both.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines