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

How is APPLY_FRAME_FITTING_OPTIONS supposed to work?

$
0
0

I don't understand how the FitOption called Apply_Frame_Fitting_Options is supposed to work. According to documentation it applies the current frame fitting options to the frame and content,but as I see it (using scripting) it doesn't.

Is there anyone out there, who can explain?

 

You can follow my tests below, step-by-step:

 

1. Add a graphic frame to an empty document

2. Right click the frame. In the pop-up menu select Fitting / Frame Fitting Options. In the dialogue box select "Fit content Proportionally" for the frame.

3. Adjust the paths in the code below to two test images of your choice, with different proportions and sizes.

 

app.activeDocument.pages[0].rectangles[0].place(File('/C//temp//test.jpg'));
app.activeDocument.pages[0].rectangles[0].place(File('/C//temp//test2.jpg'));
app.activeDocument.pages[0].rectangles[0].fit(FitOptions.APPLY_FRAME_FITTING_OPTIONS);

 

The first image (test.jpg) will come out right, adapting its size proportionally within the frame.

Calling the fit method with APPLY_FRAME_FITTING_OPTIONS (line 3) will however not change the fitting, and neither will changing the fitting manually from the Frame Fitting Options dialogue, unless you right click and select "Fitting / Clear Frame Fitting Options".

 

Calling the fit method with a frameFittingOption explicitly set to PROPORTIONALLY or even read out from the frame (from the property called fittingOnEmptyFrame), works the way I would have expected from APPLY_FRAME_FITTING_OPTIONS.

 

app.activeDocument.pages[0].rectangles[0].place(File('/C//temp//test.jpg'));
app.activeDocument.pages[0].rectangles[0].place(File('/C//temp//test2.jpg'));
app.activeDocument.pages[0].rectangles[0].fit(app.activeDocument.pages[0].rectangles[0].frameFittingOptions.fittingOnEmptyFrame);

 

The documentation says:

FitOptions.APPLY_FRAME_FITTING_OPTIONS

Applies the current frame fitting options to the frame and content.

 

So why didn't ...

app.activeDocument.pages[0].rectangles[0].fit(FitOptions.APPLY_FRAME_FITTING_OPTIONS);

... re-apply the selected fittingOption?

 

 

I hope there is someone who can explain what I'm doing wrong when applying APPLY_FRAME_FITTING_OPTIONS, and how it is meant to work.

 

Best regards,

Andreas Jansson

 

The message was edited by: Andreas Jansson


How do I load an ICML File?

$
0
0

Hello,

 

Chapter 12 of the Javascript Scripting Guide talks about loading XML files into elements of an InDesign document, and about styling them using tags-to-style mappings. Given an InCopy ICML file, however, how do I place its content in a document? Using that same XML facility, or is there another and better way of loading and placing ICML files into InDesign documents?

 

Thank you,

Jens

more efficient right aligned page numbers in TOC

$
0
0
In order to right align the page numbers in a table of contents, after generating the TOC, I need to manually insert a tab character to the left of each automatically generated page number.

I'm looking for a more efficient way to do this. Is there a script that would do this automatically or maybe a GREP find/replace routine?

Select all image objects in a document, layer, page

$
0
0

Hi,

 

I'm reading the "Scripting Guide", but still I haven't found what I'm looking for...

 

I need to select, with three different JS Script, all the images that are inside the current selected InDesign document, layer and page.

 

Can someone help me, please?

 

Many thanks!

Call an ExtendScript Script from the Command Line

$
0
0

Hi! I can call an ExtendScript script from a command line or batch file just by using its path, but is there a way to pass parameters to the script? Thanks. -Rick

Cannot unzip using AppleScript

$
0
0

Hi, I use Indesign CC 20015, ExtendScript Toolkit and OSX 10.9. I try to use the following code to unzip a file:

 

try

{

app.doScript('do shell script "unzip /Users/admin/Desktop/images/04456_IMG1.zip"', ScriptLanguage.applescriptLanguage);

}

catch(e)

