Quantcast
Channel: Adobe Community : All Content - InDesign Scripting
Viewing all 8771 articles
Browse latest View live

How can I tailor this GREP script to find & replace active open document?

$
0
0
// Get the current selection
var doc   = app.activeDocument;
var sel   = doc.selection;
var frame = sel[0];


if (!frame || frame.constructor.name !== "TextFrame") {
      var msg = "Please select a text frame containing";      msg += " the story you wish to format";      alert(msg);
} else {      var story = frame.parentStory;      // Reset the Find/Change options      app.findGrepPreferences = NothingEnum.nothing;      app.changeGrepPreferences = NothingEnum.nothing;      // Remove all soft returns, then replaces all double spaces to single spaces      app.findGrepPreferences.findWhat = " \s+\n";      app.changeGrepPreferences.changeTo = " ";      story.changeGrep();         // Remove all multiple spaces      app.findGrepPreferences.findWhat = "\s+";      app.changeGrepPreferences.changeTo = " ";      story.changeGrep();      // Split Listings WITH Images      app.findGrepPreferences.findWhat = "(\d\d-\d+.*)\t(?!~a)(.*)\t(.*)\r";      app.changeGrepPreferences.changeTo = "$2\r$1\t$3\r";      app.changeGrepPreferences.appliedParagraphStyle = "Description";      story.changeGrep();   
//      // Split Listings WITHOUT Images
//      app.findGrepPreferences.findWhat = "(?<=~a)(.*)\t(.*)\t(.*)\t(.*)\r";
//      app.changeGrepPreferences.changeTo = "$1 $2\r$3\t$4\r";
//      app.changeGrepPreferences.appliedParagraphStyle = "Description";
//      story.changeGrep();         // Format Pricelines      app.findGrepPreferences.findWhat = "^(\d\d-\d+-\d\t.*)\r";      app.changeGrepPreferences.changeTo = "$1\r";      app.findGrepPreferences.appliedParagraphStyle = "Description";      app.changeGrepPreferences.appliedParagraphStyle = "Priceline";      story.changeGrep();   
}

How to change font type using InDesign scripting (Javascript) ?

$
0
0

Hi,

 

    I need to change the font type of an InDesign document using InDesign script (javascript). I found some online references in InDesign scripting guide and running the following snippet, gives me errors.

 

//Clear any existing preferences

app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences = NothingEnum.nothing;

 

app.findChangeTextOptions.caseSensitive = false;

app.changeTextPreferences.appliedFont = app.fonts.item("DEVANAGARI MT");

app.documents.item(0).changeText();

 

Get the following msg from InDesign server.

Error code: 1

Error description: changeText

 

The indesign file used to change the font is definitely not corrupted, cause the following script to export the file as .png works just fine. Any help appreciated.

app.pngExportPreferences.exportResolution = 100.0;

  app.documents.item(0).exportFile(ExportFormat.PNG_FORMAT, previewDocument);

Build a Javascript from query .xml files of the InDesign Find-Change Queries

$
0
0

Hi all,

 

Do you think that such a script that can do this could exist?

Obviously, using scripting ESTK.

 

Thanks in advance for comments!  ;-)

by value distribute spacing

$
0
0

Can a script written giving it a value (use spacing) distribute vertical spaces

1dist1.gif

Is there a character limit for prompt()?

$
0
0

I came across a comment on another website to the effect that the global method prompt() will crash PhotoShop if the user types more than 255 characters in the text field. From my brief experience today, I would say that the same limit applies to InCopy and InDesign as well. Has anyone else encountered this?

 

I guess the next step would be to use ScriptUI to create a text-entry dialog.

Put a remote file in document using Indesign Javascript

$
0
0

Hi All ,

 

I am using Indesign CS5 .

 

I am getting an error in placing an image into frame in indesign Javascript .

I am getting the error when i am accessing a network drive O but face no error while accessing local drive D

 

 

  try{   

     //This works !

       //myImage = "D:\\3641456.png";

     // This does not work   

       myImage = "O:\\3641456.png";

       var myFile = File(myImage);

       logError ("myFile : " + myFile);

    var myIm =myDocument.pages.item(currPageCount).place(myFile);

  //var myIm =myDocument.pages.item(currPageCount).place (File(myImage))

  }

     catch(e)

  {

         logError (e+" : Error");

 

  }

 

 

Output :

myFile : /o/3641456.png

IOError: Cannot find the folder "O:\3641456.png". : Error

 

Please help

 

Nirav.

Current Paragraph index in GREP replacement

$
0
0

