Copy link to clipboard
Copied
Hi good peoples,
I wish to know is there a way/script to search and match a big list of item numbers in an indesign table from a external CSV file and apply a new paragraph style over it?
Below is my example:
- We have a catalogue with part numbers on the right most columns applied with "item#" paragraph style.
- Client wish to highlight the only certain part numbers in the catalogue they have in stock and supplied a corresponding Excel/CSV list they carry (in this case it's T365 0500,T365 0600,T365 0800,T367 1000,T367 1200,T367 1400.
- We have to create a new document with the items from the CSV highlighted (in this case we wish to just bold and change colour by applying a "item#2" paragraph style)
- So my question is if there any way of scripting this process of matching item numbers to a CSV or text file and applying "item#2" over it?
I
I hope my question makes sense and thanks for any suggestions in advance
1 Correct answer
Try this:
...// by FRIdNGE, November 2018
var myDoc = app.activeDocument,
mySKUsListFile = File(myDoc.filePath + "/ProductsRefToBeCatched.txt");
mySKUsListFile.open();
var mySKUsList = mySKUsListFile.read(),
mySKUs = mySKUsList.split("\n");
mySKUsListFile.close();
var S = mySKUs.length, s;
for ( s = 0; s < S; s++ ) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b" + mySKUs
+ "\\b";app.findGrepPreferences.appliedParagraphStyle = "item#";
Copy link to clipboard
Copied
I think I would use a GREP style within your Paragraph style to attach a Character style with underline and bold to the list of numbers.
Apply text Underline to :
T365 0500|T365 0600|T365 0800|T367 1000|T367 1200|T367 1400
The | character in GREP functions as OR, so any of those values listed get the character style, and the rest are left alone.
This was, you don't need a separate paragraph style for those numbers, and if the highlighted numbers changed, you just have to edit the GREP list.
Copy link to clipboard
Copied
a bit more flexibel:
Grep:
T36(5\h[5-8]|7\h1[0-4])00
Copy link to clipboard
Copied
Thanks for the suggestion but we dealing with a big list of unique items number and they tend to jump around. So I'm not sure the range method will work
Copy link to clipboard
Copied
no list - no rule
Copy link to clipboard
Copied
Hi,
[ Hi Pixxxel! ]
If the numbers indicated in the CSV file are unique, it's not really complicated to be scripted [note using a grep style has no interest].
You'll surely find here someone to write such a script for free! Personally, it won't be the case.
Best,
Michel, for FRIdNGE
Copy link to clipboard
Copied
I have found something that sort of works, although its not from a external csv, and i will have to create a list of items that need to change to paste into the search queries...
Would someone shed some more light on this?
var myDoc = app.activeDocument,
myCodes = ["T820 0300","T820 0500","T820 0800", etc...etc...],
C = myCodes.length, c;
app.findTextPreferences = null;
for ( c = 0; c < C; c++) {
app.findTextPreferences.findWhat = myCodes
myFound = myDoc.findText();
var F = myFound.length, f;
var ItemNumber = myDoc.paragraphStyles.itemByName("ItemNumber");
var CoreRange = myDoc.paragraphStyles.itemByName("CoreRange");
for ( f = 0; f < F; f++) {
myFound
if ((myFound
myFound
} else{}
}
}
Copy link to clipboard
Copied
Try this:
// by FRIdNGE, November 2018
var myDoc = app.activeDocument,
mySKUsListFile = File(myDoc.filePath + "/ProductsRefToBeCatched.txt");
mySKUsListFile.open();
var mySKUsList = mySKUsListFile.read(),
mySKUs = mySKUsList.split("\n");
mySKUsListFile.close();
var S = mySKUs.length, s;
for ( s = 0; s < S; s++ ) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b" + mySKUs
+ "\\b";app.findGrepPreferences.appliedParagraphStyle = "item#";
app.changeGrepPreferences.appliedParagraphStyle = "item#2";
myDoc.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
I've used a .txt file here saved at the same place as the .indd file.
Best,
Michel
Copy link to clipboard
Copied
Hi Michel,
This works amazingly! Just that I have to move the paragraph styles out of its folder. Is there a command to tell the script to search inside paragraph folders also?
Copy link to clipboard
Copied
// by FRIdNGE, November 2018
var myDoc = app.activeDocument,
//------------------------------------------------------------------------------------------
myGroup1 = myDoc.paragraphStyleGroups.itemByName("item#_Group"),
myParaStyle1 = myGroup1.paragraphStyles.itemByName("item#"),
myGroup2 = myDoc.paragraphStyleGroups.itemByName("item#2_Group"),
myParaStyle2 = myGroup2.paragraphStyles.itemByName("item#2"),
//------------------------------------------------------------------------------------------
mySKUsListFile = File(myDoc.filePath + "/ProductsRefToBeCatched.txt");
mySKUsListFile.open();
var mySKUsList = mySKUsListFile.read(),
mySKUs = mySKUsList.split("\n");
mySKUsListFile.close();
var S = mySKUs.length, s;
for ( s = 0; s < S; s++ ) {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\b" + mySKUs
+ "\\b";app.findGrepPreferences.appliedParagraphStyle = myParaStyle1;
app.changeGrepPreferences.appliedParagraphStyle = myParaStyle2;
myDoc.changeGrep();
}
app.findGrepPreferences = app.changeGrepPreferences = null;
Copy link to clipboard
Copied
This works really great Michel! Can't thank you enough

