script to replace a paragraph style with a different styles, both within a folder

I am trying to write a script that will remove a paragraph style or character and then replace it with another paragraph or character style, both are in a folder within these groups of style. I have tried so many different scripts and that you have not found the right combination to work.

any help would be greatly appreciated! Thank you!

To target a paragraph style that is in a folder, you will have to tunnel to him through groups of styles, thus:

Style1 = app.activeDocument.paragraphStyleGroups.itemByName("Group1").paragraphStyleGroups.itemByN ame("Group2").paragraphStyles.itemByName ("myParagraphStyle");

Then find the second style (one you want to replace by):

Style2 = app.activeDocument.paragraphStyleGroups.itemByName("GroupA").paragraphStyles.itemByName ("AnotherParaStyle");

Simple and then remove the first style, replace it with the second:

Style1.Remove (Style2);

HTH,

Ariel

Tags: InDesign

Similar Questions

  • Script for Indesign find paragraph style change at the table with the table style

    Hello

    I hope someone could help me with a script.

    I can tab with a paragraph style and I want to convert that to a table with a table style.

    Kind regards

    Patrick

    Yes

    My problem is solved

    Thank you very much.

    Patrick

  • [win] [js] [cs4] find/replace the paragraph styles without losing the replacements the

    Hi guys I need some help here.

    I created a javascript script that will find and replace paragraph styles for the DOCFILE with indesign paragraph styles. everything works fine but the problem is that, when she applies paragraph styles, he loses all replacements the. I tried:

    changetext (false);

    but his does not work, this is a kind of conditional parameter that I can put in the function changetext() so that it used clear local overrides?

    Thank you.

    Horse

    Use findGrep() (or findText()) instead of changeText(). This returns an array of items found. Then, you can loop through the array and apply a paragraph style without erasing the replacements (the 2nd parameter must be false).

    Example:

    Main();
    
    function Main() {
        var foundItem;
        var doc = app.activeDocument;
    
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
    
        app.findGrepPreferences.findWhat = ".+";
        app.findGrepPreferences.appliedParagraphStyle = "Body text";
    
        var foundItems = doc.findGrep();
    
        for (var i = 0; i < foundItems.length; i++) {
            foundItem = foundItems[i];
            foundItem.applyParagraphStyle(doc.paragraphStyles.item("Body"), false);
        }
    
        app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
    }
    
  • Script of the current paragraph style

    Can someone tell me what is the code to return the paragraph style for the current position of the cursor.

    Also I can I ask something to the current paragraph is not using paragraph styles.

    For example, what would be the code to "make the current text of paragraph Red.

    Help would be much appreciated as we see questions that I'm a complete Newbie in scripting.

    if (app.documents.length > 0 && app.selection.length === 1 && app.selection[0].hasOwnProperty("baseline")) {
         // return the paragraph style for the current cursor position
         alert("Paragraph style: " + app.selection[0].appliedParagraphStyle.name);
         // Make current paragraph text Red (the 1st paragraph in the selection)
         app.selection[0].paragraphs[0].fillColor = "C=15 M=100 Y=100 K=0";
    }
    
  • Script to create an example of each paragraph Style?

    Hi all

    Has anyone seen a script that generates an example of all the paragraph styles that are loaded into a document (the name of actual paragraph style as style would be a plus)?

    I have a script to export all paragraph style settings, but it would be nice to show all my co-workers who are preparing to move to INDD what each style looks like actually. It would also eliminate all duplicate with different names.

    Thanks in advance!

    Ah there was he: http://forums.adobe.com/thread/922205?tstart=30

  • script to duplicate the standard paragraph style, and then change the size of the character point

    I want to create a script that will create a cascade of paragraph based on the style settings [standard paragraph] styles. My goal is to point size of each new paragraph style character as a percentage of the original [standard paragraph]. So if [standard paragraph] is 100% (point character size 10pt), the script would create a paragraph style called 120% ' that has a point size of character of 12 points. Then 133%, 140%, and on and on. I modified a script found on this forum to generate these new styles, but I don't know how to be based on the [standard paragraph]. Any help would be much appreciated, thanks in advance.

    current script:

    var doc = app.activeDocument,

    pStyle = ['100% ', '120% ', '133% '];

    for (var i = 0; i < pstyle.length; i ++)

    {

    If (pstyle [i] is "100 %")

    {

    doc.paragraphStyles.add ({name: pstyle [i], appliedFont: 'Deer', pointSize:10});})

    }

    ElseIf (pstyle [i] == "120 %")

    {

    doc.paragraphStyles.add ({name: pstyle [i], appliedFont: "Deer", pointSize:10 * 1,2})

    }

    ElseIf (pstyle [i] == "133 %")

    {

    doc.paragraphStyles.add ({name: pstyle [i], appliedFont: "Deer", pointSize:10 * 1.33333})

    }

    }

    Try this,

    var doc = app.activeDocument,
        pstyle = ["100%", "120%", "133%" ];
    
    for(var i =0;i
    

    Kind regards

    Cognet

  • import the grep styles in more than a paragraph style

    Hello

    First of all, I must say that I have no experience in scripting. I do not create scripts, simply use the.

    I have a script that imports a paragraph style grep styles to another (in the same document). Whenever I use it, I have to change the script, captures the source paragraph styles and target in this piece of code:

    source = "origem";

    target = "alvo";

    What happens is that sometimes I need to do this lots of times (especially when the updating of old projects). Is it possible to import styles grep for more than a paragraph at the same time, listing multiple targets?

    Thank you!

    Sorry,

    the variable 'source' changed during execution of the script old th. Don't have a close enough look...

    Please replace:

    function setGrepStyle(){
    var target = arguments[0].toString();
    error = "";
     basePStyle = theDoc.paragraphStyles.item(source);
    if (!basePStyle.isValid) error = 'Source style does not exist';
     var target = theDoc.paragraphStyles.itemByName(target);
     if (!target.isValid) error += '\rTarget style does not exist';
     if (error != ""){alert (error); exit()}
      gs = basePStyle.nestedGrepStyles;
     for (i = 0; i < gs.length; i++)
            target.nestedGrepStyles.add (gs[i].properties);
            }
    

    Work here, if this does not work on your machine, I'll write a new piece to add to the SNA nestedGrepStyles ship off the doScript is not really necessary...

  • Copy paragraph styles between documents

    I have a document that contains a text I want to copy to another document. The original text is tagged with a paragraph called body style. If the document that I copy in already has a paragraph style called body defined, then when I copy the text in this document, he applies his body paragraph style to the text I copy in there. Is it possible to copy the text and maintain the style of the original document (replacing the paragraph style in the receiving document)?

    I use InDesign CS5.

    Thank you!

    You will reach your goal by simply using the Basic Edition > paste, but you should try to put it in a text box empty, the new. It keeps the appearance and will replace your body style, leaving a + next to him. I advise you to create a new style with this, but especially if you want to send later in print.

    If this isn't it, you can have applied character styles.

  • application of paragraph styles

    Hi all

    play with a very simple script:

    mySel = app.selection[0];
    
    mySel.paragraphs[0].insertionPoints[0].paragraphs[0].appliedParagraphStyle = "myPStyle1";
    mySel.paragraphs[0].insertionPoints[-1].paragraphs[0].appliedParagraphStyle = "myPStyle2";
    mySel.paragraphs[0].insertionPoints[-2].paragraphs[0].appliedParagraphStyle = "myPStyle3";
    

    script applies myPStyle1 to paragraph style to a paragraph with the inserted text cursor, then in the next paragraph and then myPStyle2... I'm stuck here.

    Line 3 applies myPStyle3 to the first paragraph again, instead of expected next (3rd)...

    I thought that I can develop the sequence I need, but I can't?

    According to me, I have something very basic catch here...

    a tip?

    or another source, where are answered these questions silly?

    Thank you!

    This is not the right approach. It does that by accident.

    mysel.paragraphs [0] .insertionPoints are all insertion points in the current paragraph. Is there are 100 characters, then there are 101 insertPoints (on each side of each character). PointInsertion [0] is the left of the first character, [1] is to the right of the first character, [2] to the right of the 2nd character, etc. until [101] to the right of the last character.

    insertionPoints [-1] refers to the last PointInsertion, [101], which is actually after the paragraph itself, formats the following paragraph.

    insertionPoints-[2] refers to the 2nd to the last PointInsertion, [100], which is the left of the last character.

    I don't know what is the best way to deal with this. Maybe:

    mySel=app.selection[0];
    p = mySel.paragraphs[0]; p.appliedParagraphStyle="myPstyle1";
    p = p.insertionPoints[-1].paragraphs[0]; p.appliedParagraphStyle="myPstyle2";
    p = p.insertionPoints[-1].paragraphs[0]; p.appliedParagraphStyle="myPstyle3";
    ...
    

    I guess that the exact method depends on what you're trying to do.

  • InDesign CC 2015 (do not apply paragraph styles)

    Hello

    InDesign doesn't apply paragraph styles. Said she, but nothing has changed. Someone else has the same problem?

    Thank you

    Have you looked to see that a character Style is accidentally applied on the same text? Character styles replaces the paragraph style attributes.

  • CS3: need script to replace spaces with underscores in the paragraph and character style names

    Help! I am very new to scripting.

    I managed to find and tweak existing javascripts to search through all my paragraph styles to disable hyphenation and off balance the jagged lines, but I need help with this one.

    I work on Mac OS 10.4.11 using Indesign CS3.

    I need a script that will search all my paragraph and character styles in my open Active document and replace spaces by underscores.

    Can someone help me with this? It would be greatly appreciated!

    1. I don't know, but I think you can use all the regular GREP inside this function codes. Do not use the quotation marks around of the expression, use slashes! (Why? Just a curiosity of Javascript... maybe a hack that goes back to the gray mist of JS development...)

    This work should - but rather the code above, this is not tested:

    .. Replace (/ [-\ / ()-. _] + / g. '_');

    The GOLD group inbetween the brackets contain all the characters you want to replace with an underscore: the hyphen (this has to be the first character in the group, else it will be interpreted as a range of characters from each side!), space, slash (this one is 'special' inside the function replace JavaScript, so I think he needs to escape with a backslash)! in parentheses, a period (not sure if it should escape - into ordinary GREP, it's the wildcard character for any character, but maybe he loses his magic within a group of GOLD) and finally... the underscore character. Why?

    Well, this replacement string comes with a free bonus. Note the sign after the installment of GOLD +. This means that a whole sequence of these characters is replaced by a simple underscore: "it's / a - / test" will become "This_is_a_test". Adding the underscore line itself to the string of research means that it will also find the whole chain 'space space (stroke underscore)' in 'This style (_)' and, oh magic!, replace it immediately with a single underscore.

    Just FYI, the tiny "g" after the closing slash is abbreviation of 'global', i.e. at the global level, replacing in this string. replace the default values for a replacement only (why? see above...), and adding the 'g' ensures he keeps replacing until it is not find matches more.

    2 see point 1.

    3. uh, yes it's true, but you will need to check very carefully if nothing inside one of these basic models is substituted. You can apply a base style and add substitutions to make look like a subtitle, but that isn't making it a. And to the next paragraph, you can apply a base style and add substitutions to make it look like a paragraph of plain text (etc.). It's a signature of witness to bad formatting...

  • Script Export single Pages with the name and file custom paragraph Style?

    I have a document called "mydocument".

    I have a several pages in the document.

    Each page has a title of"style with a stylesheet called point title.

    I need to export each page as individual .jpg with a custom file name

    myDocument-01 - title.jpg

    01 is the page number

    Seemed like a simple request... but it turns out that it's a little challenging.

    This scipt below, that I found on another thread a little work

    It gives me a

    Title1.jpg

    But I can't figure out how...

    1. Add the name of "mydocument".

    2. have a 0 on the 1-digit numbers

    Can someone please guide me, I would be eternally grateful.

    if (app.documents.length != 0) {
         var myDoc = app.activeDocument;
        MakeJPEGfile();
    }
    else{  
         alert("Please open a document and try again.");  
    } 
    
    
    function MakeJPEGfile() { 
    
    
    
    
    
    
         for(var myCounter = 0; myCounter < myDoc.pages.length; myCounter++) {
    
              if (myDoc.pages.item(myCounter).appliedSection.name != "") {
                   myDoc.pages.item(myCounter).appliedSection.name = "";
              }
                
                var myPageName = myDoc.pages.item(myCounter).name;
              var myJpegPrefix = "";
              var isStyleExist = true;
    
              //Checking the existing of the paragraph style (filename)
              try {
                  myDoc.paragraphStyles.item("title");
              }
              catch (myError) {
                  isStyleExist = false;
              }
    
              if (isStyleExist)
    
    
              myJpegPrefix = getParagraphContent(myDoc.paragraphStyles.item("title"), myDoc.pages.item(myCounter)) + myPageName;
              app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; // low medium high maximum
              app.jpegExportPreferences.exportResolution = 72;
              app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
              app.jpegExportPreferences.pageString = myPageName;
    
    
              var myFilePath = "~/-client/JOYS - Just Organize Your Stuff/-Art/-art-book-kindle/" + myJpegPrefix + ".jpg";
              var myFile = new File(myFilePath);
              myDoc.exportFile(ExportFormat.jpg, myFile, false);
         }
    }
    
    
    // The new function, but needs to add checking the file name rules.
    
    
    function getParagraphContent (paragraphStyle, currentPage)
    {
        var paragraphContent = null;
        for (var c = 0; c < currentPage.textFrames.length; c++)
        {
            for (var i = 0; i < currentPage.textFrames.item(c).paragraphs.length; i++)
            {
                if (currentPage.textFrames.item(c).paragraphs.item(i).appliedParagraphStyle == paragraphStyle)
                {
                    paragraphContent = currentPage.textFrames.item(c).paragraphs.item(i).contents;
       // Remove spaces and returns at the end:
                    paragraphContent = paragraphContent.replace(/\s+$/, '');
       // Replace remaining spaces with hyphen:
                    paragraphContent = paragraphContent.replace(/\s+/g, '-');
       // Make lowercase:
                    paragraphContent = paragraphContent.toLowerCase();
                    return paragraphContent;
                }
            }
        }
        return paragraphContent;
    }
    
    

    Thank you Mi!

    One more step.

    I just need to remove the extension .indd.

    My file name is now

    myDocument.indd - 01 - title.jpg

    If (app.documents.length! = 0) {}

    myDoc var = app.activeDocument;

    MakeJPEGfile();

    }

    else {}

    Alert ("Please open a document and try again.");

    }

    function MakeJPEGfile() {}

    for (var myCounter = 0; myCounter< mydoc.pages.length;="" mycounter++)="">

    If (. appliedSection.name myDoc.pages.item (myCounter)! = "") {}

    myDoc.pages.item (myCounter).appliedSection.name = "";

    }

    var myPageName = myDoc.pages.item (myCounter) .name;

    var myJpegPrefix = "";

    var isStyleExist = true;

    Audit of the existing paragraph style (filename)

    try {}

    myDoc.paragraphStyles.item ("title");

    }

    {} catch (MonErreur)

    isStyleExist = false;

    }

    If (isStyleExist)

    myJpegPrefix = getParagraphContent (myDoc.paragraphStyles.item ("title"), myDoc.pages.item (myCounter)) + '-0 "+ myPageName;

    app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; low medium high maximum

    app.jpegExportPreferences.exportResolution = 72;

    app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

    app.jpegExportPreferences.pageString = myPageName;

    var CheminMonFichier = "" ~/-client/JOYS - just organize your Stuff Art / /-art-book-kindle / "+" / "+ myDoc.name +"-"+ myJpegPrefix +".jpg";

    var myFile = new File (myFilePath);

    myDoc.exportFile (ExportFormat.jpg, myFile, false);

    }

    }

    The new feature, but it will add filename rules checking.

    function getParagraphContent (paragraphStyle, currentPage)

    {

    var paragraphContent = null;

    for (var c = 0; c)< currentpage.textframes.length;="">

    {

    for (var i = 0; i)< currentpage.textframes.item(c).paragraphs.length;="">

    {

    If (currentPage.textFrames.item (c).paragraphs.item (i) .appliedParagraphStyle is paragraphStyle)

    {

    paragraphContent = currentPage.textFrames.item (c).paragraphs.item (i) .silence;

    Remove the spaces and returns at the end:

    paragraphContent = paragraphContent.replace (/ \s+$ /, ");

    Replace the remaining spaces with hyphen:

    paragraphContent = paragraphContent.replace (/ \s + / g, '-');

    Make lowercase:

    paragraphContent = paragraphContent.toLowerCase ();

    Return paragraphContent;

    }

    }

    }

    Return paragraphContent;

    }

  • Scripts to insert metadata automatically to the document with the paragraph style

    Hello

    I am trying to find a way to insert automatically the metadata in my document through paragraph style in indesign cs5.5.

    It comes to myDocument title, author name , and description of myDocument.

    Is there anyone who can help me with this project?

    Thank you.

    Place the script at the following location: C:\Program Files\Adobe\Adobe InDesign CS6\Scripts\startup scripts

    If you close it document the script will automatically put the metadata in your indesign file (use ctrl + w or menu-> file-> the option close to close the file)

    Code:

    #targetengine session

    If you want to test the script for your active document, comment on the threshold of another, copy the script to your startup folder

    app.menuActions.itemByName ("Close").eventListeners.add ("beforeInvoke", function()

    {

    myDoc var = app.activeDocument;

    var docTitleText ="";

    var docDescripText ="";

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.findWhat = '. +';

    found = app.activeDocument.findGrep (true);

    for (j = found.length - 1; j > = 0; j-)

    {

    var foundText = .silence found [j];

    You can set several style of paragraph for the title of the Document

    if(found[j].texts[0].appliedParagraphStyle.Name=="docTitle1")

    {

    docTitleText = found .silence [j];

    }

    of other if(found[j].texts[0].appliedParagraphStyle.name=="docTitle2")

    {

    docTitleText = docTitleText + "" + found .silence [j];

    }

    of other if(found[j].texts[0].appliedParagraphStyle.name=="docTitle3")

    {

    docTitleText = docTitleText + "" + found .silence [j];

    }

    You can define several paragraph of Description of Document style

    of other if(found[j].texts[0].appliedParagraphStyle.name=="docDescription1")

    {

    docDescripText = found .silence [j];

    }

    of other if(found[j].texts[0].appliedParagraphStyle.name=="docDescription2")

    {

    docDescripText = docDescripText + "" + found .silence [j];

    }

    of other if(found[j].texts[0].appliedParagraphStyle.name=="docDescription3")

    {

    docDescripText = docDescripText + "" + found .silence [j];

    }

    }

    with (myDoc.metadataPreferences) {}

    author = "My Name";

    documentTitle = docTitleText;

    Description = docDescripText;

    }

    });

    Vandy

  • How to replace a paragraph with an object style style

    Hello

    I'm having this problem lately in the pagination of a newspaper that I have to do all the premium post with a Rectangle border. the problem is that the text is in the grid.

    Is it just as, while I add a paragraph style specific to certain parts of the text, I can automatically give this text a specific object (such as rectangle stroke) Style

    Does make sense?

    Thank you very much

    http://dtputils.com/products/view/1

    Maybe a plugin?

  • GREP find/replace + paragraph Styles

    Hello

    I'm editing a long document and have benefited from the assistance of the community already, but being new GREP Style, find/replace, I need to ask for additional help.

    Below a screenshot of the script (original). Two blocks of text you see anticipated by the icons have have styles of different paragraphs. Icons are placed like custom glyphs.

    Now, the last line with C2, 9, 14,... is the target of this post. They are buses of London and I created a paragraph with another icon. The copy that I work with unfortunately is as you see. Buses will follow «;»

    Resulting to place a \r after the semicolon and assign the new paragraph style. The item to work with is (probably) the last "," before the registration of the bus. All entries have it in the same way, where a search/replace global grep should work fine.

    My attempts:

    I used of a previous debate (? < =------;)) [^ ;] + $ to match everything from the end until the last semicolon, but then I found the problem preserving the matched characters and placing \r (using the (? < =-;). start at the beginning and stops at each point comma + space)

    So question: how to stop at the first semicolon at the end and replace the space with \r to create a new paragraph?

    Then, it is two question :-)

    From my previous attempts, I noticed that when you replace the semicolon + space with \r, and change the style of paragraph at a time (from Rail to Bus) caused the Rail paragraph style change (logic) to the style of Bus. So I tried to say the paragraph style of the track "Following paragraph Style is style of Bus" (and not to change the paragraph style in find/replace), but in a way that no longer works.

    Second question is: given to split the find/replace in two steps, how then transform / apply to newly created paragraph the correct style of Bus?

    Thank you in advance for your valuable assistance. So far, the community has been great!

    Antonio

    Original

    Screen Shot 2016-07-12 at 22.32.23.png

    Result for

    Screen Shot 2016-07-12 at 22.54.51.png

    Hi Antonio,.

    If I understand correctly, in 2 regex [1 click play with Multi/find-replace our friend Martinho da Gloria]:

Maybe you are looking for

  • Applications of gel in El Capitan on MacBook Mid 2010

    I find that some applications (Safari, reminders, Notes, etc.) are freeze after several hours of use.   Back on the MacBook gives solves problems, but only for about eight hours or more. The problem occurs even if I start the MacBook and not to use a

  • Where are stored e-mail messages Toshiba Windows 7?

    I have a Toshiba L650 with Windows 7 Home Premium 64-bit and Windows Live Mail. Despite trying all types of repair of Toshiba, can't do Windows and so my computer at startup (I think I downloaded a virus). I intend to transfer data to a memory stick,

  • I need a driver for hp deskjet f4280

    I need a driver for hp deskjet f4280

  • pictures and graphics are not displayed to the top

    I visited several sites and seen this problem. Some appear and others do not appear, even after right-clicking and then clicking see photo. Any suggestions? I don't know if it's the browser or the computer itself.

  • How to stop automatically rebuild the index

    How to stop windows from automatically rebuild the index; I am running vista sp2?  it restarts just as soon as he completed which makes my ability to get something useless