{

    $.writeln (e);

    }

 

However, I always goes into the catch clause and I get the following error:

 

IOError: error:  cannot create 04456_IMG1/04456_IMG1.jpg

checkdir error:  cannot create __MACOSX/04456_IMG1

                 unable to process __MACOSX/04456_IMG1/.

checkdir error:  cannot create __MACOSX/04456_IMG1

                 unable to process __MACOSX/04456_IMG1/._04456_IMG1.jpg.

 

I have set the zip file to -rwxrwxrwx. So it shouldn't be a permission problem. When i do "unzip /Users/admin/Desktop/images/04456_IMG1.zip" in the shell then it works.

 

Help very appreciated.

Adding hyperlinks and text anchors using Grep

$
0
0

Dear all,

 

I've been trying to add both a hyperlink text source and destination withing my document using Grep, but I can't seem to get it right. I'm looking find the source text which has the paragraph style "1HD" and starts with the word "Historical", then turn that into the source text for the hyperlink. Second, I'd like the text "References" later on to become the text anchor for the link destination. As a reference, here's what's defined:

 

var myHeader = app.findGrepPreferences.appliedParagraphStyle = "1HD";
var myHeader = app.findGrepPreferences.findWhat = "Historical \w*";

 

as well as

 

var myAnchor = app.findGrepPreferences.appliedParagraphStyle = "";
var myAnchor = app.findGrepPreferences.findWhat = "References";

 

I've been experimenting with any information I could get my hands on online, but I always seem to get one error or another. Any directions would be greatly appreciated!

 

Kind regards and thanks in advance,

 

Julian

adding a menu action

$
0
0

Hi all,

 

I'm trying to add a menu item with an onInvoke event listener.

I'd like my menu to invoke a script using the doScript method.

However, when I run it, it doesn't create my menu item.

 

Any advice here?

 

#include "C:/Users/jcahill/AppData/Roaming/Adobe/InDesign/Version 12.0/en_GB/Scripts/Scripts Panel/import idml translations.jsx"
#targetengine "session"
var m = app.menus.item( "$ID/Main" ).submenus.item( "Import translations" );

m.isValid&&m.remove();

var addCustomMenu = (function () {
   
    var customMenuAction = app.scriptMenuActions.add( "Choose IDML files" );
   
    var customMenu = app.menus.item( "$ID/Main" ).submenus.item( "Import translations" );
   
    var customMenuItem;
   
    if ( !customMenu.isValid ) {
       
        customMenu = app.menus.item( "$ID/Main" ).submenus.add( "Import translations" );
        customMenuItem = customMenu.menuItems.item( "Choose IDML files" );
       
        }
    var u;
   var f =  function  () {
       
        app.doScript( "import idml translations.jsx", u,u,UndoModes.ENTIRE_SCRIPT, "Import IDML files" );
       
        }
   
    var el = customMenuAction.eventListeners.add( "onInvoke", f, false );
    if ( !customMenuItem.isValid ) {
       
        customMenu.menuItems.add( customMenuAction );
       
        }
   
    }());
  


Avoid overlap anchor object

$
0
0

we'd like to fix a validation in Script to identify the anchored objects which are overlapping while running the script, The below code is working for most of the cases but if i have more than five query in a para its not working. could anyone advise on this?

 

var myDoc = app.activeDocument;

myDoc.preflightOptions.preflightOff = true;

myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

myDoc.zeroPoint = [0,0];

var myAllNotesArray = myDoc.stories.everyItem().notes.everyItem().getElements(), myNotesBasealign , myPage, myNotes , myNotetextframe = []; 

var pageLeft = myDoc.pages[0].marginPreferences.right - 9;

var pageRight = myDoc.pages[0].marginPreferences.left - 9;

 

 

