Deleting condition formats but saving the contents

Advocate ,
Feb 11, 2012 Feb 11, 2012

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

2.2K

Likes

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
Engaged ,
Feb 12, 2012 Feb 12, 2012

Copy link to clipboard

Copied

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

Likes

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
Advocate ,
Feb 12, 2012 Feb 12, 2012

Copy link to clipboard

Copied

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

Likes

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 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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;

}

Likes

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
Adobe Community Professional ,
Nov 24, 2014 Nov 24, 2014

Copy link to clipboard

Copied

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

Likes

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 Beginner ,
May 01, 2017 May 01, 2017

Copy link to clipboard

Copied

Ä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.

Likes

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
New Here ,
Jun 26, 2017 Jun 26, 2017

Copy link to clipboard

Copied

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

Likes

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
New Here ,
Jan 10, 2019 Jan 10, 2019

Copy link to clipboard

Copied

Would you please share your implementation of DeleteCondTag? I have tried this but it returns the FE_BadValue error. Here my simple code:

#target framemaker

var doc = app.ActiveDoc;

    $.writeln ("The document ID is: " + doc.id);

var textRange = doc.TextSelection;

var prop = doc.GetTextPropVal (textRange.beg, Constants.FP_InCond);

var condFmt;

for (var i = 0; i < prop.propVal.osval.length; i += 1) {

    condFmt = prop.propVal.osval;

    $.writeln ("The condition format name is: " + condFmt.Name);

    $.writeln ("The condition format ID is: " + condFmt.id);

    var delstat = condFmt.DeleteCondTag (doc.id, condFmt.id, Constants.FF_UNTAGGED_UNCOND);

    $.writeln ("The delete condition status is: " + delstat);

}

Any help would be appreciated ver much.

Russ

Likes

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
Explorer ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

Hi other Russ,

I have not used this myself and do not know the exact answer, but I can say that this line looks wrong:

    var delstat = condFmt.DeleteCondTag (doc.id, condFmt.id, Constants.FF_UNTAGGED_UNCOND);

Your parameters look like a series of FDK method arguments, which you don't need in ES because the object already knows all that stuff. Maybe it is just this:

    var delstat = condFmt.DeleteCondTag (Constants.FF_UNTAGGED_UNCOND);

Just a guess?

Russ

Likes

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
New Here ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

Hi, OtherRuss

Your suggestion worked perfectly!  Thank you so much.

I was simply following the syntax as given in the 2017 FrameMaker Scripting Guide (page 688)...

guide.png

I'm not sure what else a newbie like myself can do except rely on the kindness of members like yourself when the published info does not work.

Thanks again. You have given me the motivation to continue on.

Russ

Likes

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
Mentor ,
Jan 11, 2019 Jan 11, 2019

Copy link to clipboard

Copied

LATEST

It's all good. The few of us out here have all relied on each other at some point, newbies and advanced scripters alike. For obvious reasons. Stop by anytime.

Russ

Likes

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