Back

If your email is not recognized and you believe it should be, please contact us.

Forum Replies Created

Viewing 15 posts - 31 through 45 (of 91 total)
  • Author
    Posts
  • in reply to: Script to insert grep style in all Paragraph styles #60853

    I forgot that the forum removes backslashes again.

    Here's another attempt:

    grepStyle.grepExpression = “Figure\d+\.\d+”;

    in reply to: Script to insert grep style in all Paragraph styles #60852

    Don't use Notepad to save scripts — use ExtendScript Toolkit instead.

    Use this grep-expression in the script then:

    grepStyle.grepExpression = “Figuresd+.d+”;

    which means word 'Figure' followed by a space, one ore more digit, a period and one ore more digit.

    in reply to: Script to change the language of all text on document #60834

    Here I posted some links for first-time scripters. From my own experience (I'm not a programmer by background), I can tell you that EVERYBODY can write scripts — the devil is not so terrible as he is painted!

    The most difficult is to make the first step. But when you make progress in it, another problem appears: you can't stop — scripting is very absorbing.

    On this site, I find a lot of information on how to use InDesign — both for beginners and advanced users. There are many “ready to use” scripts here as well. But I've never seen a scripting tutorial here and remember reading only one scripting trick lately.

    I think this is a big omission for indesignsecrets and suggest that a series of scripting lessons, tutorials, articles, tips & tricks, etc. should be started here on regular basis.

    in reply to: Script to insert grep style in all Paragraph styles #60833

    Query 2:

    Main();

    function Main() {
    var doc = app.activeDocument,
    parStyles = doc.paragraphStyles,
    swatch_1 = doc.swatches.item(“C=60 M=40 Y=0 K=0”),
    swatch_2 = doc.swatches.item(“C=15 M=100 Y=100 K=0”),
    i, parStyle;

    if (swatch_1.isValid && swatch_2.isValid) {
    for (i = 0; i < parStyles.length; i++) {
    parStyle = parStyles[i];
    if (parStyle.fillColor == swatch_1) parStyle.fillColor = swatch_2;
    }
    }
    else {
    alert(“A swatch doesn't exist.”);
    }
    }

    //———————————————–

    Query 1:

    I still don't understand what you want to achieve. Scripting grep style is quite straightforward — as in the user interface, you have to set only two parameters: appliedCharacterStyle (the character style applied to the text) and grepExpression (the GREP expression used to apply automatic styling).

    Probably, for the first parameter, you might want to use ^\d+ to apply the character style to any number of digits at the beginning of a line. I don't get what you mean by (Figure No : *) — a number followed by colon and some text?

    First you have to create and test a grep-expression in InDesign to make sure that it works as expected. Then you can copy and paste it to the script and escape backslashes (double them in script).

    Second parameter — character style:

    grepStyle.appliedCharacterStyle = doc.characterStyles.item(“Type in your character style here”);

    I used the following line in my example just to be on a safe side: if the character style doesn't exist in the document, create it, name it as “Figure numbers” and apply Bold to it. You can remove it if you're sure that the style is always present in the document, otherwise the script would throw an error.

    if (!charStyle.isValid) doc.characterStyles.add({name:”Figure numbers”, fontStyle:”Bold”});

    in reply to: Script to change the language of all text on document #60817

    Main();

    function Main() {
    if (app.documents.length == 0) {
    alert(“Please open a document and try again.”);
    exit();
    }
    var doc = app.activeDocument;
    app.findTextPreferences = app.changeTextPreferences = null;
    app.findTextPreferences.appliedLanguage = “English: USA”;
    app.changeTextPreferences.appliedLanguage = “English: UK”;
    doc.changeText();
    app.findTextPreferences = app.changeTextPreferences = null;
    }

    in reply to: Script to insert grep style in all Paragraph styles #60815

    What I posted is just an example of how to do this. I suppose that you want to write the script yourself and will modify the character style and the grep-expression according to your needs.

    If you want someone to write a script for you, you have to be more specific: tell us what InDesign version you are on, what character style and grep-expression you want to apply, etc.

    Yes, it's easy to make a script to change the font color of text in all the styles. What is the swatch name? Does it already exist in the document, or the script should create it if it doesn't exist yet?

    in reply to: Script to insert grep style in all Paragraph styles #60805

    I forgot that the forum removes backslashes — add two backslashes before d+.

    grepStyle.grepExpression = “\d+”;

    in reply to: Script to insert grep style in all Paragraph styles #60804

    Yes, it is. Here's an example:

    Main();

    function Main() {
    var doc = app.activeDocument,
    parStyles = doc.allParagraphStyles,
    charStyle = doc.characterStyles.item(“Figure numbers”),
    parStyle, i, grepStyle;

    if (!charStyle.isValid) doc.characterStyles.add({name:”Figure numbers”, fontStyle:”Bold”});

    for (i = 1; i < parStyles.length; i++) {
    parStyle = parStyles[i];
    grepStyle = parStyle.nestedGrepStyles.add();
    grepStyle.grepExpression = “d+”;
    grepStyle.appliedCharacterStyle = charStyle;
    }
    }

    The script adds a grep style to every paragraph style including styles in groups.

    in reply to: Simple relink script help! #60792

    #target indesign
    Main();

    function Main() {
    // the following 4 lines declare variables
    // usually I declare all vars at the beginning of the function
    // when you declare a variable with var, you limit its scope to the function
    // (making them local),
    // otherwise the scope is global which may cause you problems
    // a rule-of-thumb is to use global vars only you really need them
    var i, link, newFile,
    doc = app.activeDocument, // set variable doc to the front most document
    links = doc.links, // set variable links to collection of all links
    newPath = “/c/temp/newproject/”; // path to the folder
    for (i = links.length-1; i >= 0; i–) { // loop through all links backwards
    // from the last to the first item
    // it's very important when you modify or remove items from collection
    // to process them back to front, never use in such cases direct loop like so:
    // for (i = 0; i < links.length; i++) {
    link = links[i]; // set variable link to the current link
    newFile = new File(newPath + link.name); // create file object
    if (newFile.exists) link.relink(newFile); // relink only if the file exists
    try { // if memory serves me right, unlike CS3,
    // CS4 doesn't need update() command after using relink()
    // if you use it , it would cause an error
    // I use try-catch block to make the script compatible with CS3 and above
    // In other words, if an error occurs here, skip it over and go on
    link.update();
    }
    catch(err) {}
    }
    }

    The links placed more than once are far more difficult to deal with — in short, they should be processed separately.

    I can give you a few examples of how I do this:

    Resize images for Power Switch (see the SetLink100percent function — this is the latest algorithm I made)

    Relink Images and Apply “Rich Black” Color for Power Switch (see the RelinkLink function)

    Resize images

    in reply to: removing paragraph character styles #60784

    Try to select all text in the flow and choose Break Link to Style in the Paragraph (Character) Styles panel. Then Select All Unused and Delete.

    in reply to: Simple relink script help! #60782

    Oops! It removed them again. I guess, on this forum, we should type two backslashes for one, and four for two.

    in reply to: Simple relink script help! #60781

    Yes, it is. Forward slashes work as well:

    newPath = “c:/temp/newproject/”;

    What I mean is that backslash is the escape character, so we must use a double backslash to indicate it. In the original post I see single backslashes:

    myNewPath = 'c:tempnewproject'

    Probably, initallly they were there, but the forum software removed them.

    in reply to: Simple relink script help! #60778

    In my previous post, forum software ate up double backslashes.
    It should be:

    newPath = 'c: backslash backslash temp backslash backslash newproject backslash backslash ';

    in reply to: Place image and change position? #60777

    You can also place an image on page specifying the second (optional) parameter – placePoint.

    in reply to: Simple relink script help! #60776

    Hi Ivan,

    It doesn't work because you made too many mistakes in your code.

    #target indesign
    var i, link, newFile,
    doc = app.activeDocument,
    links = doc.links,
    newPath = “/c/temp/newproject/”;

    for (i = links.length-1; i >= 0; i–) {
    link = links[i];
    newFile = new File(newPath + link.name);
    if (newFile.exists) link.relink(newFile);
    try {
    link.update();
    }
    catch(err) {}
    }

    BTW if you want to use Windows path names, you should escape backslashes:

    newPath = 'c:tempnewproject';

    I prefer URI path names:

    newPath = “/c/temp/newproject/”;

    Hope this helps.

    Kasyan

    P.S. I don't hang out on Adobe forums any more because they blocked access from my country. If you have more questions to me about scripting links (it's quite a tricky business), feel free to ask them here.

Viewing 15 posts - 31 through 45 (of 91 total)