Skip to main content
Inspiring
May 14, 2025
Answered

Script to remove selected change bar

  • May 14, 2025
  • 2 replies
  • 894 views

I'm looking for a way to remove a single change bar from the document using a script.

 

I can do this manually, using Esc c h - Format>Style>Change Bar.

 

Usually, I have to do this twice - partly b/c I'm not sure what text set the change bar initially, so I select beyond the text with the change bar, run the command (which sets the text as change bar text), and then run the command again (which removes the new and the original change bars.)

 

Per the documentation:

Fcodes ([FCodes.TXT_CHANGEBAR]);

should work, but it doesn't seem to. I thought I would have to run it twice, but it doesn't even create the change bar if I run it once.

Fcodes ([FCodes.TXT_BOLD]); does work so the syntax is correct.

 

Am I doing something wrong, or is there a better way to do this?

 

I haven't tried yet, but I might be able to ADD a change bar via script by turning on automatic change bars, adding a space, removing the added space, and turning automatic change bars back off.

 

The bigger issue is removing the change bars. If it can't be done, is there a way to script the Format>Style Drop-down being selected?

 

In case anyone needs it, I found out I can turn on and off automatic change bars with:

doc.AutoChangeBars=1 or doc.AutoChangeBars=0

and I can remove ALL change bars with:

doc.ClearAllChangebars();

 

 

Correct answer Marshall_Brooks

It looks like you figured it out. You could generalize the function to either add or remove change bars.

var doc, textRange;

doc = app.ActiveDoc;
textRange = doc.TextSelection;
applyOrRemoveChangeBar (textRange, 0, doc); // 0 remove; 1 apply

function applyOrRemoveChangeBar (textRange, value, doc) {
    
    var prop;
        // Make a property list containing the change bar.
        prop = new PropVal ();
        prop.propIdent.num = Constants.FP_ChangeBar;
        prop.propVal.valType = Constants.FT_Integer;
        prop.propVal.ival = value;
        // Apply the property to the text.
        doc.SetTextPropVal (textRange, prop);    
} // End applyOrRemoveChangeBar

@frameexpert - Is there any chance that value is a reserved word in Extendscript? I tried your code above and it works for removing a change bar (my main concern), but does NOT work for adding one.

This works though:

var doc, textRange;

doc = app.ActiveDoc;
textRange = doc.TextSelection;
applyOrRemoveChangeBar (textRange, 1, doc); // 0 remove; 1 apply

function applyOrRemoveChangeBar (textRange, AppRem, doc) {
    
    var prop;
        // Make a property list containing the change bar.
        prop = new PropVal ();
        prop.propIdent.num = Constants.FP_ChangeBar;
        prop.propVal.valType = Constants.FT_Integer;
        prop.propVal.ival = AppRem;
        // Apply the property to the text.
        doc.SetTextPropVal (textRange, prop);    
} // End applyOrRemoveChangeBar

 

 

2 replies

frameexpert
Community Expert
Community Expert
May 14, 2025

Change Bar is a character property so it can be applied to one or more text characters. So first you have to find the character(s) that have the Change Bar property applied and then remove it. It's similar to what you did with the color property in one of your other posts.

Inspiring
May 14, 2025

@frameexpert  - Thank you.

Color property: https://community.adobe.com/t5/framemaker-discussions/script-to-change-red-text-to-black/td-p/15293234

Based on the above, I would think this would work:

var doc, textRange;

doc = app.ActiveDoc;
textRange = doc.TextSelection;


function applyChangeBar (textRange, doc) {
    
    var prop;
        // Make a property list containing the change bar.
        prop = new PropVal ();
        prop.propIdent.num = Constants.FP_Changebar;
        prop.propVal.valType = Constants.FT_Integer;
        prop.propVal.ival = 1;
        // Apply the property to the text.
        doc.SetTextPropVal (textRange, prop);    
} // End applyChangeBar

It doesn't give me an error, but it doesn't show or remove the change bar either.

 

I'm assuming like the color property, I don't have to actually find the affected text. For example if "This text" in "This text has a change bar." had the change bar property applied, I assume I could highlight the entire row and de-apply the change bar. That's basically how we do it manually.

 

Follow-up: How would I know when to use .ival, or .sval, or .obj, and what to put for the values. I'm guessing it's somewhere in the FDK and I wasn't able to download that.

 

Inspiring
May 15, 2025

@frameexpert It works!!! - I figured it out!!!

var doc, textRange;

doc = app.ActiveDoc;
textRange = doc.TextSelection;

RemoveChangeBar (textRange, doc);


function RemoveChangeBar (textRange, doc) {
    
    var prop;
        // Make a property list containing the change bar.
        prop = new PropVal ();
        prop.propIdent.num = Constants.FP_ChangeBar;
        prop.propVal.valType = Constants.FT_Integer;
        prop.propVal.ival = false;
        
        // Apply the property to the text.
        doc.SetTextPropVal (textRange, prop);    
} // End RemoveChangeBar

I'll make a new post on how I got here soon, but it wasn't that easy ...

Inspiring
May 14, 2025

@frameexpert - From your font color post, I tried this, but it gave me a bad argument value:

function applyChangeBar (textRange, doc) {
    
    var prop;
        // Make a property list containing the property.
        prop = new PropVal ();
        prop.propIdent.num = Constants.FP_Changebar;
        prop.propVal.valType = Constants.FT_Integer;
        prop.propVal.obj = 1;
        // Apply the property to the text.
        doc.SetTextPropVal (textRange, prop);    
} // End applyChangeBar
frameexpert
Community Expert
Community Expert
May 14, 2025

Instead of prop.propVal.obj, try prop.propVal.ival.