Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Created October 31, 2019 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbaty-barr/ea49c982c7cc2365fc5477392a6f285c to your computer and use it in GitHub Desktop.
Save rbaty-barr/ea49c982c7cc2365fc5477392a6f285c to your computer and use it in GitHub Desktop.
get all skus from indesign
pStyles = ['Table Cat. No./Price', 'Table Cat. No./Price+', 'CHEM cat no.', 'CHEM cat no.+', 'cat no for pg 176', 'cat no for pg 176+', 'MicroSlides CatNo./Price', 'MicroSlides CatNo./Price+', 'Slide Pricee', 'Slide Price+', 'ChemTopic_CatNo./Price', 'ChemTopic_CatNo./+']
myRegXp = /([A-Z]){1,2}([0-9]){3,4}/
my2RegXp = /([A-Z]){1}([0-9]){1}/
my3RegXp = /([A-Z]){2}/
my5RegXp = /(^[A-Z]+)([0-9]+)/
app.findPreferences = app.changePreferences = null
doc = app.activeDocument
u = undefined
if( doc.indexes.length == 0 )
doc.indexes.add()
for( j = 0; j < pStyles.length; j++ )
{
if( doc.paragraphStyles.item( pStyles[j] ) != null )
{
toMark = doc.search( u, u, u, u, { appliedParagraphStyle : pStyles[j] } )
for( i = toMark.length-1 ; i > -1; i-- )
{
if( toMark[i].contents != "1397058884" ) //em-dash character
{
top = toMark[i].contents.replace( /[\u0001-\u001F\uFEFF]/g, '' )
for( k = 0; k < top.length; k++ ){
if ( myRegXp.test(top.substring(k,k+6)) ){
//doc.indexes[0].topics.add( top )
//doc.indexes[0].topics.item( top ).pageReferences.add( toMark[i], PageReferenceType.currentPage )
if ( my2RegXp.test(top.substring(k,k+2)) ){
//matches A1234 format
productLabel = doc.indexes[0].topics.add( "Products" )
productLabel.topics.add( top.substring(k,k+5) )
productLabel.topics.item( top.substring(k,k+5) ).pageReferences.add( toMark[i], PageReferenceType.currentPage )
}
else if ( my3RegXp.test(top.substring(k,k+2)) ){
//matches AB1234 format
productLabel = doc.indexes[0].topics.add( "Products" )
productLabel.topics.add( top.substring(k,k+6) )
productLabel.topics.item( top.substring(k,k+6) ).pageReferences.add( toMark[i], PageReferenceType.currentPage )
}
else if ( my5RegXp.test(top.substring(k,k+2))) {
// should match all letter number combos - honestly
productLabel = doc.indexes[0].topics.add( "Products" )
productLabel.topics.add( top.substring(k,k+7) )
productLabel.topics.item( top.substring(k,k+7) ).pageReferences.add( toMark[i], PageReferenceType.currentPage )
}
break;
}
else{
continue;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment