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

The associated InDesign XML crashes IDML file.

$
0
0

After move the floats in to text frame. The associated InDesign XML crashes IDML file.

 

How to remove the associated XML Link. Without untag the element.


Export all images with a specified frame appearance (Adobe indesign)

$
0
0

Hi All,

 

Please answer this question

 

This is a Original  Image:

bv.jpg

 

After placing in indesign, I will manually do fitting options like below

juice.png

In my Indesign document I made like this formatting approximately 30 images. When I will do package, in the links folder contain only original image. That manual fitting option image not exported. But I need the second one (Manual fitting image).

 

Anyone please help me!

Move more then one xml element to particular script labeled textframe

$
0
0

#include "glue code.jsx";

var myDoc = app.activeDocument;

var myLabel = "received";// change to label

var myPage = app.properties.activeWindow && app.activeWindow.activePage;

var myTextFrames = app.activeDocument.textFrames.everyItem().getElements().slice(0);

l = myTextFrames.length,

//____________________ XML RULE SET

var myRuleSet = new Array (new Move_element); 

with(myDoc){

    var elements = xmlElements;

    __processRuleSet(elements.item(0), myRuleSet);

}

 

 

function Move_element(){

    this.name = "r";

    this.xpath = "//a";

    this.apply = function(myElement, myRuleProcessor){

        with(myElement){

           // app.select(myElement);

      //     try{

        while (l--)

        {

            if (myTextFrames[l].label != myLabel) continue;

               myElement.placeXML(myTextFrames[l])

            //   break;

            myTextframes[l].fit(FitOptions.FRAME_TO_CONTENT);

       }

      

               // }catch(e){}

            }

        return true;

        }

    }

 

 

 

 

I need to move more than one xml element particular script labeled text frame but At a time I can only move one element.

 

 

Also while move the element script throws the below error message.

Error1.PNG

 

 

 

Its removing the next paragraph paragraph style. How to fix thix issue.

 

 

Error2.PNG

Export all images with a specified frame appearance (Adobe indesign)

$
0
0

Hi All,

 

Please answer this question

 

This is a Original  Image:

bv.jpg

 

After placing in indesign, I will manually do fitting options like below

juice.png

In my Indesign document I made like this formatting approximately 30 images. When I will do package, in the links folder contain only original image. That manual fitting option image not exported. But I need the second one (Manual fitting image).

 

Anyone please help me!

Intercept click on listbox (scriptui)

$
0
0

I have a dialog that, in part, lists the character styles in a document in a listbox that can be multi-clicked. In some cases the list is rather long and I'd like to be able to break it up into multiple columns. Peter Kahrel's ScriptUI for dummies points out that multi-column list boxes aren't really grids but sets of rows (so a click anywhere in a row selects the whole row). Not what I want. I set up multiple columns like he does in his table example. The issue I have is that each column functions independently of the others. So, for instance,

  • if I click on cell 1 of listbox 1 and then click on cell 2 of listbox 1, cell1 is deselected.
  • If I click on cell 1 of listbox 1 and then control-click on cell 2 of listbox 1, cell 1 and cell 2 are both selected.
  • If I click on cell 1 of listbox 1 and then click on cell 1 of listbox 2, both cell 1s are selected.
  • etc.

This is kind of awkward and makes it seem as if the columns aren't linked. From what I can tell (and confirmed for older versions of CC here: http://indiscripts.com/blog/public/ScriptUIEvents.pdf ) listboxes don't register the left mouse click at all. I am working on getting better at understanding the more complex aspects of event handling, like bubbling and propogation, but there are some gaps in my knowledge (to say the least). Does anyone know if it is possible to, perhaps, access information about a click from a change event? Or some other, cleverer approach? I'd rather avoid the dreaded scrolling panel if I can.

 

Here's a working example:

 

main();


function main(){
        testDlg(app.activeDocument);
}


function testDlg(funcDoc){
    //Creates a new modal dialog and sets some attributes.    var myDialog = new Window("dialog", "Test Dialog", undefined);    myDialog.location = [50, 50];    myDialog.orientation = "column";    myDialog.alignChildren = ["fill", "top"];       var myStyGrp = myDialog.add("group");    var myStyArr = funcDoc.characterStyles.everyItem().name;    if (myStyArr[0] == "[None]"){myStyArr.shift();}    var cols = myStyGrp.add("group");    cols.spacing = 1;    var i = 0, j = 20;    var smallArr = [];    while (j < myStyArr.length){        smallArr = myStyArr.slice(i, j);        cols.add("listBox", undefined, undefined, {multiselect: true, items: smallArr});        i = j, j += 20;    }    var arrMod = (myStyArr.length - 1) % 20;    if (arrMod > 0){        smallArr = myStyArr.slice(arrMod * -1, myStyArr.length - 1);        var smallCol = cols.add("listBox", undefined, undefined, {multiselect: true, items: smallArr});    }    cols.alignment = "left";    cols.alignChildren = ["left", "top"];    cols.addEventListener("change", function(){        //I am using this event listener currently, but its code is irrelevant (enables/disables and OK button).    });


//Displays the dialog and watches for the return value. If it is 1, OK was pressed and the values are returned to the values variable
    //via an array. Otherwise, exit the script.    if (myDialog.show() == 1){        return true;    }    else {return false}
}

