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

replace groups and their content

$
0
0

Hi!

This shouldn´t be a question but a post about a short script I worked on for a week (the destiny of each newbee).

It works in larger documents. Of course there is a need for a library and its elements, special kind of items the script searches for and an open document with some pages.

 

I´m sure there are many other ways to make the script more short and with higher performance. Feel free to leave your opinion...

 

 

var myDoc = app.activeDocument;
var myObj = myDoc.selection[0];
var myPages = myDoc.pages.everyItem();
var numberOfPages = myDoc.pages.length;

var lastPgNumber = myDoc.pages.lastItem().name;

var newLabel;
var myNewLabel;
var myGroups = myDoc.groups;
var allMyGroups = myGroups.length;
var allMyObjects;
var myPageNumber; var oldObjPgNr;
var myObjects = [],
badObj = [],
myText = [],
myRectPositionY1 = [],
myRectPositionX1 = []
newPagesArray = [];

app.doScript(deleteObj, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Preislabel ändern");

function deleteObj() {
    for (var i=0; i < allMyGroups; i++) {        var thisGroup = myGroups[i];        //selecting groups (I only need the groups ON pages, with TWO items inside, one of the items should be a RECTANGLE) ...        if (thisGroup.parentPage != null && thisGroup.pageItems.length == 2 && thisGroup.allPageItems[1].constructor.name == "Rectangle") {            // ... in addition: the rectangle should be WHITE            if(thisGroup.rectangles[0].fillColor.name == "Paper") {                // add all "useful" groups in an ARRAY                myObjects.push(thisGroup);            }        }           //else if (badObj.push(thisGroup));    }
allMyObjects = myObjects.length;
for(var n=0; n < allMyObjects; n++){    // calculate the "real" PAGE-NUMBER    oldObjPgNr = myObjects[n].parentPage.name;    myPageNumber = numberOfPages - (lastPgNumber - oldObjPgNr)-1;       // get coordinates for the current object    myRectPositionY1.push(myObjects[n].geometricBounds[1]+ 6);    myRectPositionX1.push(myObjects[n].geometricBounds[0] );       // grab new object from  ibrary    newLabel = app.libraries.itemByName("SF_Kataloge_Zutaten.indl").assets.itemByName("SF_Preis_rot_NEU");    myNewLabel = newLabel.placeAsset(myDoc);       // move new object to the same page and location like the current object    myNewLabel[0].move(myDoc.pages[myPageNumber]);       myNewLabel[0].move([myRectPositionY1[n], myRectPositionX1[n]])       // replace contents of the new object with the contents of the current object    myNewLabel[0].contents = myObjects[n].textFrames[0].contents;     }
 for(var b=0; b < allMyObjects; b++){     // delete all groups    myObjects[b].remove();
}  

}  

 

Regards

A.

 

ps. It shouldn´t be forgetted: of course I had a lot of help from the community here!!! Thank you by the way!


Using scripts to place CC library item and export multiple PDFs

$
0
0

Hello InDesign wizzards,

 

I am trying to batch process files and need some scripting magic to make it happen. I have a "batch processing" script that would technically convert a bunch of INDD files into PDFs, but I need another step or two inserted in the process. This is what I'm hoping to automate:

 

INDD File > Open > Place item (in place) called "Setup1" from a library called "Prepress" > Export PDF with "S1" export setting > Append "S1" to the end of the PDF file name

 

This would need to happen with 3 different page sizes and 4 different "setup" placements. I could run them in batches (i.e. Page size 1 with setup 1, then with setup 2, etc) but of course ideally the script would just run the whole thing for me.

 

Hopefully this is enough info, thanks in advance!

Indesign cc2017 page size script

$
0
0

I have this script to generate a page size using variables. If i change the page size, i have to manually run the script. Is there a way to have the script run when i open the document and if i make changes to the sizing? Any help would be greatly appreciated.

 

var doc = app.activeDocument;

 

doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;

 

doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

 

var w = doc.documentPreferences.pageWidth,

 

    h = doc.documentPreferences.pageHeight,

 

    pagesize = app.activeDocument.textVariables.itemByName("PageSize");

 

pagesize.variableOptions.contents = h + " in X " + w + " in"; 

Apply Text variable to selected text?

$
0
0

Right now I have the Text variable where it will add to the document.  And i have it set to a shortcut so that way if i need it i can add it My question is. How can i make it apply to the text i have selected?

var doc = app.activeDocument;
var tvLn = doc.textVariables.item("L#Date");      !tvLn.isValid && tvLn = doc.textVariables.add({name:"L#Date", variableType:VariableTypes.CUSTOM_TEXT_TYPE});       tvLn.variableOptions.contents = String( getLDate() ); 
function getLDate() {    var date = new Date();     var month = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];     var formatDate = ("/" + date.getFullYear()).substr(-2);         return month[date.getMonth()] +"/" + formatDate; 
 }

CC2017 link filePath not normalized

$
0
0

Hi all,

 

I had a script that works for many years and now with InDesign CC 2017 I have a strange behavior :

In the list of links, my image path start with "P/:" (slash in first position)

But when I "Copy Full Path", I get a classic "P:/".

Capture d’écran 2017-05-05 à 17.23.55.png

This is the same problem in my script because I try to detect some path which start with "P:/" and of course it's not working anymore.

Did somebody have an idea ? I other function in class Link but nothing really relevant.

A detail that could be important : this file was created with Windows and I edited in Mac version.

 

Thanks for your help,

JavaScript code for customisable book

$
0
0

Hi all,

 

Lone time Adobe user just getting into scripting here. I have been teaching myself the basics, and it's going pretty well, but I feel it would be a lot faster to ask for some help here.

 

I am am writing a book that will need to:

 

1) put a different name for the character in each book (so finding whatever I typed as the placeholder and replacing it with a name throughout the whole document)

 

2) re-link lots of images. The idea is that there will be placeholder graphics throughout the book but I'll have a library of different character graphics I'll want to re-link / replace in each book. These are all created in the same location in Illustrator so will drop in exactly in the right place

 

 