try{if (myDoc.paragraphStyles.item('AuthorQueries') == null) { var AuthorQueries = myDoc .paragraphStyles.add({name:'AuthorQueries', appliedFont:"Times LT Std", pointSize:6, leading:7});}} catch (e){    }

 

 

 

 

    authorQueryPlacement()

    checkstackOrder()

    spineRelative()

    avoidOversetspineRelative()

 

 

    function checkstackOrder()

    {

        if (myNotetextframe != null)

        {

            for (var i =0;i<myNotetextframe.length;i++)

            {

               for (var j =i+1;j<myNotetextframe.length;j++)

                    {         

                        if (touches(myNotetextframe[i], myNotetextframe[j]) ==  true)

                        {

                        myNotetextframe[j].anchoredObjectSettings.spineRelative=false;

                        }

                    }            

                }

        }

       

     } // fn close

 

 

    function spineRelative()

    {

        if (myNotetextframe != null)

        {

            for (var i =0;i<myNotetextframe.length;i++)

            {            

                if (myNotetextframe[i].anchoredObjectSettings.spineRelative==false)

                {

                    for (var j =i+1;j<myNotetextframe.length;j++)

                    {

                        if (touches(myNotetextframe[i], myNotetextframe[j]) ==  true)

                        {          

                                if (myNotetextframe[i].geometricBounds[2]  > myNotetextframe[j].geometricBounds[0]  )

                                {

                                        var diff = myNotetextframe[i].geometricBounds[2] - myNotetextframe[j].geometricBounds[0]                                        

                                        mydiff = (myNotetextframe[j].anchoredObjectSettings.anchorYoffset) + ( diff +12)

                                        myNotetextframe[j].anchoredObjectSettings.anchorYoffset = mydiff;

                                 }

                                break;

                         }                           

                     }  

                 }

             }

        }

     } // fn close

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

function touches(bounds1, bounds2) 

if (bounds1.geometricBounds[2] < bounds2.geometricBounds[0]) return false; 

if (bounds1.geometricBounds[0] > bounds2.geometricBounds[2]) return false; 

if (bounds1.geometricBounds[1] > bounds2.geometricBounds[3]) return false; 

if (bounds1.geometricBounds[3] < bounds2.geometricBounds[1]) return false; 

  return true; 

}  

 

 

 

 

 

 

function authorQueryPlacement()

{

    for(i=0; i<myAllNotesArray.length;i++)

    { 

     if (myAllNotesArray[i].texts[0] != '' )

     {

           myPage = myAllNotesArray[i].storyOffset.insertionPoints[0].parentTextFrames[0].parentPage.name;

           myNotes = myAllNotesArray[i].storyOffset.insertionPoints[0].textFrames.add({geometricBounds:[0,0,pa geLeft,pageLeft]});  

           myNotes.anchoredObjectSettings.anchoredPosition=AnchorPosition.anchored;

           myNotes.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;

           myNotes.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.capheight;

           myNotes.anchoredObjectSettings.anchorXoffset=+5.5

            myAllNotesArray[i].texts[0].duplicate(LocationOptions.AFTER,myNotes.parentStory.texts[0]. insertionPoints[0]); 

           myNotes.paragraphs[0].applyParagraphStyle(myDoc.paragraphStyles.itemByName("AuthorQueries "));

           myNotes.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;

           myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;

           myNotes.anchoredObjectSettings.spineRelative=true;

           delEndEnterMark(myNotes)

           myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;

           myNotes.fit(FitOptions.FRAME_TO_CONTENT);   

           app.select(myNotes)

           frameHeight  = app.selection[0].geometricBounds[2] -  app.selection[0].geometricBounds[0]

           myNotes.anchoredObjectSettings.anchorYoffset=+ frameHeight;

           myNotetextframe.push(myNotes);

        }

    }

}

How to apply 'Paragraph Styles' into a Script? need help!

$
0
0

Hello,

 

I'm in Need of a Script for InDesign Cs3. I'm not new to programming. I know VB, C++ and Assmbler. I'm rather new to Javascript though, and just don't know all the syntex commands.

 

I would like a script that applies a Paragraph style to a document in indesign. But I would like the script ot apply this same paragraph style ot each paragraph on the document. Is there a way to let the script know to stop at the end of the text window, so that it doesnt make the text of the paragraphs exceed the page's size?

 