Print every nth page from a book

$
0
0

I have a client in need of a script to print every nth page in an InDesign book. The book could be more than 20,000 pages so manually entering page ranges isn't going to work.  Has anyone written anything like?

Script for shrinking overset text?

$
0
0

I use data merge to create labels for guests attending functions. Usually this is around 500-1000 labels at one time. I usually set my text frame on the template page for a large point and then shrink it horizontally (I do this to minimize the number of pages I have to manually edit for overset text). I still get some names where they are long hyphenated names that create overset text.

 

Is there a script available where it will recognize there is overset text and then shrink the text down either by decreasing the point size or adjusting the horizontal spread of the text (maybe making it 100% to 80%)?

Change from one Paragraph Style to another?

$
0
0

I've done a lot of searching on this and I can only find more complex versions of what I'm trying to do.

 

I simply need to find all text in the document with an applied paragraph style and change it to another existing paragraph style. I've done trial and error a bunch of different ways and I'm not even coming close. Seems like it should be quite easy.

 

Please keep in mind that the first paragraph style cannot be deleted from the document, it needs to stay in my template.

 

Any suggestions? It'd be a huge help.

 

Thanks!


Remove XML text markers

$
0
0

Hi,

 

My requirement is to remove XML text markers between xml tags. It is like symbol :: :: .

 

It is already discussed in forum, link below:

 

Help Need!

 

But i need to remove it.

 

1) If i removed means it effect xml structure?

 

2) I tried with <FEFF> but not able to replace.

 

Regards,

Karthi

How can we Move the Contents of an xml element into text frame label in inDesign Script

$
0
0

Dear Friends,

 

My Requirement is::==>> Move the Contents of an xml element into text frame label ("format 1") by inDesign Script,

But  XML Structure of InDesign File should not be change & Data in XML Structure should remain as was before.....

 

My codeing is below:

 

var myDocument = app.activeDocument; 
var xpath = "//book-meta/book-title-group"
var frameName = myDocument.textFrames.itemByName("format 1");
var xpathTag = myDocument.xmlElements[0].evaluateXPathExpression(xpath);
var selectTag = myDocument.select(xpathTag)


Move_element(frameName, xpathTag)
function Move_element(frameName, xpathTag){
       var placeText = xpathTag.placeXML(frameName);   
}

 

also screenshot is below:

 

Untitled.png

 

Please suggest friends,

 

Thanks in Advance

KS

[Help] Looking to make object styles enable as layers as a script??

$
0
0

PastedGraphic-1.png

 

For object Styles, is it possible to identify a layer instead of individually assigning the object box from each page? How would i make a layer a certain object style? I made that the QR Code Frame is on a certain layer on a 200+ document.. Any way for me in object styles to identify the QR Code layer without individually going through each document and assigning that a new object style? A script or something that enables me to edit this would be awesome!

Remove a Column in Tab Text …

$
0
0

Hi All,

 

How are you today? 

 

My last night game:

How to remove a "text-column" in tab text? … and how to do it with [JS] just entering the number of the column to be deleted in an UI?

 

A special mention to Peter Kahrel for his amazing pdf on ScriptUI [revision in may 2016]:  ScriptUI for dummies | Peter Kahrel 

 

Maybe the script I wrote below is not really "orthodox" but it works nice playing with Grep researches.

If (surely) better, tell me [totally appreciated]!

 

Actually, the script works on text selection without UI:

Capture d’écran 2016-08-19 à 13.18.41.png

Capture d’écran 2016-08-19 à 13.19.25.png