So I'm looking for JavaScript code, or help with writing it, that looks at a set of parameters someone sent me (like name, hair colour etc.), replaces text and re-links images to the appropriate ones in the library, then exports as a PDF ready for print. Ideally, I'll need the script to go through multiple sets of parameters (different people with different names, hair colours etc.) and do the above for each.

 

Its a big task I know, but any assistance from anyone, even with only a component of this, would be really useful and greatly appreciated.

 

Thanks  advance!

Formatting only newly placed text

$
0
0

I currently have a script that is placing the contents of a document at the cursor insertion point, and then goes on to apply some formatting to the TextFrame it was inserted into. This works situationally, but I need to find a way to reference only the text that was brought in by the Place so that I can format it without changing the whole TextFrame. Alternatively, is it possible to create a temporary frame to hold placed text, format it, and then move the formatted text to the insertion point?

 
Set myTextFrame = myDocument.TextFrames.Item("MyFrame")
Select Case TypeName(myIndesign.Selection.Item(1))
     Case "InsertionPoint"
          myIndesign.Selection.Item(1).Place "R:\mid\text\!MID FINAL.doc"
     End Select

myTextFrame.ParentStory.Texts.Item(1).ApplyParagraphStyle myParagraphStyle, True

InDesign http request fails: no shared cipher

$
0
0

Hello,

 

From my ExtendScript I try to call to a server over https:

 

  var xmlhttp = new XMLHttpRequest();

  xmlhttp.open('GET', 'https://***/api/books', true);

  xmlhttp.setRequestHeader('Authorization', 'Basic NDI5MDk...');

  xmlhttp.send(null);

  if(xmlhttp.status == 200) {

    alert(xmlhttp.responseText);

  }

 

The code triggers the following output in the console:

 

net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH

 

Tracking the request content, it seems that ExtendScript uses Version: 3.2 (TLS/1.1) and then Version: 3.1 (TLS/1.0). But looking at the server log on the other side, there is only a single error message:

 

2016/09/29 11:25:34 [info] 7048#7048: *4396957 SSL_do_handshake() failed (SSL: error:1408A0C1:SSL routines:ssl3_get_client_hello:no shared cipher) while SSL handshaking, client: **.**.**.**, server: 0.0.0.0:443

 

The web server is very stable and well maintained, runs TSL 1.2 and supports all secure ciphers:

 

443/tcp open  https

| ssl-enum-ciphers:

|   TLSv1.2:

|     ciphers:

