Skip navigation
Currently Being Moderated

Associating a condition with a paragraph/char format

Jan 26, 2014 1:40 PM

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!

 
Replies
  • Currently Being Moderated
    Jan 26, 2014 3:27 PM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 27, 2014 4:46 AM   in reply to rombanks

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 27, 2014 6:07 AM   in reply to rombanks

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 27, 2014 6:26 AM   in reply to rombanks

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 27, 2014 4:55 PM   in reply to frameexpert

    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 "";
        }
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 3, 2014 7:31 AM   in reply to rombanks

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points