Capture d’écran 2016-08-19 à 13.20.06.png

 

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;     
app.doScript         (         main,         ScriptLanguage.JAVASCRIPT,         [],         UndoModes.ENTIRE_SCRIPT,         "Remove a Column in Tab Text!"         );          
function main()     
{         var myParagraphs = app.selection[0].paragraphs;    for (var i = 0; i < myParagraphs.length; i++){           app.findGrepPreferences = app.changeGrepPreferences = null;   
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------       app.findGrepPreferences.findWhat = /(?s)^([^\t\r]*(\t|$)){1}\K(?1)/.source;   //  Define the colum number as: 0, for the column 1; 1, for the column 2; 2, for the column 3 …
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------          app.changeGrepPreferences.changeTo = "";    myParagraphs[i].changeGrep();    }    for (var i = 0; i < myParagraphs.length; i++){    app.findGrepPreferences = app.changeGrepPreferences = null;    app.findGrepPreferences.findWhat = /\t+$/.source;    app.changeGrepPreferences.changeTo = "";    myParagraphs[i].changeGrep();    app.findGrepPreferences = app.changeGrepPreferences = null;    }


}

 

 

As I said, I would like to play with an UI [made with ScriptUI].

The code I wrote to create it is:

 

 

// Here's the UI


var w = new Window ('dialog {alignChildren: "right"}', 'Remove a Column in Tab Text!');
  var group = w.add ('group');  group.add ('statictext {text: "Remove the Column:" }');  var myCol = group.add ("edittext", undefined, "1");   myCol.minimumSize.width = 50;    myCol.maximumSize.width = 50;  myCol.active = true;  var buttons = w.add ('group {alignment: "center"}');  buttons.add ('button {text: "OK"}');  buttons.add ('button {text: "Cancel"}');


if (w.show() == 2) {  // Cancel pressed  exit();
}

 

 

… But I'm always unable to continue: How to merge the 2 script parts!

 

Last comment: as I said in my first script comment, "0" targets the first column, "1", the second, "2" the third, …

in the UI, "1" (by default) will target the first column, "2", the second, "3" the third, …

So, I will need a calculation! …

 

Thanks a lot for any help and comment! 

 

Next future step for me:

Include the capacity to choose the target: selected text (as here), doc, story, para style and para style + "based on" para styles!  cool! 

Mimicking a Keystroke

$
0
0

Hi everyone,

 

I have a problem which I cannot find any information on so sorry to say I have no example or even a start of a script to put up here .

I am trying to mimic a keystroke, I use a plug-in which is not supported by scripting but I have set up a keyboard shortcut in InDesign to run an action.

The keystroke I manually use is " alt r ", I am wondering if there is some way of script mimicking this keystroke so I can run as part of a script?

 

Any help welcomed, Bren

Mapping Styles to tags, checking for unmapped

$
0
0

I've been unable to find any info on scripting the mapping of styles to tags.

 

I currently have a standing InD file that has all the styles mapped to tags. I've been using the Load button on the "Map Styles to Tags" dialog to load the

mappings into the file I want to export. This works OK but unfortunatly loads the ENTIRE style from the standing file, including formatting. I want JUST the style mappings to the tags from the standing file and maintain the formatting of the file I'm getting prepared for export.

 

I'd be most grateful if someone could supply a small code snippet or even some info as to where to look for scripting the mapping.

 

Related to that I'd like to script finding styles that are NOT mapped to any XML tag for when a new style if introduced.

 

Many thanks for reading,
Ken

two way hyperlink with another document (destination doc)

$
0
0

Hi All,

I trying to create the two way hyperlink to current or another document. Can you please guide to me how to achieve my target.

 

 

This is current document two way links successfully done (below code). Please guide to me, how to link another document also?

 

 

//roman number is current document, arabic number is another document

var myInput = ["xix:Preface for Instructors:v", "xix:Introduction for Writers:xv", "xix:Understanding the Technical Communication Environment:1"];//input variable

for(var s=0; s<myInput.length; s++){//travel based on input length

    var array = myInput[s].split(":");//split the first array

    var myInput1 = array[0]; //content page number

    var myInput2 = array[1];//content text

    var myInput3 = array[2];//hyperlink destination page number

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findChangeGrepOptions.includeMasterPages = false;

    app.findGrepPreferences.findWhat = myInput2;

    var myFound1 = app.activeDocument.findGrep();

    for(var g=0; g<myFound1.length; g++){

        var myPage=myFound1[g].parentTextFrames[0].parentPage.name;

        if(myInput1==myPage){//match the page number

            var myselect = myFound1[g].select();

            var myPage = app.activeDocument.pages.item(myInput3);

            var mytext = app.selection[0];

            var myDest = HyperlinkPageDestination.destinationPage = myPage;

            var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(mytext);

            var myHyperlinkURLDestination = app.activeDocument.hyperlinkPageDestinations.add(myDest);

            var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkURLDestination);

            }

        if(myInput3==myPage){//reverse link

            var myselect = myFound1[g].select();

            var myPage = app.activeDocument.pages.item(myInput1);

            var mytext = app.selection[0];

            var myDest = HyperlinkPageDestination.destinationPage = myPage;

            var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(mytext);

            var myHyperlinkURLDestination = app.activeDocument.hyperlinkPageDestinations.add(myDest);

            var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkURLDestination);

            }

        }

    }