Hi, I am trying to find the current paragraph number/Index where I am applying a GREP to find a word/s between quotation marks Thank you, The line in My code which is supposed to extract the index  var Currentparagrap = EnFrColumn.paragraphs.index;      //is not working my code: trace("Remove Quotation Marks than bold the word/s in between (FR Column).");     app.findGrepPreferences = NothingEnum.nothing;     app.changeGrepPreferences = NothingEnum.nothing;     //Clear the find/change text preferences.     app.findTextPreferences = NothingEnum.nothing;     app.changeTextPreferences = NothingEnum.nothing;     if (EnFrColumn == "fr"){     app.findGrepPreferences.findWhat =  '(«~S)(\\w+)(~S»)|(«~S)(\\w+)\\s(\\w+)(~S»)'; // one or two words between open & closing quotation marks     results = this.document.findGrep();     if(results != null) {       for(var j=0; j< results.length; j++) { xmlElement = results[j].associatedXMLElements[0]; strChangeTo = results[j].contents; if (xmlElement.markupTag.name == "FRMarginalNote"){ if (app.findTextPreferences.findWhat = strChangeTo){ strtChangeToNew = strChangeTo.substr(2,strChangeTo.length-4); var Currentparagrap = EnFrColumn.paragraphs.index; app.changeTextPreferences.changeTo = strtChangeToNew; app.changeTextPreferences.fontStyle = "Bold Italic";   story.changeText();     } //Clear the find/change preferences after the search. app.findTextPreferences = NothingEnum.nothing; app.changeTextPreferences = NothingEnum.nothing; } } }     }

Scripts For indesign

$
0
0

Hello all.  I'm wondering if there is a script for indesign that allow me to put the file name/ and Color Identifiers at the bottom of the Document.  Also that will all me to place the information Where i want it.  For ex....   I want to Send a job to plates and rather than Manually entering the Filename - Date and time - and Colors on the Bottom of the Plate/FIle.  I know that when i go to export a file or print a file there is Check box to put the page information on the file and it does what i want however it put the information too far down on the Plate.  It adds the information down in the bend area of the plate and that does not get Burnt or Processed in that area.  I need a script to move the information up so we can read it. 


How to implement hyphenation for Armenian in Adobe InDesign on Mac OS?

$
0
0

Hi,

I'm using Adobe InDesign CS4 and CS5.

I've never written any kind of plugin neither for Adobe InDesign nor on Mac OS, so I need your help to consider what's the best solution for this kind of problem.

I've read about ExtendScript, Linguistic Library Plug-ins SDK.

What should I use?

Thanks for any kind of help.

Does the constructor call new ExernalObject("lib:SomeLibrary"); work in InDesign CC?

$
0
0

I get an IO error saying that the file or folder doesn't exist. Does it have something to do with the call being unsupported in InDesign CC or if I need to download the library and save it somewhere? Some examples would be great. Also, if latter is the cause, some steps to resolve the same would be great.

Finding Unassigned Glyphs

$
0
0

If we import or enter a text code (e.g. a Katakana character )  for which a font has no Glyph, then Indesign will display an x'd rectangle.

 

Is it possible to find/scan for these with a script?

 

Thanks !

Adobe InDesign CS6 (8.0) Asset.placeAsset(document) getting undefined

$
0
0

UPDATE:


I commented out the addpage line and the script ran without any issues. So the error seems to come about when adding a page and then adding the library asset to it. So the question seems to lie in , "how to add a library asset on a new page?" The code below seemed to work with CS2.


Screen Shot 2015-04-01 at 2.03.04 PM.png


Hi - We wrote .jsx scripts for the CS2 version of InDesign. We now have InDesign CS6. When we run the scripts we get the following error:


Screen Shot 2015-04-01 at 1.27.19 PM.png

The basic function of the script is to import an xml file, select a library, get a specific asset from the library and then adds it to the document.

 

This is the section of code in the .jsx file that is generating the error; line 204 is generating the error

 

Screen Shot 2015-04-01 at 10.54.35 AM.png

 

I've checked both theTemplate and myDocument objects at the time of execution and they are both valid objects.


Screen Shot 2015-04-01 at 11.39.23 AM.png


I have no idea why it would throw an undefined is not an object error message? I've scoured the internet and I am unable to find anything related to this matter and the guy who wrote the scripts has left the the company. Any help in the right direction is greatly appreciated.


Also, this question was already asked in the Indesign forum, and they suggested I should ask this question here after no solution was found.


Adobe InDesign CS6 (8.0) Asset.placeAsset(document) getting undefined

Next paragraph following the GREP changeTo

$
0
0

