Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to rename styles by font, weight and size

Explorer ,
Jan 19, 2018 Jan 19, 2018

Hello experts!

I'm looking for a script that can rename exisiting styles and grab the information font name, size and color and put that it in the style name.

Something like: Helvetica-16-black

And if it is possible also create new styles for the paragraphs that don't have an style.

I'm new to scripting, and is this an easy task, or is is a complicated one?

Thanks in advance!

Best regards, Fred

TOPICS
Scripting
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jan 22, 2018 Jan 22, 2018

If it work really good, then you should mark it correct answer.

Translate
Engaged ,
Jan 19, 2018 Jan 19, 2018

Hi Fredr,

Below link helpful to you.

Re: Rename the style names -- Batch

Thanks,

Prabu G

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2018 Jan 22, 2018

Hi! Thanks for the link. I think that can solve som of the problems. Is it possible in some way to rename a font with the information that style is containing. Like the new name is name: Helvetica_regular_16px_black Thanks! Best regards, Fredrik

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 22, 2018 Jan 22, 2018

Hi Fredr,

I have created batch script for you.

var myFolder = Folder.selectDialog ('Select folder with InDesing files...');

if(myFolder != null){

  batch_process ();

  alert("Done!");

}

function batch_process () {

  var myFileList = myFolder.getFiles();

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

  var myFile = myFileList;

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

  var myDocument = app.open(myFile);

  rename_pStyle (myDocument);

  }

  }

}

function rename_pStyle (myDocument) {

  var pStyles = myDocument.paragraphStyles;

  for(var i=2; i<pStyles.length; i++){

  var pStyle = pStyles;

  var pStyleFont = (pStyle.appliedFont.name).split("\t");

  var pStyleSwatch = pStyle.fillColor.name;

  var pStylePointSize = pStyle.pointSize;

  var pStyleName = pStyleFont[0] + "_" + pStyleFont[1] + "_" + pStylePointSize + "px_" + pStyleSwatch;

  if(!myDocument.paragraphStyles.item(pStyleName).isValid){

  pStyle.name = pStyleName;

  }

  }

}

Thanks,

Sumit

-Sumit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2018 Jan 22, 2018

Hello Oriup! Thanks a lot for your help. It works really good. Best regards, Fredrik

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 22, 2018 Jan 22, 2018

If it work really good, then you should mark it correct answer.

-Sumit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 26, 2018 Jan 26, 2018

Hi Oriup!

if you want to use this script on the active document, instead of a folder/batch.

How do you do then, if you can at all?

Thanks in advance!

Best regards, Fred

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 26, 2018 Jan 26, 2018

I will do it tomorrow.

Sumit

-Sumit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 07, 2018 Feb 07, 2018
LATEST

Please use for opened document.

if(app.documents.length > 0){

var myDocument = app.documents[0];

rename_pStyle (myDocument);

alert("Done!"); 

}else {

alert("Please open your document first then run.");

}

function rename_pStyle (myDocument) {

var pStyles = myDocument.paragraphStyles;

for(var i=2; i<pStyles.length; i++){

var pStyle = pStyles;

var pStyleFont = (pStyle.appliedFont.name).split("\t");

var pStyleSwatch = pStyle.fillColor.name;

var pStylePointSize = pStyle.pointSize;

var pStyleName = pStyleFont[0] + "_" + pStyleFont[1] + "_" + pStylePointSize + "px_" + pStyleSwatch;

if(!myDocument.paragraphStyles.item(pStyleName).isValid){

pStyle.name = pStyleName;

}

}

}

Sumit

-Sumit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines