Skip to main content
4everJang
Legend
February 11, 2012
Question

Deleting condition formats but saving the contents

  • February 11, 2012
  • 2 replies
  • 2933 views

Hello all,

I hope someone from Adobe is monitoring this list, as there is lots of stuff that requires either more work on the ExtendScript coding or on the documentation.

I have almost finalized my conversion from unstructured FrameMaker documents with lots of conditional texts to structured FrameMaker, in which attributes take over the role of the conditions. I now want to delete the condition formats but keep the contents. This is possible via the menu: when I delete a condition format, I get a dialog that allows me to keep the content as unconditional text instead of throwing it out. Guess what ? The Delete() method for a CondFmt object does not take any arguments, and the default method is throwing out the content.

I can do a TextSelection on everything in the document and apply unconditional formatting to it, but that does not include the text in tables. And it is a hassle, as there should really be a way to tell the Delete() method for CondFmt what to do with the content. The options in the dialog should be available via ExtendScript somehow.

Thanks in advance for a quick reply. My deadline is approaching quickly !

Jang

This topic has been closed for replies.

2 replies

frameexpert
Community Expert
Community Expert
November 24, 2014

Hi Jang, I had to do this in a production script last week, so I decided to provide some details on my blog. The first two posts just have the basics. When I have time, I will extend the example so it can be applied to a document. Please let me know if you have any questions or comments. - Rick

Removing Conditions From Text and Table Rows | FrameAutomation.com

www.frameexpert.com
Participating Frequently
May 1, 2017

Ähm. I just found out that for the CondFmt object there's a DeleteCondTag(action) method in FM11 and higher. The action Parameter of the method can be set to Constants.FF_UNTAGGED_UNCOND to get the desired behaviour of making text which has the CondFmt applied unconditional. I wonder if this wouldn't considerably simplify the code.

Participant
June 26, 2017

Works for me! excellent solution !
Please follow this franz's solution if you are using FM 11 or newer.

Inspiring
February 12, 2012

Hi Jang,

Delete() on Condition Formats only deletes the format definition. It doesn't change anything in a text flow.

You have to search the document for condtions. It is property InCond. This property is defined on

- document level

- table row level

- text item level

FP_InCond delivers an array of conditions apply to a certain object (document, table row, text item.

There is a sample how to apply a new condition format to a text selection in FDKRef.pdf at function F_ApiSetInts. So if you apply an empty Array to FP_InCond, the conditions are removed.

This should work something like this.

1. app.ActiveDoc.InCond = new Ints() ;

2. row.InCond = new Ints() ;

3. var prop = app.ActiveDoc.GetTextPropVal (textRange.beg, Constants.FP_InCond);

    prop.propval.osval = new Ints() ;

    app.ActiveDoc.SetTextPropVal (textRange, prop);

You can get conditioned text in a paragraph like that:

    var textItems = pgf.GetText (Constants.FTI_CharPropsChange);

    for (var i = 0 ; i < textItems.length ; i++)

    {

        var item = textItems ;

        if ((item.idata &  Constants.FTF_CONDITIONTAG)==false)

               continue;

        //Condition changed found

    }

BTW: Take a look at http://www.finalyser.com. There is an ExtendScript to do this (and more) on all opened books and documents.

Hope this helps

Markus

4everJang
4everJangAuthor
Legend
February 13, 2012

Hi Markus,

I was more or less afraid that it would come to this: a lot of extra scripting because an option from the dialog is missing in ExtendScript. Oh well. I will tell my customer it will be a little more work. Maybe they will take pity on me and extend the paycheck...

Ciao

Jang

February 17, 2012

This problem has been driving me crazy for weeks, and I'm pleased to finally declare victory.

The main snarl I ran into was the propVal.osval, which uses an (undocumented) array data type named Objects to hold the CondFmt objects, and it has no constructor, so it's not easy to reset. You can reset the isval all day long without effect, and building your TextPropVal from scratch has a nasty habit of crashing Frame. It's late here, so please excuse the uncommented code, but the following will make all text in your main flow unconditional, allowing you to delete your CondFmts without deleting the text.

var findProps, foundRange, foundCond;

var doc = app.ActiveDoc;

var firstPgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

var docStart = new TextLoc(firstPgf,0);

var currCondFmt = doc.FirstCondFmtInDoc;

var findProps = AllocatePropVals(1);

          findProps[0].propIdent.num = Constants.FS_FindCondTextInCondTags;

          findProps[0].propVal.valType = Constants.FT_Strings;

          findProps[0].propVal.ssval[0]= currCondFmt.Name;

 

while (currCondFmt.ObjectValid()){

          foundRange = doc.Find (docStart, findProps);

                    while (foundRange.beg.obj.ObjectValid())

                    {

                    foundCond = doc.GetTextPropVal (foundRange.beg, Constants.FP_InCond);

                    foundCond.propVal.isval = new Ints();

                    while(foundCond.propVal.osval.length>0)

                              {

                                        foundCond.propVal.osval.pop();

                                        }

                    doc.SetTextPropVal (foundRange, foundCond);

                    foundRange = doc.Find (docStart, findProps);

                    }

          currCondFmt = currCondFmt.NextCondFmtInDoc;

          findProps[0].propVal.ssval[0]= currCondFmt.Name;

}