Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all 15932 articles
Browse latest View live

FindChangeByList script

$
0
0

I'm trying to use this pre-made script in CS4, and I customized the accompanying .txt file with all our Find-and Replace needs, but when I actually try to the run the script on a document, the following error message comes up:

 

Error Number: 23

Error String: does not have a value

File: [name and location of jsx file follows]

Line: 159

Source: app.doScript(myString, ScriptLanguage.javascript);

 

Anyone know how to get past this? It's very hard to see what Line 159 in the script file has to do with anything.

 

 

 

Thanks.


[JS][CSX] ScriptUI Tip

$
0
0

Hi

 

I thought it was about time I contributed back on here, and share a quick tip I stumbled accross.

 

I have attached a screen shot of a dialog to select different scripts from, but you may notice the top text looks bold.

 

To make the text appear bold, simply repeat the line of code:

 

myText = myMainPanel.add('statictext',[15,15,260,34.5],'Choose the mailer to run the script for');

myText2 = myMainPanel.add('statictext',[15,15,260,34.5],'Choose the mailer to run the script for');

 

 

 

Anyway, just thought I'd share that with you.

 

Roy

Picture 5 copy.jpg

[JS][CS5.5] Interrupting a script via ScriptUI

$
0
0

I have a script that automates the placement of PDFs onto pages based on an input XML file. It works splendidly, but I would like users to be able to interrupt the placement, particularly if they have accidentally passed the wrong XML file to the script!

 

Since the total time taken for the PDF placements can be a while, I put up a simple palette window containing a progress bar to give an idea of progress. I also added a cancel button, but although the window appears to have focus at least some of the time during the placements, it never becomes possible to press the cancel button, nor to close the window. The mouse pointer is an hourglass the whole time.

 

Below is a simplified test script that demonstrates the problem. I've only run it on CS5.5 on Windows XP, but I believe it should work at least as far back as CS4 on Mac and Windows. It asks for a PDF file and then places it in a new document 16 times. My PC is slow enough that it takes enough time overall to give me plenty of time to hit the cancel button, if it were possible to do so. If your machine is really fast, you might want to increase gridSize so that the script has more to do.

 

Is there anything I can do such that my cancel button can be pressed? I don't need to see the PDF import window, so if that can and needs to be turned off, that's fine. I dabbled with chains of IdleTasks, and was able to press my cancel button, but the chain didn't always end, and I ended up locking things up nastily. I probably need to read up more on IdleTasks. There may be potential there, but I would like to support earlier than CS5 if possible, and IdleTasks were introduced in CS5.

 

#target indesign

(function() {
    var gridSize = 4;    // Ask user for a PDF    var pdfFilter =($.os.toLowerCase().indexOf("macintosh") != -1) ?        (function(file) { return file.name.match(/\.pdf$/); }) : '*.pdf';    var pdfFile = File.openDialog("Choose a small PDF to place...", pdfFilter);    if (!pdfFile) { return; }    // Show a simple progress bar    var active = true;    var win = new Window('palette', 'Placing ' + pdfFile.name);    var label = win.add('statictext', undefined, '');    label.preferredSize.width = 300;    label.justify = 'left';    var progressBar = win.add('progressbar', undefined, 0, gridSize * gridSize);    progressBar.preferredSize = [ 300, 12 ];    var cancelButton = win.add('button', undefined, 'Cancel');    cancelButton.onClick = function() { win.close(); };    win.onClose = function() { active = false; };    win.show();    // Make a grid of rectangles and place the PDF in each rectangle,    // advancing the progress bar as we go    var doc = app.documents.add();    var page = doc.pages[0];    var mp = page.marginPreferences;    var originX = page.bounds[1] + mp.left;    var originY = page.bounds[0] + mp.top;    var rectWidth = (page.bounds[3] - mp.right - originX) / gridSize;    var rectDepth = (page.bounds[2] - mp.bottom - originY) / gridSize;    var placePDF = function(n) {        var y = Math.floor(n / gridSize);        var x = n % gridSize;        label.text = 'Placing PDF in [ ' + x + ', ' + y + ' ]';        var rect = page.rectangles.add();        rect.geometricBounds = [            originY + y * rectDepth,            originX + x * rectWidth,            originY + (y + 1) * rectDepth,            originX + (x + 1) * rectWidth        ];        rect.strokeWeight = 0;        var pdfList = rect.place(pdfFile);        pdfList[0].fit(FitOptions.PROPORTIONALLY);        (progressBar.value)++;        // Even this sleep doesn't let me press the cancel button!        //$.sleep(1000);    }    for (var i = 0; active && i < gridSize*gridSize; i++) {        placePDF(i);    }    win.close();
})();