|       TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A

|       TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (secp256r1) - A

|       TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 (dh 4096) - A

|       TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 (dh 4096) - A

|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (secp256r1) - A

|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (secp256r1) - A

|       TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 (dh 4096) - A

|       TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 (dh 4096) - A

|       TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 2048) - A

|       TLS_RSA_WITH_AES_256_GCM_SHA384 (rsa 2048) - A

|       TLS_RSA_WITH_AES_128_CBC_SHA256 (rsa 2048) - A

|       TLS_RSA_WITH_AES_256_CBC_SHA256 (rsa 2048) - A

|     compressors:

|       NULL

|     cipher preference: server

|_  least strength: A

 

What is happening here? Is there a problem between TLS 1.0/1.1 on the client and 1.2 on the server side? What would be the appropriate way to handle this problem?

 

Thank you!


[ANN] IdExtenso: InDesign JSX Framework

$
0
0

Hi colleagues,

 

I'm open-sourcing IdExtenso—a (new) ExtendScript framework for InDesign scripters—and I'd be happy to get feedback, issue reports, requests, etc.

 

The core structure may seem a bit esoteric but the key idea is really simple: delivering rich and efficient modules thru an easy-to-use API embedded a single object ($$). You can already test nice features such as JSON, HTTP, localization helper, but that's the tip of the iceberg, I hope ;-)

 

Thanks for joining, or sharing: GitHub - indiscripts/IdExtenso: ExtendScript Framework for InDesign Ninjas

 

Best,

Marc

mojikumi

"Error" placing icml files with anchored [object Group]

$
0
0

Hello, fellows.

I'm having troubles with icml files.

I can export all my textFrames with no problems.

Almost all textFrames has anchored group of objects within it. More than one. And some of those groups have a lot of objects.

Like this:

ScreenCapture_203621_09-05-2017.png

 

The problem is: when I place the exported icml file into a new document, all those groups became locked and InDesign shows an error ("Object is locked"). In some cases, just one error window appears. But, in other cases, a lot of errors are shown. A LOT. I don't know how to solve this. I tried to write a code to create a new document and then disable user interactions and then place the icml file. But the error persists.

 

Any ideas?

Scripting and smartTextReflow

$
0
0

Hi, I've been through loads of posts on this forum and haven't found an answer although a couple of people have had similar problems. Hopefully some guru will have an answer.

1. ImportXML via script - OK

2. Run some XML Rules e.g. adding page breaks - OK

3. Having smartTextReflow via a master page primary text flow - NOT OK

 

As others have pointed out, smartTextReflow runs asynchronously. I know this to be true since getting the page count after step 2 returns the initial number of pages (2), not the final number of pages.

 

Have tried:

app.waitForAllTasks()

document.recompose()

$.sleep(1000...)

All to no avail.

 

Is there any event listener or way to trigger some code (to remove any empty pages etc) after the reflow has finished?

Looking for a freelance InDesign Script writer for hire

$
0
0

Hello InDesign community,

 

I am looking to hire an InDesign script writer for specific purpose. I have a catalog of 15,000 items my company produces every year. For next year's catalog, my supervisor wants us to include a price for every item. Currently, all of our items have a table that includes the item number, different attributes for that product, and a cell at the end for the price. What I would like to do is, take an excel sheet that includes the item number in one cell and the price in the other, put that information into InDesign, and have a script match up the item number from the spreadsheet with the item number in the catalog pages and replace the last cell in that row with the newly created price.

 

I would love to hire a freelance script writer to make this work for us.

 

If you are a person qualified to do that, or if you know someone who might, please contact me at gjfey34@gmail.com

 

Thank you!

 

Gerry

how to make a catalog by CharacterStyle

$
0
0

default,a catalog be made by ParagraphStyle, but, how to use CharacterStyle to do it.

Incorrect value of $.os on Windows 10

$
0
0

ExtendScript gives incorrect value of the operation system version:

 

$.os // -> "Windows 7/64 6.2 (32-bit emulation)"

 

Tested on Windows 10 64bit, ESTK and InDesign CS6 and CC2015.


Changing a calcutator Script

$
0
0

Hello Everyone!

 

I've found this script and it is really helpful!

I still got a Problem. I want to put "h" instead of 0.00 for the first column.

