Skip to main content
Participant
Aug 19, 2022 11:24 AM UTC
Question

Delete a Conditional tag in a Book - Script

Hi,

 

I want to delete certain conditional tags for all files in a Book without having to delete the tags file by file.

However, I couldn't find an easy batch function in FM interface.

With references from other scripts, I wrote this script to delete specified conditional tags in a Book.

The script is only available to delete an unused Cond tag you specified, not considering the cases that the tag is used in expressions or applied to the text. (Violent lol)

However,  I am not sure if  this would ruin the conditional tag structure in FM.

Does anyone have experience on this?

It will be great if someone would help check this script and share your experiences on this.

(or you have other tips on deleting cond tags?)

Many thanks.

----------------------------------------------------------------------------------------------

var book = app.ActiveBook;
var Condname=prompt("Please enter the condition tag you want to delete");//user input cond name
if (Condname!=null){
alert(Condname);

var comp = book.FirstComponentInBook;


/*go through files*/
while(comp && comp.ObjectValid() ){
alert (comp.Name);
var openedBook = OpenFile(comp.Name, false);
if(openedBook.ObjectValid())
DeleCond(openedBook, Condname);//call the DeleCond function
comp = comp.NextBookComponentInDFSOrder;
}

 

function DeleCond(doc, Condname){
doc.ShowAll = 1;//show all
var condFmt = doc.GetNamedCondFmt (Condname);
if (condFmt.ObjectValid () == 1) 
     condFmt.Delete ();
}

    This topic is closed to new replies. Start a new post to keep the conversation going.

    6 replies

    frameexpert
    Community Expert
    Community Expert
    Aug 19, 2022 4:13 PM UTC

    A big caution here: Deleting a condition tag will delete any text that has this condition applied.

    Translate
    www.frameexpert.com
    LinSims
    Community Expert
    Community Expert
    Aug 19, 2022 12:24 PM UTC

    Rick Quatro's FindChangeFormatsBatch plugin does this, in bulk even.  http://www.frameexpert.com/store/#:~:text=for%20only%20%24169!-,FindChangeFormatsBatch,-FindChangeFormatsBatch%20is%20a

     

    Translate
    Matt-Tech Comm Tools
    Community Expert
    Community Expert
    Aug 19, 2022 4:52 PM UTC

    Echoing Lin's reply...

    Purchasing Rick's FindChangeFormatsBatch at frameexpert.com will be a fraction of the effort (and cost, in terms of hours) that you'll spend developing your own script to do this.

    Additionally, you'll get access to changing/removing a half dozen other styles/template components.

    Translate
    -Matt Sullivan, FrameMaker Course Creator, Author, Trainer, Consultant
    Participant
    Aug 20, 2022 10:36 AM UTC

    I was just getting into FM scripting and trying to write my first FM script though:) I did know Rick has lots of powerful scripts. You're right, FindChangeBatch should really save the scripting time and also support other powerful functions. I would  check that out. Thanks for the suggestion!

    Translate
    Participant
    Aug 19, 2022 11:24 AM UTC

    Hi,

     

    I want to delete certain conditional tags for all files in a Book without having to delete the tags file by file.

    However, I couldn't find an easy batch function in FM interface.

    With references from other scripts, I wrote this script to delete specified conditional tags in a Book.

    The script is only available to delete an unused Cond tag you specified, not considering the cases that the tag is used in expressions or applied to the text. (Violent lol)

    However,  I am not sure if  this would ruin the conditional tag structure in FM.

    Does anyone have experience on this?

    It will be great if anyone would help check this script and share your experiences on this.

    (or you have other tips on deleting cond tags?)

    Many thanks.

    ----------------------------------------------------------------------------------------------

    var book = app.ActiveBook;
    var Condname=prompt("Please enter the condition tag you want to delete");//user input cond name
    if (Condname!=null){
    alert(Condname);

    var comp = book.FirstComponentInBook;


    /*go through files*/
    while(comp && comp.ObjectValid() ){
    alert (comp.Name);
    var openedBook = OpenFile(comp.Name, false);
    if(openedBook.ObjectValid())
    DeleCond(openedBook, Condname);//call the DeleCond function
    comp = comp.NextBookComponentInDFSOrder;
    }

     

    function DeleCond(doc, Condname){
    doc.ShowAll = 1;//show all
    var condFmt = doc.GetNamedCondFmt (Condname);
    if (condFmt.ObjectValid () == 1) 
         condFmt.Delete ();
    }

    Translate
    LinSims
    Community Expert
    Community Expert
    Aug 19, 2022 3:50 PM UTC

    Merging into duplicate thread.

     

    Do not post multiple threads on the same topic.

    Translate