I wrote this script so far, It applies the 'Paragraph Style' to one paragraph, but I want it to apply to all the text in the word box on one page at a time. I'm just not sure how to make it apply to more than one paragraph with the style. Basically 'Thursday' and 'November 11' happens only once at the top of the page, but the paragraph style stays the same for every paragraph. 'Thursday' and 'Novmeber 11' are generic, each week it be a different day of the week and date of the given month, is there a way for the script to differ between dates and days?

 

var myDoc = app.documents[0]
var mySel = app.selection[0]
var myHolidayStyle1 = "Holiday"
//var myHolidayStyle2 = "Normal";

 

mySel.appliedParagraphStyle = myDoc.paragraphStyles.item (myHolidayStyle1);
mySel.paragraphs[-1].insertionPoints[-1].paragraphs[0];

 

 

I'm relatively New to Paragraph Styles too, so I'm hoping that will be simplier to do than to make the script, and maybe that for another prt of the forum, But I' just like to get the script part done. The Paragraph Style would be called "Holiday".I made this Paragraph style after hours of trial and error, now I just need to know how to apply multiple styles to a page and have those styles be consistent with each page. I work for a Newspaper company, so this has to be accurate and work.

 

This is an example of what the Paragraph header would look like:

 

Thursday     (present LT std. Black 22pt)

 

November 11  (Palatino Linotype Bold 10 pt)


Title of article: text goes here, bla bla bla
blablablablabl bla bla bla bla bla bla                    (Palatino LT std Roman 9 pt)
bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla. (end of Paragraph)

 


(next paragraph)
Title of article: text goes here, bla bla bla
blablablablabl bla bla bla bla bla bla
bla bla bla bla bla bla bla bla bla
bla bla bla bla bla bla.

 

repeat

 

repeat

 


Any help would be greatly appreciated. I would really like get a understand of how it should look like in the script, if someone could help me, that be wonderful.

 

Thank You.

Folder.getFiles Multiple Filters Mask

$
0
0

Hi all,

 

Folder.getFiles (".*") ... in this case it will get all types of files

 

Folder.getFiles (".jpg") ... in this case it will get all files with .jpg extension

 

... but how can I filter to get (for example) all files with ".jpg", " .tif" or ".eps" extension ?

 

ESTK help says: A mask string can also be the name of a function that takes a File or Folder object as its argument. It is called for each file or folder found in the search; if it returns true, the object is added to the return array.

 

Any idea of how to make such a function?

 

I will appreciate any help.

Override Master Items Displaces items on page (Javascript)

$
0
0

Hi,

 

I am trying to override all items in master pages using the follownig script:

 

function OverrideMasterItems() {
  var allItems = myDocument.pages[CurrentPage].appliedMaster.pageItems.everyItem().getElements();
  for(var i=0;i<allItems.length;i++){
    try{allItems[i].override(myDocument.pages[CurrentPage])}
    catch(e){}
  }
}

 

 

 

(thanks to Harbs fro providing this in another thread)

 

The problem I have is that once the script has run, all items move on the page. For example a text bos that in the master has coordinates of 0 and 1p6 ends up at 26p3 and 19p6

 

I'm probably over looking some really obvious settign somewhere but I just can't figure out what.

 

Working with CS6 and Javascript on a Mac

 

Thanks for any suggestions

Text Find/Change | Syntax for two special characters next to each other

$
0
0

Hi all,

just found an oddity with InDesign's app.findTextPreferences.findWhat concerning special characters.


I wanted to find two special characters encoded as <FEFF> that are next to each other.

Did that with InDesign's UI Text Find/Replace function and typed <FEFF><FEFF> in the search field.

In my sample document there were two of them next to each other so the result was:
one single instance.

 

Now the scripting side:

 

app.findTextPreferences.findWhat = "<FEFF><FEFF>";

var result = app.documents[0].findText();
alert(result.length); // 2

 

"<FEFF><FEFF>" found two instances instead of one.

 