And like i don't know anything about scripting i'm a bit stuck.

Any help would be super appreciated!

 

Best,

Simon

 

Like my Table looks like:

Bildschirmfoto 2017-05-11 um 15.55.44.png

 

Like my Table should look like:

Bildschirmfoto 2017-05-11 um 15.57.34.png

 

and here is the Script:

 

// simpleBilling.jsx   

  

var MWST = 8/100;  

if (app.selection[0].parent.constructor.name == "Cell"){   

    var myTable = app.selection[0].parent.parent;   

    var myLastCol = myTable.columns.length-1;   

    var myLastRow = myTable.rows.length-1;   

    var myStunden = myTable.columns.item(1).contents;

    var myNetto = myTable.columns.item(2).contents;

    var mySum = 0;   

    var myPrice = 0;

    for (k = 0; k < myLastRow-2; k++) {   

 

         myPrice = (((myTable.columns.item(1).cells[k].contents))*((myTable.columns.item(2).cells[k].content s)));

 

         myTable.columns.item(1).cells[k].contents = digitFormatter(myTable.columns.item(1).cells[k].contents);

         myTable.columns.item(2).cells[k].contents = digitFormatter(myTable.columns.item(2).cells[k].contents);

 

         myTable.columns[myLastCol].cells[k].contents  = digitFormatter(myPrice);   

         mySum += (myTable.columns[myLastCol].cells[k].contents.replace(",",  "."))*1   ;

 

    }   

    

    myTable.columns[myLastCol].cells[myLastRow-2].contents  = digitFormatter(mySum);   

    myTable.columns[myLastCol].cells[myLastRow-1].contents  = digitFormatter(mySum*MWST);   

    myTable.columns[myLastCol].cells[myLastRow].contents  = digitFormatter(mySum*MWST + mySum);   

}  

 

 

function digitFormatter(x) {  

    // Quelle: http://www.dcljs.de/faq/antwort.php?Antwort=rechnen_runden#6  

    var k = (Math.round(x * 100) / 100).toString();  

    k += (k.indexOf('.') == -1)? '.00' : '00';  

    var p = k.indexOf('.');  

    return k.substring(0, p) + ',' + k.substring(p+1, p+3);  

}

Add "bleed size" to script...

$
0
0

Here's the script. How do i add a "bleed size" variable to it?

 

// https://forums.adobe.com/thread/2049382 

// Main script by Loic Aigon Add highly customized Text Variables to InDesign | Ozalto 

// Additions (First Page Dimensions and variable update on script execution) 

// and modifications (without permission, sorry Loic) by Trevor http://www.creative-scripts.com 

#targetengine 'usernameVariable' 

 

//This function adds static text variables in InDesign 

//They won't be dynamically updated though. 

//That's why we need the updating function below 

 