//end the code

 

Additionally, the documents concept,

 

for(var dcn = 0; dcn < app.documents.length; dcn++){

    var document = app.documents[dcn];

    var mypages = document.pages;

    for(var p=0; p<mypages.length; p++){

        if(mypages[p].name==2){

            var mydocname = document.name;

            }

        }

    }

 

//but I can't go to next step.

 

 

Thanks in advance,

Selva


Applying master page in last page

$
0
0

Just a simple question, how to apply my Master Page "Last-Page" on the last page of my Document. Thanks

Punctuation stack

$
0
0

Hi,

 

My indesign document have lot of paragraph. My client dont want word and punctuation stack. That means, we dont want three same character, hyphens... So what i do is giving trackin/kerning or giving non-breaking space to avoid this stsck.

 

Is there any way to control this through script?

 

Also is there any way to control loose/tight line?

 

Thanks in advance,

Karthi

HELP! Scripts wont work "inside" InDesign anymore…

$
0
0

Hello,

 

strange things have happend over the weekend with my company workspace, Friday everthing was fine with my scripts, but now…

Who has a clue:

 

I cant fire Script within InD anymore, by shortcut or the scripts palette. Strange thing, if i open them in AppleScriptEditor and run, everything is fine…

But Script fired within InDesign throws:

Bildschirmfoto 2016-08-22 um 10.33.40.png

Other strange things happend aswell, but i cant say if IT screwed my Mac after i had gone firday. Every link in my document was broken, found out, my server was connected wrong somehow: It was mounted with an -1 behind…SRVMAR_01 had become SRVMAR_01-1…dont know why tho.

[JS][CC] Get the first character on each page

$
0
0

Hi scripters,

 

We have an InDesign xml out workflow and one of the requirements is page break. The InDesign document has one story for the text and then with multiple images and tables which have wraps to push the main text flow. Now i've written something which does exactly what I intended:

 

function pageAnchors(){    writeLog('    Creating Page Anchors...');    var myPages = myDoc.pages;    var myTitlePagePara = myPages[0].textFrames[0].paragraphs[1];    var myTitle1stChar;    for(var i=0; i<myTitlePagePara.characters.length; i++) {        if (myTitlePagePara.characters[i].contents.match(/^\w+$/)){            myTitle1stChar = myTitlePagePara.characters[i];            break;        }    }    var myTitleParentTag = myTitle1stChar.texts[0].associatedXMLElements[0];    var myTitlePageAnchorTag = myTitleParentTag.xmlElements.add("xref", myTitle1stChar);    myTitlePageAnchorTag.xmlAttributes.add("ref-type","page");    myTitlePageAnchorTag.xmlAttributes.add("id","page_"+myPages[0].name);    writeLog('        tagged first page '+myPages[0].name);    // alert(myTitle1stChar.contents);    for(var i=1; i<myPages.length; i++) {        // alert("page "+myPages[i].name);        if (myPages[i].textFrames.length > 0){            var my1stChar;            var myFrame = myPages[i].textFrames[-1];            var myText = myFrame.texts[0];            try{                var myLine = myText.lines[0];                for (var c=0; c<myLine.characters.length; c++) {                    try {                        if (myLine.characters[c].contents.match(/^\w+$/)){                            my1stChar = myLine.characters[c];                            break;                        }                    }                    catch(err) {                        writeLog('        error on page '+myPages[i].name+': '+err.message);                    }                }                var parentTag = my1stChar.texts[0].associatedXMLElements[0];                var pageAnchorTag = parentTag.xmlElements.add("xref", my1stChar);                pageAnchorTag.xmlAttributes.add("ref-type","page");                pageAnchorTag.xmlAttributes.add("id","page_"+myPages[i].name);                writeLog('        tagged page '+myPages[i].name);            }            catch(err){                writeLog('        Page '+myPages[i].name+' has an error: '+err.message);                      }        }        else{            writeLog('        Page '+myPages[i].name+' has no text frame.');                  }    }    writeLog('    Page anchors were created!');
}

 

My problem is I don't know how do I get to the image frames and tables (sometimes they are continued) if there are any on the page?

 

I appreciate any idea. I'm not very in coding but i can code enough for my needs so even a logic would be very appreciated.

 

Thanks,

-CharlesD

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?

Viewing all 8771 articles
Browse latest View live


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