The special characters in my sample document contain one Note object each so I could read out the Note's id number and found that indeed the two notes were found twice!

 

My solution was to change the search string a bit:

 

app.findTextPreferences.findWhat = "<FEFF>"+"<FEFF>";

var result = app.documents[0].findText();
alert(result.length); // 1

 

That gave me the right number of results.

Tested with InDesign CS 6 v8.1.0 and CC 2017 v12.0.0.81 on OSX 10.10.5.

 

Did I detect a bug?

Or should special strings always be written on their own as substrings and concatenated when working with Text Find/Replace ?

 

Regards,
Uwe

 

Message was edited by: Uwe Laubender

exportFile() - export selection option via script?

$
0
0

Hello,

 

From InDesign, I can select a group/textFrame/pictureFrame, and then click File -> Export. From this dialog, after I select my "save location," I can then choose to "Export Selection" by selecting the "Selection" radio button.

 

I'm wondering if this is possible to do with a script? The reason I ask is because I need to export single picture frames (actually, grouped frames, there will be text frames grouped with picture frames). In the SDK I see exportFile() options where you can select if you wish to export as PDF, IDML, JPG, etc. But nothing on "exporting selection". Does anyone know if this is possible, and if so, how it is done?

 

I know there is a bool you can set to "true" to display the dialog, but this all needs to be automated. Anyone have any thoughts on this?

 

Thanks in advance!

 

-Lloyd

Creating Color swatches?

$
0
0

I've came across this script Scripting Help! Batch color swap between libraries.  My question about this is.  How would i edit this to make multiple columns per page as opposed to listing them in one column?  THis works great For if we make a color book.  however we would also like to print a Roll of swatches.  IF this is insanely complex i'll just use this one.

 

Here's the script thats working so far..  This was made by ""

// Script by Trevor to make CMYK color Swabs http://forums.adobe.com/message/4890389#4890389 
var il = app.scriptPreferences.userInteractionLevel; 
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Make CMYK Swabs"); 
app.scriptPreferences.userInteractionLevel = il; 

function main() 
{     var swatchDoc, doc, swatchColors, l, newSwatch, newSwatchName, cv, ps, m, mtb, tb, ms, tf, ptf;     swatchDoc = app.activeDocument;     setupDoc();     app.activeDocument = doc;     swatchColors = swatchDoc.swatches.everyItem().getElements();     l = swatchColors.length;     while (l--)         {         if (swatchColors[l].name != "None" && swatchColors[l].name != "Registration" && swatchColors[l].name != "Paper")             {             newSwatch = doc.colors.add ({model: swatchColors[l].model, space: swatchColors[l].space, colorValue: swatchColors[l].colorValue});             newSwatch.space = ColorSpace.CMYK;             cv = newSwatch.colorValue;             newSwatchName = "C="+cv[0]+ " M="+cv[1]+ " Y="+cv[2]+ " K="+cv[3];             newSwatch.name = (doc.swatches.itemByName(newSwatchName).isValid) ? newSwatch.name : newSwatchName;             ps.insertionPoints[0].contents = "\r"+swatchColors[l].name+"\r"+newSwatch.name+"\r"             ps.insertionPoints[0].rectangles.add({geometricBounds:[0, 0, "15mm", "45mm"], fillColor: newSwatch.name /*  appliedObjectStyle: myStyle */});             };         }     ps.overflows ? addPages(tf): 0;     function setupDoc()         {             doc = app.documents.add({documentPreferences:{facingPages:0, pageOrientation: PageOrientation.PORTRAIT}});             m = doc.pages[0].marginPreferences;             mtb = doc.pages[0].bounds;             tb = doc.pages[0].bounds;             mtb[0]=mtb[2]-m.bottom;             ms = doc.masterSpreads[0].textFrames.add ({geometricBounds:mtb, textFramePreferences:{verticalJustification:VerticalJustification.CENTER_ALIGN}});             ms.parentStory.properties = ({digitsType: DigitsTypeOptions.ARABIC_DIGITS, hyphenation: 0, justification: Justification.CENTER_ALIGN, paragraphDirection: ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION, contents: SpecialCharacters.AUTO_PAGE_NUMBER});             tb[0] += m.top; tb[1]+=m.left; tb[2]-=m.bottom; tb[3]-=m.right;             tf = doc.pages[0].textFrames.add({geometricBounds:tb})             ps= tf.parentStory;             ps.properties = {digitsType: DigitsTypeOptions.ARABIC_DIGITS, hyphenation: 0, justification: Justification.LEFT_ALIGN, paragraphDirection: ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION, rightIndent: 2};         }         function addPages(ptf)         {             np = doc.pages.add();             ptf = np.textFrames.add({geometricBounds:tb, previousTextFrame: ptf});             if (ps.overflows) addPages(ptf);         } 
} 

 