function toTitleCase(s) { // By Trevor 

    return s.toLowerCase().replace(/\b\w/g, function () {return arguments[0].toUpperCase()}); 

 

function myRound(thisNumber, digits) { // By Trevor 

        digits = (digits) ? Math.pow(10, digits) : 1000; 

        return Math.round(thisNumber * digits) / digits; 

 

function addVariables(openEvent){ 

    if (!openEvent) return; 

    var doc = (openEvent.constructor == Document) ? openEvent : openEvent.parent; // By Trevor 

    while ( doc.constructor.name != "Document" ) 

    { 

        if ( doc.constructor.name == "Application" ){ return; } 

 

       doc = doc.parent; 

    } 

 

    //Adding User name to text variables 

    createTextVariable(doc, "User name", $.getenv($.os[0] == "M" ? "USER" : "username") ); // changed by Trevor 

    //Adding Computer name to text variables 

    createTextVariable(doc, "HD Name", (Folder.system).parent.displayName ); 

 

    //Adding Computer name to text variables 

    createTextVariable(doc, "Computer Name", getComputerName() ); 

 

    //Adding a link to my website 

    createTextVariable(doc, "_About Loic Aigon", "Feel free to visit my website: http://www.loicaigon.com !" ); 

 

    //Adding a link to my website 

    createTextVariable(doc, "_About Trevor", "Feel free to visit my website: http://www.creative-scripts.com !" ); // by Trevor 

 

    //Adding First Page Dimensions 

    createTextVariable(doc, "First Page Dimensions", getPageDimentions(doc.pages[0])); // by Trevor 

 

 

addVariables(app.properties.activeDocument); // callback by Trevor 

 

//Generic function to add static custom text variables 

function createTextVariable(target, variableName, variableContents){ 

 

    var usernameVariable = target.textVariables.itemByName(variableName); 

    if(!usernameVariable.isValid){ 

        usernameVariable = target.textVariables.add(); 

        usernameVariable.variableType = VariableTypes.CUSTOM_TEXT_TYPE; 

        usernameVariable.name = variableName; 

    } 

    usernameVariable.variableOptions.contents = variableContents; 

 

 

//Snippet for grabbing the  deep name of the computer 

function getComputerName(){ // by Trevor 

    return $.os[0] == "M" ? app.doScript("get computer name of (system info)", ScriptLanguage.APPLESCRIPT_LANGUAGE) : $.getenv("computername"); 

 

function getPageDimentions(page){ // by Trevor 

    var width, height, bounds, units, decPlaces; 

    // function presumes that normal pages 

    // i.e. same vertical and horizontal and no page shape transformations 

    decPlaces = 3; 

    units = toTitleCase(page.parent.parent.viewPreferences.horizontalMeasurementUnits.toString()); // If you forgot to include the toTitleCase function then remove the method 

    bounds = page.bounds; 

    height = bounds[2] - bounds[0]; 

    height = myRound(height, decPlaces); 

    width = bounds[3] - bounds[1]; 

    width = myRound(width, decPlaces); 

    return width + " X " + height + " " + units 

 

//Add listeners to update file when opened. 

app.addEventListener('afterOpen', addVariables); 

// You might like to add some or all of these to make the update better 

app.addEventListener('beforeSave', addVariables); // by Trevor 

app.addEventListener('beforeSaveAs', addVariables); // by Trevor 

app.addEventListener('beforeSaveACopy', addVariables); // by Trevor 

app.addEventListener('beforeExport', addVariables); // by Trevor 

app.addEventListener('beforePrint', addVariables); // by Trevor 

app.addEventListener('beforeDeactivate', addVariables); // by Trevor 

app.addEventListener('afterActivate', addVariables); // by Trevor

How to get full path of parent script that uses #include

$
0
0

Script A has an #include "ScriptB" line.

 

ScriptB now needs the full path of Script A -- i.e., exactly the info you get from $.fileName if you run that line in Script A.

 

But the command $.fileName if it appears in Script B returns the path to Script B, not Script A. (I always thought that #include actually causes the contents of the #include statement to be copied over to that location, but this proves that it is not quite so simple.)

 

Obviously, this path could be assigned to a variable in Script A and then used in Script B. But Script B is a library component, and the whole point is not to have to update the two-dozen Script A's that are calling Script B. So I would rather not have to modify all the Script A's. It would be better if Script B stays an independent module.

 

So: How to get the full path of Script A, when you're inside Script B, which has been #included in Script A?

 

For a moment I thought I had found an answer: The first line of the string $.stack is the file name of Script A. But it doesn't include the path, just the file name, so not good enough.

 

Can anyone help?

 

Thanks,

Ariel

Launch script with "Startup script" folder

$
0
0

Hello,

I have a script that process, save and close some documents.

I'm having some problems when I launch it using the "startup script" folder: when the script tries to close documents using the standard function myDocument.close(SaveOptions.NO), the documents aren't closed.

But, if I launch the same script with ExtendScript Toolkit, documents are closed correctly.

Any thoughts?

Thank you

addEventListener not working when there's loop

$
0
0

Hi there,

 

addEventListener seems not working when there's a loop in the program. Any way to solve this?

Thank you...

 

;---------------------------------------------------------------------------------------

var myWin = new Window ( "window", "LOOP TESTING.." );
var myTxt = myWin.add("statictext", undefined, "Testing.....................");
var cancel_button = myWin.add ("button", undefined, "Cancel");
cancel_button.addEventListener ("click", function () {alert("cancel_button.addEventListener");myWin.close();exit();});
myWin.show();

for (var i =0; i<20;i++){
    myTxt.text = String("TEsting: " + i);
    $.sleep(100);  
}

myWin.close();
exit();

Viewing all 8771 articles
Browse latest View live


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