CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Copying all GREP-styles from one paragraph style to annother
Tagged: grep styles
- This topic has 13 replies, 7 voices, and was last updated 11 years, 7 months ago by
Anonymous.
-
AuthorPosts
-
-
November 14, 2013 at 2:54 am #66192
Marcin Ploch
MemberHello,
I’m trying to find a simple way to copy all GREP-styles included in one paragraph style to others. Sometimes it is nessecary to just copy GREP-styles insted of inheritance.Can someone please help me?
Best regards
Marcin -
November 14, 2013 at 4:43 am #66193
valedot
MemberYou can help Peter
https://www.kahrel.plus.com/indesign/grep_editor.html -
November 29, 2013 at 11:13 am #66307
John Korchok
MemberHere’s a script that will copy GREP styles, even if they’re nested in up to 2 levels of style groups. Copy the text below to a text editor like NotePad or TextEdit, then save as a file with a “.js” ending. Copy it into the Scripts Panel folder inside the Scripts folder inside the InDesign application folder. The first 4 lines of comments explain how to use it:
//This utility will copy GREP styles into styles that are nested in up to two levels of groups i.e. Main Style Group>Headings Group>Heading 1
//Create a style at the lowest level of the Paragraph Styles i.e. NOT in a style group.
//Put all the GREP styles you wich to copy into this style.
//Type the style name between quotes in the line below. Then run the srcipt and select the styles to which you want to copy the GREP styles.
var source = ‘GREPSourceStyle’;
var theDoc = app.activeDocument;
var pStyles = theDoc.allParagraphStyles;
var pStyleStringList = [];// listbox
fillpStyleStringList();
var getpStyleIndexinpStyles = selectpStyle(pStyleStringList);//[1,2,3,4, 5]
var selectedpStylesByName = getSelectedpStyleNames(getpStyleIndexinpStyles);
l = selectedpStylesByName.length;while(l–){setGrepStyle([selectedpStylesByName[l][0]],[selectedpStylesByName[l][1]],[selectedpStylesByName[l][2]])}
function fillpStyleStringList(){
for(i = 0 ; i < pStyles.length; i++){
if(pStyles[i].parent.parent.toString() === ‘[object ParagraphStyleGroup]’){
pStyleStringList.push(‘Group: ‘ + pStyles[i].parent.parent.name + ‘, Subgroup: ‘ + pStyles[i].parent.name + ‘, Name: ‘ + pStyles[i].name);
}else if(pStyles[i].parent.toString() === ‘[object ParagraphStyleGroup]’){
pStyleStringList.push(‘Subgroup: ‘ + pStyles[i].parent.name + ‘, Name: ‘ + pStyles[i].name);
}else{
pStyleStringList.push(‘Name: ‘ + pStyles[i].name);
}
}
}function selectpStyle (array){
var myWindow = new Window (“dialog”, “Please select your target paragraph styles.”);
var myInputGroup = myWindow.add (“group”);
var select = myInputGroup.add (“listbox”, [0, 0, 300, 300], array, {scrolling: true, multiselect: true});
var myButtonGroup = myWindow.add (“group”);
myButtonGroup.add (“button”, undefined, “OK”);
myButtonGroup.add (“button”, undefined, “Cancel”);
if (myWindow.show() == 1){
var mySelection = select.selection;
var tmpList = [];
for(g = 0; g < mySelection.length; g++){
tmpList.push(mySelection[g].index);
}
return tmpList;
myWindow.close();
}else{
exit();
}
}function getSelectedpStyleNames(getpStylesIndexinpStyles){
var currentTargetpStyleName;
var SelectedNameArray = new Array();
for(j = 0; j < getpStylesIndexinpStyles.length; j++){
var tempArray = new Array(2);
currentTargetpStyleName = pStyles[getpStyleIndexinpStyles[j]].name;
currentTargetpStyleSubgroup = pStyles[getpStyleIndexinpStyles[j]].parent.name;
currentTargetpStyleGroup = pStyles[getpStyleIndexinpStyles[j]].parent.parent.name;
tempArray[0] = currentTargetpStyleGroup;
tempArray[1] = currentTargetpStyleSubgroup;
tempArray[2] = currentTargetpStyleName;
SelectedNameArray[j] = tempArray;
}
return SelectedNameArray;
}function setGrepStyle(targetGroup, targetSubgroup, targetName){
var target
error = “”;
basepStyle = theDoc.paragraphStyles.item(source);
if (!basepStyle.isValid) error = ‘Source style does not exist’;
if(targetGroup != “” && targetGroup != theDoc.name && targetGroup != app.name){
var temptarget = theDoc.paragraphStyleGroups.itemByName(targetGroup.toString());
target = temptarget.paragraphStyleGroups.itemByName(targetSubgroup.toString()).paragraphStyles.itemByName(targetName.toString());
}else if(targetSubgroup != “” && targetSubgroup != theDoc.name && targetSubgroup != app.name){
target = theDoc.paragraphStyleGroups.itemByName(targetSubgroup.toString()).paragraphStyles.itemByName(targetName.toString());
}else{
target = theDoc.paragraphStyles.itemByName(targetName.toString());
}
if (!target.isValid) error += ‘\rTarget style does not exist’;
if (error != “”){alert (error); exit()}
gs = basepStyle.nestedGrepStyles;
for (i = 0; i < gs.length; i++){
target.nestedGrepStyles.add (gs[i].properties);
}
} -
December 4, 2013 at 6:55 am #66337
Colin Flashman
MemberI’ve made an improvement to John’s script that presents a dialog box to select a “source” Paragraph style (instead of going into the code and typing the paragraph style out each time the script needs to be run). From there, the script runs as per John’s script:
//https://forums.adobe.com/thread/681085 (Ariel’s script to select a paragraph style)
//https://forums.adobe.com/message/5888276 (jkorchok2’s script to apply grep styles from a predefined paragraph style)
//This utility will copy GREP styles into styles that are nested in up to two levels of groups i.e. Main Style Group>Headings Group>Heading 1
myDoc = app.activeDocument;
myStyle = SelectParagraph();function SelectParagraph(){
mydialog = app.dialogs.add({name:”Source Paragraph Style”, canCancel:true});
myStyles = myDoc.allParagraphStyles;
var mystring = [];
for (aa = 0; aa < myStyles.length; aa ++){
mystring[aa] = myStyles[aa].name;
if (myStyles[aa].parent.constructor.name == “ParagraphStyleGroup”) mystring[aa]+=” [“+myStyles[aa].parent.name+”]”;
}
with (mydialog.dialogColumns.add()){
staticTexts.add({staticLabel:”Please choose:”});
}
with (mydialog.dialogColumns.add()){
mymenu = dropdowns.add({stringList:mystring, selectedIndex:0});
}
if (mydialog.show()) myresult = myStyles[mymenu.selectedIndex]
else myresult =-1;
mydialog.destroy();
return(myresult);
}var theDoc = app.activeDocument;
var pStyles = theDoc.allParagraphStyles;
var pStyleStringList = [];// listbox
fillpStyleStringList();
var getpStyleIndexinpStyles = selectpStyle(pStyleStringList);
var selectedpStylesByName = getSelectedpStyleNames(getpStyleIndexinpStyles);
l = selectedpStylesByName.length;while(l–){setGrepStyle([selectedpStylesByName[l][0]],[selectedpStylesByName[l][1]],[selectedpStylesByName[l][2]])}
function fillpStyleStringList(){
for(i = 0 ; i < pStyles.length; i++){
if(pStyles[i].parent.parent.toString() === ‘[object ParagraphStyleGroup]’){
pStyleStringList.push(‘Group: ‘ + pStyles[i].parent.parent.name + ‘, Subgroup: ‘ + pStyles[i].parent.name + ‘, Name: ‘ + pStyles[i].name);
}else if(pStyles[i].parent.toString() === ‘[object ParagraphStyleGroup]’){
pStyleStringList.push(‘Subgroup: ‘ + pStyles[i].parent.name + ‘, Name: ‘ + pStyles[i].name);
}else{
pStyleStringList.push(‘Name: ‘ + pStyles[i].name);
}
}
}function selectpStyle (array){
var myWindow = new Window (“dialog”, “Please select the target paragraph styles.”);
var myInputGroup = myWindow.add (“group”);
var select = myInputGroup.add (“listbox”, [0, 0, 300, 300], array, {scrolling: true, multiselect: true});
var myButtonGroup = myWindow.add (“group”);
myButtonGroup.add (“button”, undefined, “OK”);
myButtonGroup.add (“button”, undefined, “Cancel”);
if (myWindow.show() == 1){
var mySelection = select.selection;
var tmpList = [];
for(g = 0; g < mySelection.length; g++){
tmpList.push(mySelection[g].index);
}
return tmpList;
myWindow.close();
}else{
exit();
}
}function getSelectedpStyleNames(getpStylesIndexinpStyles){
var currentTargetpStyleName;
var SelectedNameArray = new Array();
for(j = 0; j < getpStylesIndexinpStyles.length; j++){
var tempArray = new Array(2);
currentTargetpStyleName = pStyles[getpStyleIndexinpStyles[j]].name;
currentTargetpStyleSubgroup = pStyles[getpStyleIndexinpStyles[j]].parent.name;
currentTargetpStyleGroup = pStyles[getpStyleIndexinpStyles[j]].parent.parent.name;
tempArray[0] = currentTargetpStyleGroup;
tempArray[1] = currentTargetpStyleSubgroup;
tempArray[2] = currentTargetpStyleName;
SelectedNameArray[j] = tempArray;
}
return SelectedNameArray;
}function setGrepStyle(targetGroup, targetSubgroup, targetName){
var target
error = “”;
basepStyle = myresult;
if (!basepStyle.isValid) error = ‘Source style does not exist’;
if(targetGroup != “” && targetGroup != theDoc.name && targetGroup != app.name){
var temptarget = theDoc.paragraphStyleGroups.itemByName(targetGroup.toString());
target = temptarget.paragraphStyleGroups.itemByName(targetSubgroup.toString()).paragraphStyles.itemByName(targetName.toString());
}else if(targetSubgroup != “” && targetSubgroup != theDoc.name && targetSubgroup != app.name){
target = theDoc.paragraphStyleGroups.itemByName(targetSubgroup.toString()).paragraphStyles.itemByName(targetName.toString());
}else{
target = theDoc.paragraphStyles.itemByName(targetName.toString());
}
if (!target.isValid) error += ‘\rTarget style does not exist’;
if (error != “”){alert (error); exit()}
gs = basepStyle.nestedGrepStyles;
for (i = 0; i < gs.length; i++){
target.nestedGrepStyles.add (gs[i].properties);
}
} -
March 18, 2014 at 8:48 am #67671
Marcin Ploch
MemberThank You John ad Colin for help. I’m tryingg to use the script but i found some syntax problems. I’m not familiar with scripting :(
Adobe script edithor stops here:
while(l–
and I don’t know why :(
-
March 18, 2014 at 9:20 am #67673
Marcin Ploch
MemberIf I delete “-” after “l” debugging goes OK, script starts and works til I try to choose destination style.
-
March 19, 2014 at 1:49 am #67674
Marcin Ploch
MemberHi, my friend helped me to realize that web browser changed “–” to “-” long style.
After that change script works PERFECT !!!
Thanks a lot again :)))
-
March 21, 2014 at 4:46 am #67698
Masood Ahmad
ParticipantHi Marcinploch, would it be possible to upload the script to avoid any errors. I’m too getting errors.
-
March 24, 2014 at 2:24 am #67717
Masood Ahmad
ParticipantHi Marcinploch, could you please upload the zip version of the script. I’m on Mac and unable to fix the issue. I do not know about scripting. Getting numerous errors when trying to fix the script.
-
March 24, 2014 at 5:15 am #67718
Masood Ahmad
ParticipantSorry Marcinploch, I should have asked Colin Flashman for the script. Colin: could you please arrange the script in a zip format.
-
March 24, 2014 at 8:02 am #67727
Marcin Ploch
MemberHi, write me please your e-mail. I’ll send you a zipped script which works on both platforms OSX and Win
regards
marcin
-
-
March 24, 2014 at 2:34 pm #67732
Jean-Claude Tremblay
ParticipantIf you are on a Mac, there is an applescript available that help copy Grep Styles to styles from a user-chosen paragraph style in a source doc to a user-chosen paragraph style in a destination document.
It was done by Rick Gordon and is available here: https://github.com/rickgordon/Migrate-GREP-Styles
-
March 25, 2014 at 1:46 am #67735
Masood Ahmad
ParticipantThanks Jean, that was really very good. I’m indeed on MAC but I do use PC.
@Marcinploch, Thanks for such an initiative, here is my email-id: masoodahmad@inbox.com
-
April 16, 2014 at 9:03 am #68010
Anonymous
InactiveThank you John and Colin.
Both posted script needed a bit of work, but the 5 minute of fixing is well worth the tremendous amount of time the script is going to save my team and I. Thanks again!
-
-
AuthorPosts
- The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
