Skip to main content
Deefadog
Participant
February 28, 2024
Question

Can you change the appearance of multiple checkboxes the same time in an indesign document

  • February 28, 2024
  • 1 reply
  • 503 views

Hi all, I have several indesign projects of 8 pages that have been previously created, each project has around 100 checkboxes. I need to change the appearance of all the checkboxes, I there an easy way to do this - Change them all at the same time? or do I have to manually copy and paste the new checkbox (With the changed appearance) for each one?

Thanks in advance.

This topic has been closed for replies.

1 reply

m1b
Community Expert
Community Expert
February 28, 2024

Hi @Deefadog, try this script I wrote. But there's a little preparation first:

 

1. Open all your eight documents.

2. Create an object style that styles a checkbox they way you want.

3. Copy that object style into all your documents (eg. paste and then delete a checkbox into each.)

4. Edit my script, this line:

var objectStyleName = 'Put the name of your style here!'

5. Run my script (listed below).

 

Let me know how you go.

- Mark

 

/**
 * Apply object style to all checkBoxes of all open documents.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/scripting-find-all-form-fields-and-remove/m-p/14000885
 */
function main() {

    // you must specify the name of your object style:
    var objectStyleName = 'My Style';

    var thingPlural = 'checkBoxes',
        docs = app.documents,
        counter = 0;

    for (var i = docs.length - 1; i >= 0; i--) {

        if (!docs[i].saved)
            continue;

        var doc = docs[i],
            things = doc[thingPlural].everyItem().getElements(),
            objectStyle = getThing(doc.allObjectStyles, 'name', objectStyleName);

        if (undefined == objectStyle) {
            alert('Sorry no object style "' + objectStyleName + '" found in document "' + doc.name + '".');
            continue;
        }

        if (doc.groups.length > 0)
            // also collect things in groups
            things = things.concat(doc.groups.everyItem()[thingPlural].everyItem().getElements());

        if (doc.stories.length > 0) {

            // also collect any anchored things
            things = things.concat(doc.stories.everyItem()[thingPlural].everyItem().getElements());

            if (doc.stories.everyItem().tables.length > 0)
                // also collect any thing in tables
                things = things.concat(doc.stories.everyItem().tables.everyItem().cells.everyItem()[thingPlural].everyItem().getElements());
        }

        // apply the object style
        for (var j = things.length - 1; j >= 0; j--) {
            if (things[j].isValid) {
                things[j].applyObjectStyle(objectStyle, true, false);
                counter++;
            }
        }

    }

    alert('Applied object style to ' + counter + ' checkboxes.');

} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Apply Object Style to CheckBoxes');


/**
 * Returns a thing with matching property.
 * @param {Array|collection} things - the things to look through, eg. PageItems.
 * @param {String} key - the property name, eg. 'name'.
 * @param {*} value - the value to match.
 */
function getThing(things, key, value) {

    for (var i = 0; i < things.length; i++)
        if (things[i][key] == value)
            return things[i];

};

 

Deefadog
DeefadogAuthor
Participant
February 28, 2024

m1b, you're a genius! If you attending Adobe Max later this year, i will buy you a drink or several for sure!

It does work with the styles perfectly! But it does not bring across the appearance settings of that check box, which are: Normal On - Normal off - Click On - Click Off.
I guess as these are not a style more an interactive function?

I am not sure if they can be implemented into the script?

Robert at ID-Tasker
Legend
February 28, 2024

@Deefadog 

 

CheckBox have few a collection o States - but I dont see there what you've listed?

 

StateTypes.DOWN

StateTypes.DOWN_OFF

StateTypes.DOWN_ON

StateTypes.ROLLOVER

StateTypes.ROLLOVER_OFF

StateTypes.ROLLOVER_ON

StateTypes.UP

StateTypes.UP_OFF

StateTypes.UP_ON

 

Or Normal would be UP and Click would be DOWN?

 

If those are correct ones - then it can be scripted.