Hi, I am trying to locate the next paragraph following the  changeTextPreferences.changeTo where I am applying a GREP to find a word/s between quotation marks

Thank you,

The line in My code which is supposed to extract the index

var Currentparagrap = EnFrColumn.paragraphs.index;      //is not working

 

my code:

trace("Remove Quotation Marks than bold the word/s in between (EN column)");

   var results = "";

  var xmlElement = ""; //--- xml tag associated to the findGrep string

var strChangeTo = ""; //--- changeTo string with quotations

var strtChangeToNew = ""; //--- ChangeTo string quotations removed

  if (EnFrColumn == "en"){

app.findGrepPreferences.findWhat =  '(")(\\w+)(")';

  results = this.document.findGrep();

if(results != null)

  for(var j=0; j< results.length; j++)

  if (xmlElement.markupTag.name == "ENMarginalNote"){

  if (app.findTextPreferences.findWhat = strChangeTo){

  app.changeTextPreferences.fontStyle = "Bold Italic";

 

//// want to change only the first word/s and the word/s in the following paragraph

 

 

 

story.changeText();

 

}

 

 

app.findTextPreferences = NothingEnum.nothing;

 

app.changeTextPreferences = NothingEnum.nothing;

}

}

}

]

A little help to combine two js scripts

$
0
0
Dear all,

I have made a script selecting a Color Setting preset and would like to combine it with a script updating the links in the current doc. I've been fiddling with functions but that didn't work. I'm very much a beginner, please be patient :-)

script setCMS:

var ListLength = app.colorSettings.cmsSettingsList.length;
var ColorList = app.colorSettings.cmsSettingsList;
var mySetting = 'Europe General Purpose 2';
var found = false;

for(var a = 0; a < ListLength; a++)
{
if(ColorList[a] == "Europe General Purpose 2")
{
found = true;
alert('found');
app.colorSettings.cmsSettings = mySetting;
}
}
if (found==false)
{
alert("Warning: <" + mySetting + "> can't be found");
}

script updateLinks:

var theLinks = app.documents[0].links;

for (var i = 0; i < theLinks.length; i++)
{
theLinks[0].update();
}

Best regards,
Rasmus

Indesign to incopy

$
0
0

Work flow is indesign + XML

 

 

How to export the incopy file form indesign application file

 

 

When I export the content form the application file most of the text disappear in the incopy file.

 

 

Could you advice


Arrays from listbox and file naming

$
0
0

To ask this question, I have to give some abridged background. I'm making a UI to data merge individual records to PDF or INDD, and currently have a UI that works:

Screen Shot 2015-08-08 at 2.25.33 pm.png

The dropdown fields call the header field from a tab delimited TXT file in the following fashion:

 

   myDoc.dataMergeProperties.selectDataSource(csvFile,);    //CSV import   var fileName1 = new Array();   csvFile.open('r');   while (!csvFile.eof)    {    fileName1.push(csvFile.readln().split(/\t/)[myName1-1]);    }   csvFile.close();   var fileName2 = new Array();   csvFile.open('r');   while (!csvFile.eof)    {    fileName2.push(csvFile.readln().split(/\t/)[myName2-1]);    }   csvFile.close();

 

The filename1 and filename2 arrays are then called upon later in the filenaming portion

 

