Rename the style names -- Batch

Engaged ,
Nov 10, 2017

Copy link to clipboard

Copied

Hi All,

I want to rename the Pstyles, Cstyles etc..names using excel. I have use the below script its also working in activeDocument.

Now i have 100 inDesign documents so i will go to batch process.  Any advice would be greatly appreciated.

Code:

#target indesign

var myFile = File.openDialog("Choose a Remap styles csv file:"); 

myFile.open('r');

var myCounter = 0;

while (myFile.eof==false)

     myCounter++

     line=myFile.readln(); 

     line = line.split(",");

     if(myCounter == 1)

     {

        continue;

        }

     Find_Pstyles = line[0];

     Change_Pstyles = line[1];

     Find_Cstyles = line[2];

     Change_Cstyles = line[3];  

var myDoc = app.activeDocument;

try

{

     

if (myDoc.paragraphStyles.item(Find_Pstyles) != null) 

myDoc.paragraphStyles.item(Find_Pstyles).name = Change_Pstyles;

}

if (myDoc.characterStyles.item(Find_Cstyles) != null) 

myDoc.characterStyles.item(Find_Cstyles).name = Change_Cstyles;

}

}

catch(e){}

}

Thanks,

Prabu G

After.pngBefore.png

TOPICS
Scripting

Views

894

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Rename the style names -- Batch

Engaged ,
Nov 10, 2017

Copy link to clipboard

Copied

Hi All,

I want to rename the Pstyles, Cstyles etc..names using excel. I have use the below script its also working in activeDocument.

Now i have 100 inDesign documents so i will go to batch process.  Any advice would be greatly appreciated.

Code:

#target indesign

var myFile = File.openDialog("Choose a Remap styles csv file:"); 

myFile.open('r');

var myCounter = 0;

while (myFile.eof==false)

     myCounter++

     line=myFile.readln(); 

     line = line.split(",");

     if(myCounter == 1)

     {

        continue;

        }

     Find_Pstyles = line[0];

     Change_Pstyles = line[1];

     Find_Cstyles = line[2];

     Change_Cstyles = line[3];  

var myDoc = app.activeDocument;

try

{

     

if (myDoc.paragraphStyles.item(Find_Pstyles) != null) 

myDoc.paragraphStyles.item(Find_Pstyles).name = Change_Pstyles;

}

if (myDoc.characterStyles.item(Find_Cstyles) != null) 

myDoc.characterStyles.item(Find_Cstyles).name = Change_Cstyles;

}

}

catch(e){}

}

Thanks,

Prabu G

After.pngBefore.png

TOPICS
Scripting

Views

895

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 10, 2017 0
Engaged ,
Nov 10, 2017

Copy link to clipboard

Copied

I have attached csv format:

csv_fomat.png

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 10, 2017 0
Enthusiast ,
Nov 10, 2017

Copy link to clipboard

Copied

Hi.

I use this little code when i want to proccess files inside a folder.

var myFileFolder = Folder(/*HERE GOES THE DEFAULT FOLDER*/).selectDlg("Select the folder.");

var myDialog = myFileFolder;

if (myDialog != null) {

    var myIDFiles = myFileFolder.getFiles("*.indd");

    alert (myIDFiles.length + " files were found in the selected.","Script by LFCorullón");

    for (var z = 0; z < myIDFiles.length; z++) {

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

        app.open(File(myIDFiles));

//~ =========================================================================================================

//~ =========================================================================================================

// HERE GOES THE CODE TO BE EXECUTED IN EACH FILE

       

// HERE GOES THE CODE TO BE EXECUTED IN EACH FILE

//~ =========================================================================================================

//~ =========================================================================================================

        app.activeDocument.close(SaveOptions.YES);

        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

        }

    }

Or this other one, when I want to proccess files in the main folder and subfolders.

#target indesign

//=============================================================

//  Script by Luis Felipe Corullón

//  Contato: lf@corullon.com.br

//  Site: http://lf.corullon.com.br

//=============================================================

var myFolder = Folder(/*the specified folder here*/).selectDlg("Select the main folder.");

// se o usuário pressionar OK na JANELA DE DIALOGO

var myDialog = myFolder;

if(myDialog == null){

        alert ("Canceled.","Script by LFCorullón");}

else {

    var myFiles = [];

    GetSubFolders(myFolder);

    alert (myFiles.length + " files found in the main folder and subfolders.","Script by LFCorullón");

//open files in the selected folder and subfolders

for(var i = 0; i < myFiles.length; i++)

    {

//não exibe nenhuma janela de interação.

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

//turn check links off

app.linkingPreferences.checkLinksAtOpen = false;

    app.open(File(myFiles));

   

//~ =========================================================================================================

//~ =========================================================================================================

// EXECUTA A AÇÃO EM CADA UM DOS ARQUIVOS DA PASTA SELECIONADA

       

       

// EXECUTA A AÇÃO EM CADA UM DOS ARQUIVOS DA PASTA SELECIONADA

//~ =========================================================================================================

//~ =========================================================================================================

//turn check links on again

app.linkingPreferences.checkLinksAtOpen = true;

//exibe todas as janelas de interação.

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

    }

alert (myFiles.length + " files in the main folder and subfolders were processed.","Script by LFCorullón");}

function GetSubFolders(theFolder) { 

     var myFileList = theFolder.getFiles(); 

     for (var i = 0; i < myFileList.length; i++) { 

          var myFile = myFileList

          if (myFile instanceof Folder){ 

               GetSubFolders(myFile); 

          } 

          else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) { 

               myFiles.push(myFile); 

          } 

     } 

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 10, 2017 2
Engaged ,
Nov 11, 2017