Clipping Paths in InDesign

$
0
0

Hi

 

I am working on an Indesign document (brochure) that contains hundreds of images. Is there a way I can select all images and run a command to show the clipping path (if there is one and if it isn't already highlighted).

 

I don't really want to check each image individually to check if the clipping path option is shown.

 

Thanks in advance

Reg. Decimal Alignment in selected column of a Table

$
0
0

Hi All,

 

Can anyone help me to align the selected column cells of table in decimal?

 

Thank you in advance.

 

Regards,

Sathya Rani M

Custom zoom script

$
0
0

I found a script by Jongware at InDesign Secrets for fitting on a page and then zooming:

 

app.layoutWindows[0].zoom(ZoomOptions.FIT_PAGE);

try {app.layoutWindows[0].zoomPercentage = Number(app.activeScript.name.match(/\d+/)[0]);} catch (e) {};

 

I modified it to fit on the spread and then zoom:

 

app.layoutWindows[0].zoom(ZoomOptions.FIT_SPREAD);

try {app.layoutWindows[0].zoomPercentage = Number(app.activeScript.name.match(/\d+/)[0]);} catch (e) {};

 

It works great for my needs if no items are selected on the spread.  However, the problem is that when a frame(s) is selected it doesn't center the spread anymore.  The center point (vertically and horizontally) becomes the center of the frame or group of frames selected.  Would anyone know how to modify this script so that it it is frame selection independant?  Thanks.

How add Item in an existing group ?

$
0
0

Hello,
I wonder ifit is possible toadd an item toa groupwithout ungrouping.

 

 

Thank you

JS: Convert Arabic numbers to Hebrew

$
0
0

Does anyone know of a function (preferably JavaSript) to convert Arabic numbers to Hebrew?

 

Thanks,

 

Peter


CS6 - how to get page number?

$
0
0

i have selected frame. I want to know page number, where it is.

aSel = app.selection[0];

alert (aSel.parent.name); - i get empty string

cause it' Object spread. And what to do then? (without losing of right/left reffering)

 

thanks

 

p.s. in CS3 i did it, and in CS6 i get stuck.

Can't get to add the data merge text placeholder to all the text frames on the document

$
0
0

I'm trying to put together a script that loops though all the pages in an indesign file, look for all text frames label caption1, caption2, caption3 … (every time you get to a new page the text frame label count starts again from 1) and add a data merge text placeholder: caption1, caption2, caption3… but this time when you get to a new page the count keeps going …caption4, caption5 and so on.

 

page 1 - Text frame label= caption1 => data merge placeholder= <<caption1>>

page 1 - Text frame label= caption2 => data merge placeholder= <<caption2>>

page 1 - Text frame label= caption3 => data merge placeholder= <<caption3>>

page 2 - Text frame label= caption1 => data merge placeholder= <<caption4>>

page 2 - Text frame label= caption2 => data merge placeholder= <<caption5>>

 

Right now the script is adding the data merge text placeholder only to the first two text frames (out of 6)  on page one (out of 8 pages) and just the first text frame on page two (out of 3)

 

Any help will be greatly appreciated

Here is the script:

 

var myDocument = app.activeDocument;

 

//---------------CALLS DATA MERGE SOURCE

main();

 

function main() {

 

var myDataSource = File.openDialog("Please select a datamerge source", "Text files:*.txt");

 

if (myDataSource != null) {

    myDocument.dataMergeProperties.selectDataSource(myDataSource);

    myDocument.dataMergeProperties.dataMergePreferences.recordsPerPage = RecordsPerPage.MULTIPLE_RECORD;

    }

}

 

//-------------------DATA MERGE FIELD

 

function get_field(captionString, myDocument) {

    var fields = myDocument.dataMergeProperties.dataMergeFields;

 

    for ( var f = 0, l = fields.length; f < l; f++ ) {

        if (fields[f].fieldName == captionString) {

            return fields[f];

        }

    }

    alert('Error: did not find any fields with name ' + field_name);

}

 

//--------------------------ADD DATA MERGE TEXT PLACEHOLDER

 

var countFrames= 1;

 

for (i=0; i<myDocument.pages.length; i++){  // TOTAL NUMBER OF PAGES IN DOCUMENT

        var capPerPage = 1;

 

    for(x = 0; x <  myDocument.pages[i].textFrames.length; x++){  //COUNT TOTAL TEXT FRAMES PER PAGE

 

        if(myDocument.pages[i].textFrames[x].label < 0){

            alert('can not find any caption frame');

          

        }else if(myDocument.pages[i].textFrames[x].label == 'caption'+capPerPage){  //IF THERE IS A TEXT FRAME LABEL 'caption1' EXECUTE

                var captionString = 'caption'+countFrames;

                var myTextFrame = myDocument.pages[i].textFrames[x];

                var myDataMergeProperties= myDocument.dataMergeProperties;

                var myStory = myTextFrame.parentStory;

                var myStoryOffset = myTextFrame.parentStory.insertionPoints[-1];

                var myNamePlaceHolder = myDocument.dataMergeTextPlaceholders.add(myStory, myStoryOffset, get_field(captionString, myDocument)); // ADD DATA MERGE TEXT HOLDER TO TEXT FRAME

              

                countFrames++; // INCREASE COUNT TO ADD DATA MERGE TEXT PLACE HOLDER TO NEXT TEXT FRAME

                capPerPage++;

               

                }

        }

}

Zoom settings change when adding pages

$
0
0

Hi

When adding a page to a document with this code:

app.activeDocument.pages.add(LocationOptions.AT_END);

InDesign automatically reverts the zoom setting to FIT_TO_PAGE

 

Is there a way to prevent this from happening?

I would like that it should stay at whatever it was.

 

 

Help will be much appreciated!

 

Thanks,

Davey

Modifying an old script from Dave Saunders

$
0
0

I've gotten permission from Dave Saunders to ask someone here to help modify a script he wrote way back when.

 

The script is posted at:

 

http://pdsassoc.com/downloads/PDFimportCropPref.jsx.zip

 

The purpose of the script is to change the Crop options of an already placed PDF (includes AI and INDD) file.

 

The script was written in 2006 for CS2 and so it doesn't work in today's environment.

 

I'm posting a copy of the text in the hope it doesn't get garbled.

 

//DESCRIPTION: Allows user to change PDF-import cropping preference

/*
©Copyright 2006 PDS Associates

This script must not be distributed without first obtaining written permission of:

Dave Saunders, proprietor
PDS Associates
P.O. Box 127
Allenhurst, NJ 07711-0127

e-mail: davesaunders@pdsassoc.com
*/

// Destroy any existing dialogs
if (app.dialogs.length > 0) app.dialogs.everyItem().destroy();
interactWithAll();
curSetting = app.pdfPlacePreferences.pdfCrop;
userChooses = askUser(curSetting);
app.pdfPlacePreferences.pdfCrop = userChooses

// +++++++ Functions Start Here +++++++++++++++++++++++

function interactWithAll() {
if (app.version == 3) {
app.userInteractionLevel = UserInteractionLevels.interactWithAll;
} else {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
}
}

function askUser(curValue){
var cropChoices = ["Art", "Bleed", "Content", "Media", "PDF", "Trim"];
var cropValues = [1131573313, 1131573314, 1131573315, 1131573325, 1131573328, 1131573332];
cv = -1;
for (var j = cropValues.length – 1; j >= 0; j–) {
if (curValue == cropValues[j]) {
cv = j;
continue
}
}
if (cv == -1) errorExit(“Current value of crop preference not recognized”);
with (app.dialogs.add({name:”Place PDF Crop Preference”})) {
with (dialogColumns.add()) {
with (dialogRows.add()) {
staticTexts.add({staticLabel:”Choose preference:”});
uchoose = dropdowns.add({stringList:cropChoices, selectedIndex:cv})
}
}
app.activate();
if (!show()) {
// User canceled;
destroy();
exit()
} else {
value = cropValues[uchoose.selectedIndex];
destroy();
}
return value
}
}

function errorExit(message) {
if (arguments.length > 0) {
if (app.version != 3) { beep() } // CS2 includes beep() function.
alert(message);
}
exit(); // CS exits with a beep; CS2 exits silently.
}

 

If you are interested in this challenge, your modified script will be mentioned at InDesignSecrets.com where we can link to your download page as well as extoll the brilliance of your scripting abilities. Sorry, no money, just glory.

 

Send me a message at Sandee at mac dot com if you want to tackle the script.

 

Thanks

CS5.5 (Applescript) Packaging and PDF creation script

$
0
0

Hello there.

 

I have an applescript droplet which, once an InDesign file is dragged onto it, it creates:

 

  • a High Quality PDF;
  • a Press Quality PDF;
  • a Smallest File Size PDF; and
  • a packaged InDesign file without the instructions.txt.

It's an amazing script but I need it to do one more thing... put the four items into its own folder.

 

Here is how the script looks so far:

 

 

on open mgItems    repeat with mgThisItem in mgItems                tell application id "com.adobe.InDesign"            try                open mgThisItem                set mgDocName to name of active document                set text item delimiters of AppleScript to " "                set mgShortName to text item 1 of mgDocName                set text item delimiters of AppleScript to ""                set mgHRFilePath to "Macintosh HD:Users:colly:Desktop:testfolder:" & mgShortName & "_HR.pdf" as string                set properties of PDF export preferences to properties of PDF export preset "[High Quality Print]"                tell active document                    export format PDF type to mgHRFilePath without showing options                end tell                set mgHRDigitalFilePath to "Macintosh HD:Users:colly:Desktop:testfolder:" & mgShortName & "_HRD.pdf" as string                set properties of PDF export preferences to properties of PDF export preset "[Press Quality]"                tell active document                    export format PDF type to mgHRDigitalFilePath without showing options                end tell                set mgProofFilePath to "Macintosh HD:Users:colly:Desktop:testfolder:" & mgShortName & "_proof.pdf" as string                set properties of PDF export preferences to properties of PDF export preset "[Smallest File Size]"                tell active document                    export format PDF type to mgProofFilePath without showing options                end tell                set mgPackageFilePath to "Macintosh HD:Users:colly:Desktop:testfolder:" & mgShortName as string                tell active document                    package to mgPackageFilePath with copying fonts, ignore preflight errors, copying profiles, updating graphics, including hidden layers, copying linked graphics and creating report                end tell                close active document            on error                -- decide what kind of error handling you want to include if the file won't open            end try        end tell            end repeat    display dialog "PDFs created and InDesign file packaged"
end open

 

As it works at the moment, many indesign files can be dragged onto this droplet, but they all end up in the same folder e.g. upon processing two indesign files, one called namequestion and the other called splash, all files populate the one folder as such:

 

namequestion.indd

namequestion.indd_HR.pdf

namequestion.indd_HRD.pdf

namequestion.indd_proof.pdf

splash.indd

splash.indd_HR.pdf

splash.indd_HRD.pdf

splash.indd_proof.pdf

 

what I would like the script to do is put each set of 4 items into their own folders e.g.

 

namequestion (folder)

   namequestion.indd

   namequestion.indd_HR.pdf

   namequestion.indd_HRD.pdf

   namequestion.indd_proof.pdf

 

splash (folder)

   splash.indd

   splash.indd_HR.pdf

   splash.indd_HRD.pdf

   splash.indd_proof.pdf

 

it's probably a rather simple fix but this is my first crack at an applescript... normally play with javascript and still learning all that.

 

Peter Kahrel has a very good javascript at http://www.kahrel.plus.com/indesign/batch_convert.html  but to get the outcome above (that's how it's been told to be made) Pete's script has to be run four times with much drag and dropping afterwards.

 

Many thanks

 

Colin

hi i want to create a shape with multiple point

$
0
0

My original text frame is:

first.jpg

All character make by using the pen tool point

I used that script(shows below) for first 2 character of that text frame which is create by the use of pen and pencil tool point:

 

var myTextFrame=myDocument.spreads.item(0).textFrames.add();

 

W = [["113.324296","212.731144"],["124.871437","212.731144"],["124.871437 ","205.148222"],["113.324296","205.148222"],];

 

myTextFrame.paths.firstItem().pathType = 1668051812;

 

W.splice(4,8,["152.405080","190.761163"],["152.405080","232.323775"],[ "156.821515","232.323775"],["156.821515","173.873789"],["153.555194"," 173.873789"],["152.090595","181.286355"],["144.653314","185.104713"],[ "144.653314","190.761163"],);

myTextFrame.paths.firstItem().entirePath = W;

myTextFrame.paths.firstItem().pathType = 1668051812;

 

but i am getting first both character as:

 

next.jpg

 

which is not write.

i want to the separate character which is make by the pen tool use such as above text frame. please provide me the write script for that type of text frame character. i am also given the path type.

 

 

Thanks

Linking a JS object to ScriptUI listbox item

$
0
0

I am writing a script that that takes elements from a document and for each element makes a custom object with its own properties and methods. This list of elements is then spat out into a ScriptsUI listbox.

 

How do I link each listbox item to its associated obejct? i.e. So if I double click on a listbox item it will run a particular method within that object.

 

P.S. I dont want to have to store array ids in a column or something hacky like that.


Creating Directory - Showing Listing Count on All Directory Pages

$
0
0

Hi to all InDesign Scripters

 

I am currently creating a directory with InDesign CS6, which contains the name of the person, address, cities, etc.

I have a question which is about showing the listing count per city,

for example, there are 30 names under a city (across spreads and pages),

how to show the number of listing count on InDesign automatically?

And how to make InDesign pick up what numebrs to use on that page?

(If I have two pages should show total listing count under the same city is 30)

 

I found a script to add sequential # to the paragraph styles, however I was only able to pick up the last number on the page using text variable -Running Headers function in InDesign, not the last number under the same city.

 

Any help would be appreciated!

 

 

Best Regards

V

Finding the end of line

$
0
0

Is It possible to find and change a character in the end of each line from a block text?

I know Indesign GREP can't do this, GREP only finds the end of paragraph, not lines.

I understand this is a problem because every time the text frame is modified, you have another character being changed.

Is It possible to do this with a script?

I have attached an image of what I would like to do.

The text in the image is Hebrew (R2L language) and the end of line is in the left.

Any help would be great.

Sami

exemple.jpg

Script Export Single Pages with Custom Filename and Paragraph Style?

$
0
0

I have a document called 'mydocument'

I have a multiple pages in the document.

Each page has one "title" styled with a pargraph style sheet called title.

I need to export each page as individual .jpg with a custom file name

 

mydocument-01-title.jpg

 

with the 01 being the page number

 

Seemed like a simple request... but turns out it is a bit of a challenge.

 

 

This scipt below I found on another thread is kinda working

it gives me a

title1.jpg

 

But I can't figure out how to....

1. add "mydocument" name

2. have a leading 0 on 1 digit numbers

 

Can someone please guide me, I would be for ever grateful.

 

 

if (app.documents.length != 0) {     var myDoc = app.activeDocument;    MakeJPEGfile();}else{       alert("Please open a document and try again.");  }  
function MakeJPEGfile() {           for(var myCounter = 0; myCounter < myDoc.pages.length; myCounter++) {           if (myDoc.pages.item(myCounter).appliedSection.name != "") {               myDoc.pages.item(myCounter).appliedSection.name = "";          }                        var myPageName = myDoc.pages.item(myCounter).name;          var myJpegPrefix = "";          var isStyleExist = true;           //Checking the existing of the paragraph style (filename)          try{              myDoc.paragraphStyles.item("title");          }          catch (myError) {              isStyleExist = false;          }           if (isStyleExist)            myJpegPrefix = getParagraphContent(myDoc.paragraphStyles.item("title"), myDoc.pages.item(myCounter)) + myPageName;          app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; // low medium high maximum          app.jpegExportPreferences.exportResolution = 72;          app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;          app.jpegExportPreferences.pageString = myPageName;            var myFilePath = "~/-client/JOYS - Just Organize Your Stuff/-Art/-art-book-kindle/" + myJpegPrefix + ".jpg";          var myFile = new File(myFilePath);          myDoc.exportFile(ExportFormat.jpg, myFile, false);     }}  // The new function, but needs to add checking the file name rules.  
function getParagraphContent (paragraphStyle, currentPage){    var paragraphContent = null;    for (var c = 0; c < currentPage.textFrames.length; c++)    {        for (var i = 0; i < currentPage.textFrames.item(c).paragraphs.length; i++)        {            if (currentPage.textFrames.item(c).paragraphs.item(i).appliedParagraphStyle == paragraphStyle)            {                paragraphContent = currentPage.textFrames.item(c).paragraphs.item(i).contents;   // Remove spaces and returns at the end:                paragraphContent = paragraphContent.replace(/\s+$/, '');   // Replace remaining spaces with hyphen:                paragraphContent = paragraphContent.replace(/\s+/g, '-');   // Make lowercase:                paragraphContent = paragraphContent.toLowerCase();                return paragraphContent;            }        }    }    return paragraphContent;} 

Indesign autosave

$
0
0

I believe there's some autosaving and backup feature in Indesign, where to turn off this option or rather set to a longer time..

My Indesign will get slow at some time interval.

 

Heeeeellllp..

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 !

Viewing all 15932 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>