myDoc.dataMergeProperties.exportFile((finished + fileName1 [i+start] + " "+fileName2 [i+start] +'.pdf'

 

So that's great and I know that works.


However, two fields isn't enough, and if the database only has one field, it needs an if/else. Alas i've made an improved UI:

 

Screen Shot 2015-08-08 at 2.28.49 pm.png

So now the UI allows one field, two, ten... even the same field over and over again for naming purposes... the UI works but I'm now having trouble with how the filename is added to the output.

 

I can get the listbox values on the right hand column to have the same indexOf values as the column on the left by using the following code:

 

 var myNameSplit = new Array();
 for(var i = 0; i < myWin.group5.groupb.myNewList.items.length; i++)   {   myFutureFiles.push(myWin.group5.groupb.myNewList.items[i].text);   }
 for(var i = 0; i < myFutureFiles.length; i++)
 {   for(var j = 0; j < myDropPresets.length; j++)   {if (myFutureFiles[i] == myDropPresets[j])    {    myNameSplit.push([j]);    }   }   }

 

myFutureFiles is an array made from the contents of the right hand side listbox (once the OK button is pressed), and myNameSplit is an array made by x-referencing the left listbox's indexOf so that fields still refer to the correct positions in the database (e.g. Last Name still refers to Last Name instead of Dt BP Sort Code if it were using the array reference 1)

 

BUT, this is where I come unstuck. If I replace the myNameSplit.push([j]); to push a csv split of the filename e.g.

 csvFile.open('r');
 while (!csvFile.eof)
 {
 myNameSplit.push(csvFile.readln().split(/\t/)[j]);
 }
 csvFile.close();

 

I know that I'll get an array that is three times longer than it should be (as there are 3 fields in the example), and that the filenames won't be correct.

 

Unlike the last UI that had two known fields for naming output, this UI allows for an unknown amount of fields for naming output. This is where I can't get any further, and need some direction. I honestly don't know what loop to use, or a multidirectional array, I have no clue.

 

For once, I've been trying NOT to bother the forum and to work it all out myself. For a solo effort so far to produce this interface has been a monumental task for me.

 

Many thanks, Colin.

How to make InDesign choose the actual 1st word in required style when using Running Head (Character style)

$
0
0

I need to have a running header with the first word in a required style. However, when I choose Running Head (character style) and choose "the 1st on page", it finds the first paragraph on page and if the paragraph is not whole (started on the previous page), it takes the first word from that paragraph. For example:

Výstřižek.PNG

I need the running header to show the word "Quis", which is the first word in Open Sans Bold. Instead, InDesign shows the word "Lorem" in the red text field.

Is it possible to create a script that will make InDesign unsee the first paragraph on page, if it is not whole when creating a running header?

Editing a current filename to add a suffix in InDesign

$
0
0

Hi there!

 

I have been searching through the forums trying to find something that would help me edit file names so that they include a suffix at the end. I did find some scripts that have gotten me to a point where I can rename the file with the shortname (var myPrepend), have it add a number, and then have it add the language suffix. However, I would like to keep the name of the original file and just add the language suffix if possible. The code below does help if I want to rename files completely but I would also like an option that will literally just add "_es" or "_fr" and others.

 

In addition to that, I would like to specifically target EPS and or ILLUSTRATOR files ONLY. I do not want to change the names of tiffs, jpegs, or anything else.

 

Is this at all possible? Thank you in advance!

 

Here is what I have so far:

 

var myDoc = app.activeDocument;

var myPrepend = prompt("Please enter issue shortname.\nExample: Client_Project", "Issue Shortname");

if (!myPrepend) exit();

var myLanguage = prompt ("Please enter language suffix.\nExample: _es (Spanish)", "Enter language suffix");

if (!myLanguage) exit();

var response = confirm("Warning: You are about to rename all images linked to the foremost Indesign Document - proceed?\n Keep in mind - it is not reversible!", false, "Rename Links Script");

if (!response) exit();

 

 

var doc = app.activeDocument,

    links = doc.allGraphics, count = 1, eqcount = 1, a = "000" ;

for(var i=links.length-1;i>=0;i--)

{

                var ext = links[i].itemLink.name.substr(links[i].itemLink.name.lastIndexOf(".")),

                    old = File(links[i].itemLink.filePath),

                    num = (count++).toString(),

                    newname = myPrepend + a.substring(0, a.length - num.length) + num + '_' + myLanguage + ext

                old.rename(newname);

                links[i].itemLink.relink(File(old.toString().replace(links[i].itemLink.name,newname)))

    }

Running socket sever without locking up InDesign

$
0
0

Is it possible to have a script running a socket server in the background that can listen for and interact with InDesign based on the requests it receives without locking up InDesign? So you can still use it regularly while the socket server is listening.  I have one now being set in a startup script but it locks up InDesign and you can't use it.

Why is PageItem.resize() unit independent? What other methods are?

$
0
0

I am continuing my journey through InDesign scripting units and values blues. I am currently trying to resize a PageItem and have found the following code resizes the selected PageItem in 'points' not my viewPreferences.horizontalMeasurementUnits, 'millimeters'.

 

document.selection[0].resize( CoordinateSpaces.pasteboardCoordinates, AnchorPoint.centerAnchor, ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO, [ 100, 0 ] );

 

I am still trying to work out the best way to work with units and values of size. I thought all properties and methods used the documents viewPreferences unit properties when dealing with values of size… Turns out I was wrong!

 

I am asking the experienced scripters:

 

  1. Considering all methods that manipulate, measure, compare or return values of size, what would be the ratio of methods that are unit dependent vs unit independent be? I.e. viewPreferences vs points.
  2. If Adobe were to work on making this more consistent in the future which direction do you think they would go?

 

I ask so that I can pick a methodology that I feel will be simpler across a wider range of methods and possibly be more future proof.

Viewing all 8771 articles
Browse latest View live