Mobile app version of vmapp.org
Login or Join

Login to follow query

More posts by @RJPawlick971

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ann6370331

If you need a more fine grained search engine you could also use the FindChange capabilities built into InDesign (you still need a little bit of code to delete all the objects though).

You can set the object style to search for or just specific properties in the FC panel and get all the found elements with this little script snippet.

app.doScript(function() {
var objectsList = app.findObject();
for (var i = objectsList.length -1; i >=0 ; i --){
objectsList[i].remove()
}
}, ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, 'Object removal via script');


Update 2018-01-15: Make it a one step undo mode

10% popularity Vote Up Vote Down


 

@Alves566

This little script should do the job.

The main functionality of the script (the first part) is commented and quite simple (if you know javascript). I have added a small input dialog to make the script easy to use, but I haven't commented that part of the code.

Copy the code below to a text editor and save it as a .jsx file (for example RemoveAllObjectsWithACertainObjectStyle.jsx) in the folder for user scripts.

In InDesign, run the script and a dialog box will appear. Choose which Object Style to remove and press "OK".

Does this work for you?



// REMOVE ALL OBJECTS WITH A CERTAIN OBJECT STYLE
// Copyright (c) 2018 Mads Wolff
// This script is distributed under the MIT License.


// MAIN FUNCTIONALITY

// Make a reference to the Object Styles of the active document.
var objectStyles = app.activeDocument.objectStyles;

// Make a reference to the Page Items of the active document.
var pageItems = app.activeDocument.allPageItems;

// Removes all Objects with a certain Object Style.
// Takes 2 arguments:
// objectStyleName the name of the Object Style
// removeFrom the kind of Spreads to apply to (0: all, 1: only normal Spreads, 2: only Master Spreads)
function removeAllObjectsWithACertainObjectStyle(objectStyleName, removeFrom) {

// Iterate through the Page Items.
// (Since we are going to delete some of the items while iterating, we need to "loop backwards".)
for (i = pageItems.length- 1; i >= 0; i--) {

// Make a reference to the Page Item.
var pageItem = pageItems[i];

// Make a reference to the Page Item's Spread type
var spreadType = pageItem.parentPage.parent.constructor.name;

// Check if the Page Item has the right Object Style and Spread type.
if (
pageItem.appliedObjectStyle.name === objectStyleName &&
(removeFrom === 0 || (removeFrom === 1 && spreadType === "Spread") || (removeFrom === 2 && spreadType === "MasterSpread"))
) {

// Remove the Page Item.
pageItem.remove();

}

}

}


// DIALOG

// Stores all the names of the document's Object Styles in an array.
function getObjectStylesNames() {
var objectStyleNames = new Array;
for (i = 0; i < objectStyles.length; i++){
objectStyleNames.push(objectStyles.item(i).name);
}
return objectStyleNames;
}

// Displays the input dialog.
function displayDialog(){
var dialog = app.dialogs.add({name:"Remove all Objects with a certain Object Style"});
var objectStyleNames = getObjectStylesNames();
with (dialog) {
with (dialogColumns.add()) {
with (borderPanels.add()) {
with (dialogColumns.add()) {
staticTexts.add({staticLabel:"Object Style:"});
staticTexts.add({staticLabel:"Remove from:"});
}
with (dialogColumns.add()) {
var objectStyleNameDropdown = dropdowns.add({stringList: objectStyleNames, selectedIndex: 0, minWidth: 200});
var radiobuttonGroup = radiobuttonGroups.add();
with (radiobuttonGroup) {
radiobuttonControls.add({staticLabel: "All Spreads", checkedState: true})
radiobuttonControls.add({staticLabel: "Normal Spreads only"})
radiobuttonControls.add({staticLabel: "Masters Spreads only"})
}
}
}
with (borderPanels.add()) {
}
}
}
var dialogReturn = dialog.show();
if (dialogReturn == true) {
var objectStyleName = objectStyleNames[objectStyleNameDropdown.selectedIndex];
var removeFrom = radiobuttonGroup.selectedButton;
dialog.destroy();
removeAllObjectsWithACertainObjectStyle(objectStyleName, removeFrom);
} else {
dialog.destroy();
}
}

displayDialog();




Update 14/1 2018

The script now works with anchored objects and makes the user choose whether to remove objects from normal Spreads, Master Spreads or both.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme