Skip to main content
Known Participant
March 5, 2025
Question

Hi character.remove() is crashing the Indesign server.

  • March 5, 2025
  • 2 replies
  • 1321 views
    function removeBoundaryMarkers(document) {
        try {
            logMsg(logFile, "Fetching marker style: " + MARKER_STYLE_NAME);
            // Find our specific marker style
            var markerStyle = document.characterStyles.itemByName(MARKER_STYLE_NAME);
            if (!markerStyle.isValid) {
                return;
            }

            logMsg(logFile, "Resetting findGrepPreferences and changeGrepPreferences");
            app.findGrepPreferences = NothingEnum.NOTHING;
            app.changeGrepPreferences = NothingEnum.NOTHING;



            // Find all hair spaces
            logMsg(logFile, "Setting findGrepPreferences.findWhat");
            app.findGrepPreferences.findWhat = BOUNDARY_MARKER;



            // Remove them if they have the specific style
            logMsg(logFile, "Executing findGrep");
            var foundItems = document.findGrep();
            logMsg(logFile, "Found " + foundItems.length + " items to check and remove");
            for (var i = foundItems.length - 1; i >= 0; i--) {
                if (foundItems[i].appliedCharacterStyle == markerStyle) {
                    logMsg(logFile, "Removing marker : "+i);
                    if (foundItems[i].contents.length > 0) {
                        foundItems[i].remove();
                    }
                }
            }

            // Clean up the style
            logMsg(logFile, "Removing marker style");
            markerStyle.remove();
        } catch (e) {
            logMsg(logFile, "Error removing boundary markers: " + e.message);
        }
    }
            }

This funtion just gets the Hair Space content and compares with specific chracter style, and removes the character. But, the issue im facing is foundItems, is gettign around 130 characters, able to remove from 130 till 91 but at 90th character, when foundItems[i].remove(); InDesign server crashes. What could be the issue.
 

2 replies

Robert at ID-Tasker
Legend
March 5, 2025

@adarsh_0848

 

Why do you have to iterate through all results - instead of doing Find&Change?

 

Known Participant
March 5, 2025

I dont want to change all the found Charcters, In my Codebase I have created custom character style and applied to Characters for processing some other functionality (which I have not shared here). But Conclusion is I want to remove characters with perticular character style . if (foundItems[i].appliedCharacterStyle == markerStyle)

Robert at ID-Tasker
Legend
March 5, 2025

But you're looking for a specific marker: 

 

app.findGrepPreferences.findWhat = BOUNDARY_MARKER; 

 

So if you'll combine this marker WITH specific CharStyle - you can use Find&Change to remove ONLY instances where this specific marker has this specific CharStyle applied. 

 

Peter Kahrel
Community Expert
Community Expert
March 5, 2025

I've seen this a few times at the level of story, maybe the underltying problem is the same as with character. Anyway, try

 

foundItems[i].contents = ''

 

 

Known Participant
March 5, 2025

But this wont cause any issue right. as we are just assigning '' empty character and not removing the character itself.

Peter Kahrel
Community Expert
Community Expert
March 5, 2025

character.remove() and character.contents = '' are equivalent. They have the same effect. It won't cause any problems. Just try it.