Thanks

Chris


Vectorize paths in InDesign

$
0
0

Looking for a script to vectorize paths in InDesign.

 

Or someone to show me where is the InDesign's vectorize command (for paths, not types)…

script for running multiple find/change queries

$
0
0

Working on a large ID book document (*.indb), I have saved several dozens of Find/Change Queries (named "col01", "col02" etc.) that I run on "All documents". For a particular reason I have to run these queries several times a day.

 

So I was wondering whether there is, or whether anybody out there would write, a script that runs these queries one after the other. Given the size of the book, it might be necessary to provide for the script to pause after each query is run (before it goes on with the next), but I am just guessing.

 

Any help is much appreciated!

How to disable anchor settings

$
0
0

I need to disable the below feature how to do this via script.

Capture.GIF

script menu action invokes itself

$
0
0

Hello,

 

I'm wondering why my function gets called automatically when the script runs without me clicking on the menu item.

 

customMenuAction.addEventListener( "onInvoke", importTranslations(), false );

 

This runs everytime.

[JSX] On “Applying” a Paragraph Style through changeGrep() #override

$
0
0

Hi fellows,

 

In my document I temporarily use a special character (U+E100) that serves as a marker for applying some specific paragraph style:

 

GrepRestyle01.png

 

Then my script uses changeGrep() to both remove this marker and change the paragraph style at the corresponding location. It looks like this:

 

var myDoc = app.properties.activeDocument,    myBoldStyle = myDoc.paragraphStyles.itemByName('MyBoldStyle');

// Init.
app.findGrepPreferences = app.changeGrepPreferences = null;

// Find the marker U+E100
//    + the next char (captured in $1)
app.findGrepPreferences.findWhat = "\uE100(.)";

// Preset changeGrep so that it both removes the
// marker and change the paragraph style.
app.changeGrepPreferences.properties = {
    changeTo: '$1',    appliedParagraphStyle: myBoldStyle,
};

// Go!
myDoc.changeGrep();

 

Note that findWhat looks for two characters: the marker "\uE100" and the next character which is saved into $1 thanks to the parentheses in the "\uE100(.)" pattern. Then changeGrepPreferences is preset so that the whole capture is changed into $1 (which removes the marker) while assigning the desired paragraph style (myBoldStyle).

 

But I get two different results on two different platforms:

 

GrepRestyle02.png

 

GrepRestyle03.png

 

First result is of course what I was expecting. On platform 2, however, the paragraph style is applied but the very first character—that is, our $1 variable in the GREP command—seems to retain its old attributes. In other words, myBoldStyle does not override the text formatting although it's usually assumed that changeText/changeGrep commands having an appliedParagraphStyle property should work in clearing mode. (See for example these discussions: changeGrep() clears overrides, or Preserve Manual Overrides .)

 

My guess is there is in fact some Application or Document preference that controls this behavior, or maybe something related to the default paragraph style mechanism, but I don't find the needle in the haystack and can't figure out a generic solution to this issue. In case #2 all happens as if $1 was somehow “copied” with its own attributes, then the style applied, then $1 “pasted.”

 

Any clue?

 

Thanks for your help.

 

@+

Marc

Viewing all 15932 articles
Browse latest View live


Latest Images

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