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

Associating a condition with a paragraph/char format

Participant ,
Jan 26, 2014 Jan 26, 2014

Copy link to clipboard

Copied

Hello fellows,

I wonder if there is a way to automatically apply a certain condition to a specific type of a paragraph/character thru an event script.

Thank you in advance!

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

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 ,
Jan 26, 2014 Jan 26, 2014

Copy link to clipboard

Copied

Your best bet is to follow the advice I posted on my blog:

http://frameautomation.com/run-a-script-in-response-to-a-command/

Install the "test" event script that will display an integer whenever you perform a function. Try applying paragraph formats in various ways and see if you get a consistent number. If you do, you can modify the event script to test for that particular function number. Then, when that number is triggered, test the paragraph format of the current paragraph and apply the appropriate condition format. If you detect a different format, you may want to call a function that will remove the condition format if it is applied. Please let me know if this is not clear. Thanks.

Rick

Votes

Translate

Translate

Report

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
Participant ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

Hi Rick,

Thank you very much for your response! Unfortunately, when applying a Pgf format, I am getting a well-known error - [object InvalidObject].

Please, advise!

My best regards,

Roman

Votes

Translate

Translate

Report

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 ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

Hi Roman, OK, here is a way you might be able to work around this. It is going to take more code, but it should work. Remember that with many events, there is a "Pre" event that corresponds to the "Post" event. So you could monitor the "Pre" side of the function event (FA_Note_PreFunction) and store the paragraph format of the current paragraph. Then when the FA_NotePostFunction event is triggered, again test the paragraph format of the current paragraph. If it has changed, then you know that a paragraph format has been applied. Then you can apply your condition.

A couple of notes: You will have to store the paragraph format name in a global variable so that it will still be available when the Post event is triggered. Also, this type of script will be "expensive" because it will get executed regardless of the function that is invoked. In practice, though, you may not notice any performance degredation. Please let me know if you have any questions or comments.

Rick

Votes

Translate

Translate

Report

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
Participant ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

Hi Rick,

Thank you for the suggestion! I don't understand how I can make sure that the condition is applied to a specific Pgf format when using this method. Please, clarify.

Thank you!

Roman

Votes

Translate

Translate

Report

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 ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

In your code, you test for the paragraph format of the current paragraph. If it is the one that should have the condition, you apply it. If not, you ignore it.

Votes

Translate

Translate

Report

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
Participant ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

Hi Rick,

Adding a case for FA_Note_PreFunction yields the same error message. I am probably missing something. Please, advise. I remember it worked for you in FM11 but not in FM10.

Thank you!

Roman

Votes

Translate

Translate

Report

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 ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

You are no longer going to test for the function number because it does not work with FM 10. Instead, you are going to test for the paragraph format of the paragraph containing the cursor, and you are going to store this in a variable. Then when the Post event is triggered after the function, you are going to test for the paragraph format of the paragraph containing the cursor and compare it to the value stored in the variable. If it is different, then you know that the function was a paragraph format change. If the format has been changed to one that requires a condition, you apply it.

Votes

Translate

Translate

Report

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 ,
Jan 27, 2014 Jan 27, 2014

Copy link to clipboard

Copied

See if the code below makes sense to you.

#target framemaker

var pgfName; // Global variable.
setupNotifications ();

function setupNotifications () {
   
    // Set notifications for before and after functions.
    Notification(Constants.FA_Note_PostFunction, true);
    Notification(Constants.FA_Note_PreFunction, true);

}

function Notify (note, object, sparam, iparam) {
   
    // Handle the pre- and post-function events.
    switch (note) {
        case Constants.FA_Note_PreFunction :
            if (object.constructor.name === "Doc") {
                 pgfFmtName = getPgfFmtName(object);
            }
        break;
       
        case Constants.FA_Note_PostFunction :
            if (object.constructor.name === "Doc") {
                alert (pgfFmtName); // Paragraph format name before function.
                alert (getPgfFmtName(object)); // Paragraph format name after function.
            }
        break;

    }
}

function getPgfFmtName (doc) {
   
    var pgf = doc.TextSelection.beg.obj;
    if (pgf.ObjectValid() === 1) {
        return pgf.Name;
    }
    else {
        return "";
    }
}

Votes

Translate

Translate

Report

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
Participant ,
Jan 28, 2014 Jan 28, 2014

Copy link to clipboard

Copied

Hi Rick,

First of all, thank you for writing this script! It helped me learn more about Extendscript. I am surprised that Adobe haven't released any ES documentation yet - real shame. Yesterday, I spent quite a lot of time looking for a function that selects the current paragraph. And guess what - I could not find it in the ES data browser (which is not user friendly at all).

The above script displays the name of the previous and current Pgf format, which is already something to start with.

Now come the questions:

1. "function Notify" is not explicitly called in this script. So, how does it work?

2. object.constructor.name === "Doc" - It's not clear to me what this is supposed to do. Why is it "Doc" and not "doc"?

3. getPgfFmtName(object) - Why does a call to this function contain an "object" as an argument, while in the function definition, it is "doc"?

4. What's the code for applying a condition to doc.TextSelection?

Thank you for your explanations in advance!

Roman

Votes

Translate

Translate

Report

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
Participant ,
Feb 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

Hi Rick,

Did you have a chance to look at my questions?

Thanks!

Roman

Votes

Translate

Translate

Report

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 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

Hi Roman, I am sorry, but I have been very busy and haven't had time to answer your questions. Do you have any budget for training or script help? We could schedule a web meeting where I could answer your questions and help you get this done. My basic rate is $100/hour. I would love to provide free help, but I am not always able to. --Rick

Votes

Translate

Translate

Report

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
Participant ,
Feb 03, 2014 Feb 03, 2014

Copy link to clipboard

Copied

LATEST

No problem, Rick. I am glad to hear that you are busy. Thanks again for the help you had provided so far!

My best wishes,

Roman

Votes

Translate

Translate

Report

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