It is easy to delete Condition Formats from a FrameMaker document in the interface. If you try to delete a Condition Format that is use, you will be prompted on what to do to the conditionalized text:
With ExtendScript, things aren’t so easy. If you delete a Condition Format programmatically, the conditionalized content is always deleted along with the format. There is no “option” on the Delete function to make the text unconditional. If you want to keep the text, you will have to remove the Condition Format from any text (and table rows) where it is applied.
A couple of preliminary things: First of all, you should show all of the conditions at the beginning of your code. You can store the current ShowAll setting so you can restore it later. Second, if you do want to delete the text and rows with the Condition Format, just delete the Condition Format (CondFmt):
#target framemaker var doc = app.ActiveDoc; // Store the current ShowAll setting and show all conditions. var showAll = doc.ShowAll; doc.ShowAll = 1; // Get the CondFmt object and delete it (and any text and rows) from the document. var condFmt = doc.GetNamedCondFmt ("Comment"); if (condFmt.ObjectValid () === 1) { condFmt.Delete (); } // Restore the document's ShowAll setting. doc.ShowAll = showAll;
To see how to remove Condition Formats from text, make a sample document and add two Condition Formats to it, Condition1 and Condition2. Apply both conditions to a single paragraph. Select part of the paragraph and run this code:
#target framemaker var doc = app.ActiveDoc; var textRange = doc.TextSelection; var prop = doc.GetTextPropVal (textRange.beg, Constants.FP_InCond); alert (prop);
This will show us a PropVal object that has information about the Condition Formats (if any) that are applied to the text. Run the following code to see the properties of the PropVal object.
#target framemaker var doc = app.ActiveDoc; var textRange = doc.TextSelection; var prop = doc.GetTextPropVal (textRange.beg, Constants.FP_InCond); // Use the ExtendScript reflection interface to see the properties. alert (prop.reflect.properties);
The propIndent value is the kind of property it is (FP_InCond), while the propVal properties has specific information about the Condition Formats that are applied. Let’s poke further down and look at the propVal properties with this code:
#target framemaker var doc = app.ActiveDoc; var textRange = doc.TextSelection; var prop = doc.GetTextPropVal (textRange.beg, Constants.FP_InCond); // Use the ExtendScript reflection interface to see the properties. alert (prop.propVal.reflect.properties);
As you can see, the propVal property has a lot of child properties. For Condition Formats, we are interested in the osval property. Make sure your conditional text is still selected and run this code:
#target framemaker var doc = app.ActiveDoc; var textRange = doc.TextSelection; var prop = doc.GetTextPropVal (textRange.beg, Constants.FP_InCond); alert (prop.propVal.osval);
You should see a dialog box like this:
The osval property is an array-like list of the CondFmt objects that are applied to the text. If there is no CondFmts applied, this osval list will be empty. Because this list is similar to an array, we can loop through it to look at the individual CondFmt objects.
#target framemaker var doc = app.ActiveDoc; 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[i]; alert (condFmt.Name); }
When you run this code, you should see the name of each CondFmt displayed in a dialog box. You can probably see what we need to do here. Assuming that we want to remove Condition2 from the text, we need to figure out how to remove the Condition2 CondFmt object from the osval list. Once we do that, we can take the modified PropVal and apply it back to the text, which will remove the unwanted Condition Format. We will explore that in Part 2.