Copy link to clipboard

Copied

Hi lf.corullon,

Thanks for your reply and source code

I am really happy with the solution found here.

Thanks,

Prabu G

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2017 0
Adobe Community Professional ,
Nov 11, 2017

Copy link to clipboard

Copied

Hi Prabu,

also consider Peter Kahrel's script here:

Free script Batch convert/export InDesign documents | Peter Kahrel

You can run a script in the batch process!

Regards,
Uwe

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2017 2
Engaged ,
Nov 11, 2017

Copy link to clipboard

Copied

Hi Uwe,

Thanks for the reply. I have used the Peter Kahrel's script, but i need the source code.

I tried (lf.corullon code) and finally get the source code below.

//=============================================================================================================//

// Read the Excel.

//=============================================================================================================//

var myFile = File.openDialog("Choose a Remap styles csv file:");

if (!myFile)

exit(); 

}

//=============================================================================================================//

// Radio buttons

//=============================================================================================================//

var window = new Window ("dialog"); 

window.alignChildren = "left"; 

var radio1 = window.add ("radiobutton", undefined, "Rename the styles"); 

var radio2 = window.add ("radiobutton", undefined, "Rename and Load styles"); 

var myOkButton = window.add ("button", undefined, "OK"); 

var myCancelButton = window.add ("button", undefined, "Cancel"); 

myOkButton.onClick = function() 

  //Closing dialog indicating a call for action => 1 

  window.close(1); 

 

 

//If dialog returned 1, then routine has to be executed… 

if ( window.show ()==1 )

  if(radio1.value == true) 

  {

var Ch_Folder = Folder.selectDialog("Select Input Folder");

if (!Ch_Folder)

exit(); 

}

var myIndFilePath = Ch_Folder.filePath;

myFolder = new Folder ([Ch_Folder]);

myFolderContents = myFolder.getFiles("*.indd"); // array

//~ var myIndFileName = myFolderContents.name;

myFileAmount = (myFolderContents.length - 1);

for (i = myFileAmount; i >= 0; i--)

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;     

var sourceDoc = app.open(File (myFolderContents)); 

myFile.open('r');

var myCounter = 0;

while (myFile.eof==false)

     myCounter++

     line=myFile.readln(); 

     line = line.split(",");

//~       line = line.split("\t");

//=============================================================================================================//

// to skip the heading in csv (1st row)

//=============================================================================================================//

     if(myCounter == 1)

     {

        continue;

        }

     Find_Pstyles = line[0];

//~      alert("Find_Pstyles: " + Find_Pstyles)

     Change_Pstyles = line[1];

//~      alert("Change_Pstyles: " + Change_Pstyles)

     Find_Cstyles = line[2];

//~       alert("Find_Cstyles: " + Find_Cstyles)

      Change_Cstyles = line[3];

//~       alert("Change_Cstyles: " + Change_Cstyles)    

//=============================================================================================================//

// Rename the Non-DRV style names such as paragraph and character styles//

//=============================================================================================================//

try 

    { 

           

     if (sourceDoc.paragraphStyles.item(Find_Pstyles) != null)   

    {   

    sourceDoc.paragraphStyles.item(Find_Pstyles).name = Change_Pstyles;  

    } 

     

    if (sourceDoc.characterStyles.item(Find_Cstyles) != null)   

    {   

    sourceDoc.characterStyles.item(Find_Cstyles).name = Change_Cstyles;  

    }  

}//try

    catch(e){}

   

    }//while loop

sourceDoc.save(new File(Ch_Folder.path + "/" + myFolderContents.name.replace(".indd", "") + "_processed.indd"));

sourceDoc.close(SaveOptions.NO);

}// close for loop

}//if

Thanks,

Prabu

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2017 0
Guru ,
Nov 11, 2017

Copy link to clipboard

Copied

Here I wrote a couple of scripts for you -- Rename paragraph styles and Rename character styles which should be used with the Batch processor script like so:

1) Place the both scripts into the same folder

11-11-2017 15-22-05.png

2) Select the following settings in the BP dialog box

11-11-2017 15-21-07.png

You can easily edit the array containing the names list in the "find-change" format:

11-11-2017 15-36-46.png

Also, you can rework the script to read info from a CSV-file located, say, in the same folder as the script, or from Excel directly.

Examples are here.

Hope it helps!

— Kas

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 11, 2017 2
Nov 23, 2020

Copy link to clipboard

Copied

Could you please reupload them or send them by email?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 23, 2020 0
Adobe Community Professional ,
Nov 23, 2020

Copy link to clipboard

Copied

Kasyan's new website is here: http://kasyan.ho.ua/scripts_by_categories.html

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 23, 2020 1
Nov 23, 2020

Copy link to clipboard

Copied

Thank you! Great

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 23, 2020 0
Jan 22, 2018

Copy link to clipboard

Copied

Hi! Is it possible to make a script that grab information like font name, size and color and put that it in the style name. So the renamed style should be named something like: Helvetica-16-black Best regards, Fredrik

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 22, 2018 0
Adobe Community Professional ,
Nov 23, 2020

Copy link to clipboard

Copied

This is for paragraph styles:

styles = app.documents[0].allParagraphStyles;
for (i = 2; i < styles.length; i++) {
  styles[i].name = styles[i].appliedFont.fontFamily + '-' + styles[i].pointSize + '-' + styles[i].fillColor.name;
}

For character styles, change allParagraphStyles to all CharacterStyles, and change i = 2 in the second line to i = 1

P.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 23, 2020 0