Copy link to clipboard
Copied
I have created a multi page indesign file that uses data merge and is a template to be used by an account coordinator.
The Indesign document contains my standard data placeholders and then there some extra pages that use optional data placeholders. The reason I have combined them is to have all the pages combined into one document.
The problem I am running into is that not all documents use the optional placeholders. So when they select a data source file that does not contain the optional data placeholders, they get the āThere is at least one data placeholder that cannot be found in the data sourceā
Is there a way to remove all the unused data placeholders?
Copy link to clipboard
Copied
Rather only with custom script - kind of post-processing.
Are you a PC or Mac user?
Copy link to clipboard
Copied
HI Robert. I am on a Mac and it looks as if ID Tasker does not support it. Do you know anyone who can write a script like that for me?
Copy link to clipboard
Copied
There are a few members here who are Experts in JavaScript - @m1b, @rob day, @Peter Kahrel, @FRIdNGE, @etc
Or, if you have a lot of files to process and you can connect a PC to your Mac network - you could use my ID-Tasker in WatchedFolders mode.
Copy link to clipboard
Copied
Hi Countrym@n, is it a possible solution to add all the missing placeholders to the data source, but just leave them empty? That might be the cleanest way.
Otherwise, it might be solvable with a script, but I personally don't have time at the moment to look at it, unfortunately. Also, it may help for you to post a small sample document and data file set up to show the problem, to make it easiest for someone to jump in and help.
- Mark
Copy link to clipboard
Copied
@m1b Do you know anyone who can help me write a script?
Copy link to clipboard
Copied
Hi Countrym@n, first I strongly suggest you set up a test document with test data files *that show the problem* and post the files here. You don't need to use real data (probably shouldn't anyway), but just a similar situation that gives the error, and explain the steps to perform to produce the error. This will be the best way to get help.
- Mark
Copy link to clipboard
Copied
Hi @m1b . Attached is the indd file and the data merge. If you try to preview you will receive the missing placeholder message. What I am trying to do is remove the placeholders in the indd file.
If you or anyone else has a solution that would be great
Copy link to clipboard
Copied
Thanks for the test files. I've written a script that attempts to remove any invalid *text* placeholders. Let me know if it works for you.
- Mark
/**
* Remove Invalid DataMerge Placeholders.js
* This will attempt to remove any text placeholder
* that is not valid in the context of the current
* DateMerge data source.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/is-there-a-way-to-remove-all-the-unused-data-placeholders/m-p/14172138
*/
function main() {
var doc = app.activeDocument,
placeholders = doc.dataMergeTextPlaceholders,
counter = 0;
for (var i = placeholders.length - 1; i >= 0; i--) {
try {
// invalid placeholders throw error here
placeholders[i].field.isValid;
} catch (error) {
removeTextPlaceholder(placeholders[i]);
counter++;
}
}
alert('Removed ' + counter + ' placeholders.');
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Remove Unused Placeholders');
/**
* Remove a DataMergeTextPlaceholder.
* @author m1b
* @date 2023-10-20
* @Param {DataMergeTextPlaceholder} placeholder
* @Returns {InsertionPoint}
*/
function removeTextPlaceholder(placeholder) {
var story = placeholder.storyOffset.parent,
index = placeholder.storyOffset.index;
story.characters.itemByRange(index, index + placeholder.length - 1).remove();
return story.insertionPoints[index];
};
Copy link to clipboard
Copied
I've found 78 items, not 73! ā¦
function main() {
var myDoc = app.activeDocument,
placeholders = myDoc.dataMergeTextPlaceholders;
var myCondition = myDoc.conditions.item("temp");
if (!myCondition.isValid) myDoc.conditions.add({name: "temp"});
for (var i = placeholders.length - 1; i >= 0; i--) {
try {
if (placeholders[i].field.isValid) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "<<" + placeholders[i].field.fieldName + ">>";
app.changeGrepPreferences.appliedConditions = [myCondition];
myDoc.changeGrep();
}
} catch(e) {}
}
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "<<.+?>>";
app.findGrepPreferences.appliedConditions = [];
var F = myDoc.findGrep().length;
myDoc.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
myCondition.remove();
alert(F + " placeholders removed.")
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Remove Unused Placeholders');
(^/) The Jedi
Copy link to clipboard
Copied
I like how you applied a temporary condition! Very cool! I'm not sure why you delete more placeholders... when I run my script it removes the minimum number of placeholders so that DataMerge will go ahead. - Mark
Copy link to clipboard
Copied
Just Grep find: <<cat.+?>>
5 occurrences (73 + 5, manually typed, so false but not removed as placeholder = 78)!
(^/)
Copy link to clipboard
Copied
this could be handy.
https://corullon.com.br/scripts/product/data-merge-placeholder-checker/
Copy link to clipboard
Copied
Thank you for the link @Studio 223681069pbak . This is definetly handy. HOwever I am looking for a way to delete and placeholders in the indesgin file that are not being used. Im not sure if this is possible or not