Forum Replies Created
-
AuthorPosts
-
Uwe Laubender
Member@Roland: there is a way changing the default Place parameters through scripting. Try the following JavaScript, just a single line long:
app.pdfPlacePreferences.pdfCrop = PDFCrop.CROP_MEDIA;It'll work until you choose to change the settings through the UI. After a restart of InDesign you have to fire the script again…
Hope that helps.Uwe
Uwe Laubender
Member@Roland: there is a way changing the default Place parameters through scripting. Try the following JavaScript, just a single line long:
app.pdfPlacePreferences.pdfCrop = PDFCrop.CROP_MEDIA;It'll work until you choose to change the settings through the UI. After a restart of InDesign you have to fire the script again…
Hope that helps.Uwe
Uwe Laubender
MemberRocky,
hm. Can't tell if reformatting added overhead to your library.
You said that the library is very old. Does it mean InDesign CS2? Maybe CS2-libraries were encoded in a more compressed way…
Pure speculation.Something different came to my mind. I hope you noticed that after running the script you no longer had the tiny previews along with the assets. That is because InDesign is not able to recompose the placed text frames when running.
To generate the preview just add the following line:
d.textFrames.item(0).recompose();
before that line:
libraryName.store(app.activeDocument.textFrames.item(0));
And when you are at it just swap “app.activeDocument” to simply “d” in that same line; in this case it's all the same, just it's short form:
libraryName.store(d.textFrames.item(0));
Uwe Laubender
MemberHappy New Year, Rocky!
Good to hear that all went well. In the meantime I wrote an advanced version of the script with a little UI, that let you choose an available library and a font. Of course, now it's too late for that, but if you feel like it, test it on your material.Just open a library, this time have no InDesign document open, the script will add one by itself and give it a go:
//Uwe Laubender
//ReformatTextAssets_2-3.jsx
/**
* @@@BUILDINFO@@@ ReformatTextAssets_2-3.jsx !Version! Mon Jan 04 2010 10:58:57 GMT+0100
*///DESCRIPTION:Reformats text assets of library to new paragraph style regardless of local formatting!
app.documents.add();
var d=app.activeDocument;
var pStyles=d.paragraphStyles;var fontsList = app.fonts.everyItem().name;
if(app.libraries.length!=0){
var librariesList=app.libraries.everyItem().name;
}
else{
alert(“There is no library open. Please open a library and try again.”);
exit();
};//Begin dialog:
var myDialog=app.dialogs.add({name:”List of Libraries and Fonts:”, canCancel:true});with(myDialog){
with(dialogColumns.add()) {
with (dialogRows.add()) {
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:”Library: “});
};
with(dialogColumns.add()){
var libraryDropDown = dropdowns.add({stringList: librariesList, selectedIndex:0});
};
};
};
with (dialogRows.add()) {
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:”Font: “});
};
with(dialogColumns.add()){
var fontsDropDown = dropdowns.add({stringList: fontsList, selectedIndex:0});
};
};
};
};
};
var result=myDialog.show();if(result == true){
var newFont = fontsList[fontsDropDown.selectedIndex];
var libraryName = app.libraries.item(librariesList[libraryDropDown.selectedIndex]);myDialog.destroy();
};else{
myDialog.destroy();
};if(d.textFrames.length!=0){
for (n=0;n<d.textFrames.length;n++){
d.textFrames[n].remove();
};
};//Getting rid of all paragraph styles that can be removed:
if(pStyles.length>2){
for(n=pStyles.length-1;n>1;n–){
pStyles[n].remove();
};
};for(n=0;n<libraryName.assets.length;n++){
var assetName=libraryName.assets.item(n).name;
var assetDescription=libraryName.assets.item(n).description;
var assetLabel=libraryName.assets.item(n).label;
var assetAssetType=libraryName.assets.item(n).assetType;libraryName.assets.item(n).placeAsset(d);
//Now give the old paragraph style a new font:
for(m=0;m<d.stories.item(0).paragraphs.length;m++){
if(d.textFrames.item(0).paragraphs.item(m).appliedParagraphStyle.isValid==true){
var appliedPStyle=d.textFrames.item(0).paragraphs.item(m).appliedParagraphStyle;
appliedPStyle.appliedFont=newFont;
};
else{
d.textFrames.item(0).paragraphs.item(m).appliedFont=newFont;
};
};libraryName.assets[n].remove();
libraryName.store(app.activeDocument.textFrames.item(0));libraryName.assets[0].name=assetName;
libraryName.assets[0].description=assetDescription;
libraryName.assets[0].label=assetLabel;
libraryName.assets[0].assetType=assetAssetType;d.textFrames.item(0).remove();
if(pStyles.length>2){
for(p=pStyles.length-1;p>1;p–){
pStyles[p].remove();
};
};
};Uwe Laubender
MemberRocky,
hm. Can't tell if reformatting added overhead to your library.
You said that the library is very old. Does it mean InDesign CS2? Maybe CS2-libraries were encoded in a more compressed way…
Pure speculation.Something different came to my mind. I hope you noticed that after running the script you no longer had the tiny previews along with the assets. That is because InDesign is not able to recompose the placed text frames when running.
To generate the preview just add the following line:
d.textFrames.item(0).recompose();
before that line:
libraryName.store(app.activeDocument.textFrames.item(0));
And when you are at it just swap “app.activeDocument” to simply “d” in that same line; in this case it's all the same, just it's short form:
libraryName.store(d.textFrames.item(0));
Uwe Laubender
MemberHappy New Year, Rocky!
Good to hear that all went well. In the meantime I wrote an advanced version of the script with a little UI, that let you choose an available library and a font. Of course, now it's too late for that, but if you feel like it, test it on your material.Just open a library, this time have no InDesign document open, the script will add one by itself and give it a go:
//Uwe Laubender
//ReformatTextAssets_2-3.jsx
/**
* @@@BUILDINFO@@@ ReformatTextAssets_2-3.jsx !Version! Mon Jan 04 2010 10:58:57 GMT+0100
*///DESCRIPTION:Reformats text assets of library to new paragraph style regardless of local formatting!
app.documents.add();
var d=app.activeDocument;
var pStyles=d.paragraphStyles;var fontsList = app.fonts.everyItem().name;
if(app.libraries.length!=0){
var librariesList=app.libraries.everyItem().name;
}
else{
alert(“There is no library open. Please open a library and try again.”);
exit();
};//Begin dialog:
var myDialog=app.dialogs.add({name:”List of Libraries and Fonts:”, canCancel:true});with(myDialog){
with(dialogColumns.add()) {
with (dialogRows.add()) {
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:”Library: “});
};
with(dialogColumns.add()){
var libraryDropDown = dropdowns.add({stringList: librariesList, selectedIndex:0});
};
};
};
with (dialogRows.add()) {
with(dialogColumns.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:”Font: “});
};
with(dialogColumns.add()){
var fontsDropDown = dropdowns.add({stringList: fontsList, selectedIndex:0});
};
};
};
};
};
var result=myDialog.show();if(result == true){
var newFont = fontsList[fontsDropDown.selectedIndex];
var libraryName = app.libraries.item(librariesList[libraryDropDown.selectedIndex]);myDialog.destroy();
};else{
myDialog.destroy();
};if(d.textFrames.length!=0){
for (n=0;n<d.textFrames.length;n++){
d.textFrames[n].remove();
};
};
//Getting rid of all paragraph styles that can be removed:
if(pStyles.length>2){
for(n=pStyles.length-1;n>1;n–){
pStyles[n].remove();
};
};for(n=0;n<libraryName.assets.length;n++){
var assetName=libraryName.assets.item(n).name;
var assetDescription=libraryName.assets.item(n).description;
var assetLabel=libraryName.assets.item(n).label;
var assetAssetType=libraryName.assets.item(n).assetType;
libraryName.assets.item(n).placeAsset(d);
//Now give the old paragraph style a new font:
for(m=0;m<d.stories.item(0).paragraphs.length;m++){
if(d.textFrames.item(0).paragraphs.item(m).appliedParagraphStyle.isValid==true){
var appliedPStyle=d.textFrames.item(0).paragraphs.item(m).appliedParagraphStyle;
appliedPStyle.appliedFont=newFont;
};
else{
d.textFrames.item(0).paragraphs.item(m).appliedFont=newFont;
};
};
libraryName.assets[n].remove();
libraryName.store(app.activeDocument.textFrames.item(0));
libraryName.assets[0].name=assetName;
libraryName.assets[0].description=assetDescription;
libraryName.assets[0].label=assetLabel;
libraryName.assets[0].assetType=assetAssetType;
d.textFrames.item(0).remove();
if(pStyles.length>2){
for(p=pStyles.length-1;p>1;p–){
pStyles[p].remove();
};
};
};Uwe Laubender
MemberRocky,
basically I see a possibility doing this by JavaScript (ExtendScript).
Warning! The following lines of code are a case study for doing so.To test this we need some prerequisites:
1. A blank InDesign CS4 file, make sure it is the only one opened
2. A new paragraph style with your desired font and font weight
3. An open library, make sure all assets are single text framesWhat does the script do?
It will loop through all the assets of the library:
1. Places the asset (which is one single text frame) to the open InDesign file
2. Reformats all paragraphs in the text frame's story to the new paragraph style
3. Removes the old asset from the library
4. Stores the new asset to the library
5. Removes the placed text frame from the InDesign fileFor testing the script be aware that:
1. “Your_Test_Library_Name” in line 11 should be replaced by the name of your test-library
DO NOT DO THE TEST ON YOUR ORIGINAL LIBRARY!2. “Your_New_Paragraph_Style” in line 22 should be replaced by the name of your new paragraph style
Again: be aware, this script is only a case study. To make it properly work, we have to discuss a lot:
1. Are all assets in your library are of the type “text”?
2. Are there paragraph or character styles applied to the text?
3. Is there formatting without styles?
4. Is there more than one text frame per asset?
etc. etc.
Here is the script. Copy it to your text editor, make sure it is text only, rename the file with the suffix “.jsx” and place it to your InDesign CS4 scripts folder at “Adobe InDesign CS4/Scripts/Scripts Panel”:
//Uwe Laubender
//ReformatTextAssets.jsx
/**
* @@@BUILDINFO@@@ ReformatTextAssets.jsx !Version! Wed Dec 30 2009 17:17:53 GMT+0100
*/
//DESCRIPTION:Reformats text assets of library to new paragraph style regardless of local formatting!
var d=app.activeDocument;if(d.pageItems.length==0){
//Don't forget to enter the suffix “.indl” to the name of your test-library:
var myLibrary=app.libraries.itemByName(“Your_Test_Library_Name.indl”);for(n=0;n<myLibrary.assets.length;n++){
var assetName=myLibrary.assets.item(n).name;
var assetDescription=myLibrary.assets.item(n).description;
var assetLabel=myLibrary.assets.item(n).label;
var assetAssetType=myLibrary.assets.item(n).assetType;
myLibrary.assets.item(n).placeAsset(d);//Now reformat all paragraphs to the new paragraph style:
for(m=0;m<d.stories.item(0).paragraphs.length;m++){
d.textFrames.item(0).paragraphs[m].appliedParagraphStyle=”Your_New_Paragraph_Style”;
};myLibrary.assets[n].remove();
myLibrary.store(app.activeDocument.textFrames.item(0));myLibrary.assets[0].name=assetName;
myLibrary.assets[0].description=assetDescription;
myLibrary.assets[0].label=assetLabel;
myLibrary.assets[0].assetType=assetAssetType;d.textFrames.item(0).remove();
};
};Uwe Laubender
MemberRocky,
basically I see a possibility doing this by JavaScript (ExtendScript).
Warning! The following lines of code are a case study for doing so.To test this we need some prerequisites:
1. A blank InDesign CS4 file, make sure it is the only one opened
2. A new paragraph style with your desired font and font weight
3. An open library, make sure all assets are single text framesWhat does the script do?
It will loop through all the assets of the library:
1. Places the asset (which is one single text frame) to the open InDesign file
2. Reformats all paragraphs in the text frame's story to the new paragraph style
3. Removes the old asset from the library
4. Stores the new asset to the library
5. Removes the placed text frame from the InDesign fileFor testing the script be aware that:
1. “Your_Test_Library_Name” in line 11 should be replaced by the name of your test-library
DO NOT DO THE TEST ON YOUR ORIGINAL LIBRARY!2. “Your_New_Paragraph_Style” in line 22 should be replaced by the name of your new paragraph style
Again: be aware, this script is only a case study. To make it properly work, we have to discuss a lot:
1. Are all assets in your library are of the type “text”?
2. Are there paragraph or character styles applied to the text?
3. Is there formatting without styles?
4. Is there more than one text frame per asset?
etc. etc.
Here is the script. Copy it to your text editor, make sure it is text only, rename the file with the suffix “.jsx” and place it to your InDesign CS4 scripts folder at “Adobe InDesign CS4/Scripts/Scripts Panel”:
//Uwe Laubender
//ReformatTextAssets.jsx
/**
* @@@BUILDINFO@@@ ReformatTextAssets.jsx !Version! Wed Dec 30 2009 17:17:53 GMT+0100
*/
//DESCRIPTION:Reformats text assets of library to new paragraph style regardless of local formatting!
var d=app.activeDocument;if(d.pageItems.length==0){
//Don't forget to enter the suffix “.indl” to the name of your test-library:
var myLibrary=app.libraries.itemByName(“Your_Test_Library_Name.indl”);for(n=0;n<myLibrary.assets.length;n++){
var assetName=myLibrary.assets.item(n).name;
var assetDescription=myLibrary.assets.item(n).description;
var assetLabel=myLibrary.assets.item(n).label;
var assetAssetType=myLibrary.assets.item(n).assetType;
myLibrary.assets.item(n).placeAsset(d);
//Now reformat all paragraphs to the new paragraph style:
for(m=0;m<d.stories.item(0).paragraphs.length;m++){
d.textFrames.item(0).paragraphs[m].appliedParagraphStyle=”Your_New_Paragraph_Style”;
};
myLibrary.assets[n].remove();
myLibrary.store(app.activeDocument.textFrames.item(0));
myLibrary.assets[0].name=assetName;
myLibrary.assets[0].description=assetDescription;
myLibrary.assets[0].label=assetLabel;
myLibrary.assets[0].assetType=assetAssetType;
d.textFrames.item(0).remove();
};
};Uwe Laubender
MemberHi, Adi!
Thank you for the script. I came accross one minor glitch: in case someone set different measurement units to vertical and horizontal rulers I suggest you would better add one line of code right after line 3:myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
if you don't the end result is not predictable.
Off topic:
One question to the admin (David?): how would I tag code in this forum to look like code? Say format one string of text to “Courier”?
I know that there is the HTML-button, where I can edit, but I could not figure out what kind of tags will work. Something likeHere comes my code
is ruled out. Or, I cannot see it in the preview. Let's try it. The line of code is tagged with
.
Cheers,
Uwe//Edit: oh,
worked as expected.
Uwe Laubender
MemberHi, Adi!
Thank you for the script. I came accross one minor glitch: in case someone set different measurement units to vertical and horizontal rulers I suggest you would better add one line of code right after line 3:myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
if you don't the end result is not predictable.
Off topic:
One question to the admin (David?): how would I tag code in this forum to look like code? Say format one string of text to “Courier”?
I know that there is the HTML-button, where I can edit, but I could not figure out what kind of tags will work. Something likeHere comes my code
is ruled out. Or, I cannot see it in the preview. Let's try it. The line of code is tagged with
.
Cheers,
Uwe//Edit: oh,
worked as expected.
-
AuthorPosts