Skip to main content
Participant
August 19, 2022
Question

Delete a Conditional tag in a Book - Script

  • August 19, 2022
  • 3 replies
  • 276 views

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 has been closed for replies.

    3 replies

    frameexpert
    Community Expert
    Community Expert
    August 19, 2022

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

    LinSims
    Community Expert
    Community Expert
    August 19, 2022
    Matt-Tech Comm Tools
    Community Expert
    Community Expert
    August 19, 2022

    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.

    -Matt Sullivan, FrameMaker Course Creator, Author, Trainer, Consultant
    Participant
    August 20, 2022

    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!

    Participant
    August 19, 2022

    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 ();
    }

    LinSims
    Community Expert
    Community Expert
    August 19, 2022

    Merging into duplicate thread.

     

    Do not post multiple threads on the same topic.