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

Delete entire row if any cell is blank

$
0
0

Hi all

 

I have found this script and it works perfectly for its purposes (if an entire row has no data/length, then remove it).

 

var myDocument = app.activeDocument;

for(var i=myDocument.textFrames.length-1; i>=0; i--){

    for(var j=myDocument.textFrames[i].tables.length-1; j>=0; j--){

        for(var k=myDocument.textFrames[i].tables[j].rows.length-1; k>=0; k--){

            myContents = 0;

            for(var l=myDocument.textFrames[i].tables[j].rows[k].cells.length-1; l>=0; l--){

                if (myDocument.textFrames[i].tables[j].rows[k].cells[l].contents != "") myContents++;

                }

            if (myContents == 0) myDocument.textFrames[i].tables[j].rows[k].remove();

            }

        }

    }

 

However, in the first column of my table, I have some text, and in the second column, I have no data.

 

How do I delete an entire row (including the first column containing text) using a script if just one cell of the row is blank?

I like the above script as I don't have to enter a table to run it - i.e. it will just apply to the whole document as I have many pages...

 

Thanks!


XSLT file

$
0
0

Hi,

I am very new in using XSLT to format XML file.

I would like to know if there is a tool to generate an xslt/fo file from an xml?

Thank you,

How to maintain the quality of the reduced image?

$
0
0

  

                        InDesign CC                                                           InDesign 5.5

 

 

Hi.

 

Both are the same source and image.

 

I want to improve the image quality of  the InDesign CC ScriptUI.

 

Any ideas?

 

Thanks.

 

 

 

 

Save image

  set_png_export_options();    var myFileName = "preview.png";    var myFilePath = "C:/Users/user1/Desktop/" + myFileName;    var myFile = new File(myFilePath);    app.activeDocument.exportFile(ExportFormat.PNG_FORMAT, myFile);

function set_png_export_options() {
    with(app.pngExportPreferences) {        antiAlias = true;        embedColorProfile = true;        exportResolution =  72;        exportingSpread = false;        PNGColorSpace = PNGColorSpaceEnum.RGB;        PNGExportRange = PNGExportRangeEnum.EXPORT_ALL;        PNGQuality = PNGQualityEnum.HIGH;        simulateOverprint = true;        transparentBackground = true;        useDocumentBleeds = true;    }
}

 

 

 

 

Load image

main();
function main()
{    Image.prototype.onDraw = function()    {    if( !this.image ) return;    var WH = this.size,    wh = this.image.size,    k = Math.min(WH[0]/wh[0], WH[1]/wh[1]),    xy;    wh = [k*wh[0],k*wh[1]];    xy = [ (WH[0]-wh[0])/2, (WH[1]-wh[1])/2 ];    this.graphics.drawImage(this.image,xy[0],xy[1],wh[0],wh[1]);    WH = wh = xy = null;    }    var w = new Window ("dialog", "test");    var photo = w.add ("image", undefined, File ("C:/Users/user1/Desktop/preview.png"));    photo.size = [200,300];
 w.show ();
}

Any method to add the event listener for text frame content change?

$
0
0

I'm trying to add the event for capture the user typing anything in the document, however, Indesign have no any event to do so, any ideal?

Is it impossible?

thx a lot~

Is there script to put pages from a large ID-file and convert it in a pdf with the correct pagenumbers and table of contents?

$
0
0

This looks a lot like the 'book' standard option in Indesign, but different.

What i want is this: the source is one large ID-document (a partbook), wich contains everything.

From this source i want, lets say, pag 1 (cover), 2 (table of content), and a lot of different part pages convert to a pdf where the pagenumbers and table of content are correct.

Is this possible through a script?

Move all URLs in Text to Footnotes

$
0
0

Hi everyone

 

I have an interesting little issue. Basically, I have a text in which all URLs are displayed in the format <URL>www.example.org<URL> and I want to move those parts - preferrably without the <URL>-tags to footnotes. So I set out to do this and I got quite far. I can create empty footnotes for every occurrence of <URL>(.+?)</URL> but then when I want to move the text, I am stumped on how to define what text should be moved without losing the location of the footnote in relation to the text. So here's what I have:

 

function href() {

var curSel = app.selection[0];

// current selection is what the script is looking through

var searchTerm = "<URL>(.+?)<URL>";

// Search term as variable for ease of potential later use

app.findGrepPreferences = app.changeGrepPreferences = null;

// Reset search settings

app.findGrepPreferences.findWhat = searchTerm;

// Perform search for searchTerm

var result = curSel.findGrep( true );

app.findGrepPreferences = null;

for ( var f = 0; f < result.length; f++ ) {

  //f is defined as 0, but if there are more results than 0, increment f by the number of results

  var curRes = result[f];

  // Defines curRes as the number of results f --> Last occurrence of searchTerm in selection

  var curFootnote = curRes.footnotes.add();

  // Creates empty footnote for last instance of <URL>.+?<URL>

  moveURL.move(LocationOptions.AFTER, curFootnote.insertionPoints[-1]);

}

app.findGrepPreferences = null;

}

I apologize for the rather silly sounding commenting in it, but I try to make sure that everyone with a bit of JavaScript knowledge knows that I'm doing.

 

As you can see, var moveURL is undefined. var moveURL would be the function where I define the text that is to be moved. Now, it can't be curSel because that would try to move the entire text into the footnote, which is silly for obvious reasons. curFootnote is also not it, because that generates the footnote. So what am I doing wrong here?

 

Thanks for your help!

InDesign Check Spelling

$
0
0

Hi experts

 

Is that possible to collect typos in a list will then a new file?

My target is a one single file's spelling checking.

I need the script to collect those typos will then save the typos in a new file.

no matter java, or C++ to make a plugin.

If you are have a good idea, please help me to finish it.

I'll very happy to pay for this.

 

 

Thanks

Regard

John

Count Characters of Search Result

$
0
0

Hey everyone!

 

I am working on formatting code lines now. Bascially, they have line numbers and are handled using rule above/below to make the paragraphs look fancy. However, this requires me to make different paragraph styles for each line of code needed. However, I thought I'd automate this, because using a monospaced font, I can conclude that every line will never have more than 60 characters. In the raw text, a line that will have code formatting assigned will be prefixed with "bc. ". So the idea is simple.

 

  • Use RegEx ^bc\\. (.+?)$ to find code line
  • compare length of $1 or length of entire thing -4 with var lineLength which I set to 60.
  • Run search/replace to apply formatting and remove "bc. "

Here's what I have so far:

 

function codeLine() {
ar curSel = app.selection[0];
var searchTerm = "^bc\\. (.+?)$";
//search term for ease of later use
var lineLength = 60; //length of line in Code on page
app.findGrepPreferences = app.changeGrepPreferences = null;
// Reset search settings
app.findGrepPreferences.findWhat = searchTerm;
// Perform search for searchTerm
var result = curSel.findGrep( true );
app.findGrepPreferences = null;  for ( var f = 0; f < result.length; f++ ) {    //f is defined as 0, but if there are more results than 0, increment f by the number of results    var curRes = result[f];    // Defines curRes as the number of results f --> Last occurrence of searchTerm in selection    var curCode = searchTerm.length - 4;    if (curCode >= lineLength * 5) {          //Applies Pre formatting in the correct length          var applyFormat = "pre_5";          findSettings();          var myDocument = app.selection[0];          app.findGrepPreferences.findWhat = searchTerm;          app.changeGrepPreferences.changeTo = "$1"          app.changeGrepPreferences.appliedParagraphStyle = applyFormat;          resetFind(myDocument);        } else if (curCode >= lineLength * 4) {        //Applies Pre formatting in the correct length        var applyFormat = "pre_4";        findSettings();        var myDocument = app.selection[0];        app.findGrepPreferences.findWhat = searchTerm;        app.changeGrepPreferences.changeTo = "$1"        app.changeGrepPreferences.appliedParagraphStyle = applyFormat;        resetFind(myDocument);      } else if (curCode >= lineLength * 3) {        //Applies Pre formatting in the correct length        var applyFormat = "pre_3";        findSettings();        var myDocument = app.selection[0];        app.findGrepPreferences.findWhat = searchTerm;        app.changeGrepPreferences.changeTo = "$1"        app.changeGrepPreferences.appliedParagraphStyle = applyFormat;        resetFind(myDocument);      } else if (curCode >= lineLength * 2) {        //Applies Pre formatting in the correct length        var applyFormat = "pre_2";        findSettings();        var myDocument = app.selection[0];        app.findGrepPreferences.findWhat = searchTerm;        app.changeGrepPreferences.changeTo = "$1"        app.changeGrepPreferences.appliedParagraphStyle = applyFormat;        resetFind(myDocument);      } else {        //Applies Pre formatting in the correct length        var applyFormat = "pre_1";        findSettings();        var myDocument = app.selection[0];        app.findGrepPreferences.findWhat = searchTerm;        app.changeGrepPreferences.changeTo = "$1"        app.changeGrepPreferences.appliedParagraphStyle = applyFormat;        resetFind(myDocument);      }      }
}

 

Mind you, this code is as raw as it gets, is probably considered to be very ugly, and, most of all, it doesn't work. Basically, the only issue I have left is that when I go compare var curCode to var lineLength, curCode reverts back to searchTerm (minus four). It doesn't take the result, but the actual RegEx I've entered up there in line 03.

 

So my question is this: How do I get to count characters in the search result. I don't mind if I can count the length of $1 or the entire thing. So, please, help?

 

Thanks!


Runtime script

$
0
0

Hello Experts,

 

Below is the code, i am using to alert machine generated small cap found in document or not.

 

This will give alert only if i run the script. Is it possible to make a panel which run this script in backend and show the results via javascript? (like preflight panel)

 

I hope this can be done by plugin. But need to know is it possible to do the same in javascript.

 

var myDoc = app.activeDocument;
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
var myFinds = myDoc.findText();
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
if (myFinds.length == 0) {   alert("No Small Caps found");
}
else {  alert("Small Caps found"); 
}

 

 

Thanks in advance.

 

Karthi

Footnote junk character replace

$
0
0

Hi All,

 

In my document having the footnote contents. This contents already having the xml tag(<FEFF>).

But, these XML element is hide in the footnote contents.

I need, How to delete the xml tags(<FEFF>)?

 

The below figure shows the footnote contents. and also contains xml element tags.

Screen Shot 2015-11-19 at 7.46.13 PM.png

 

 

 

 

The below figure show the selected xml element content. They can't have xml structure.

Screen Shot 2015-11-19 at 7.58.23 PM.png

Please help me anyone, How to delete the selected contents in footnote contents?

 

Thanks by,

Peter.

Move unassigned story to an assignment (for InCopy)

$
0
0

I want to add a stroy to a new assignment with javascript.

I found out how to create an assignment, and how to make a icml and icma document

However it comes in unassigned incopy items, and I can't find a way to place it into my new assignment.

 

To create an assignment I use:
var myAssignment = myDoc.assignments.add(...);

 

And to create an icml file I use:
myStory.exportFile(ExportFormat.INCOPY_MARKUP, File(myFileIcml));

 

Both work, but now I need a way to place the icml into myAssignment. How can this be done?

 

Thanks!

How to replace the image in the scriptUI?

$
0
0

 

 

#targetengine miscellaneous;

main();
function main()
{
    var w = new Window ("palette", "test");       var panel = w.add("panel");    panel.graphics.backgroundColor = panel.graphics.newBrush (panel.graphics.BrushType.SOLID_COLOR, [0.9, 0.9, 0.9]);    var photo = panel.add ("image", undefined, File ("C:/Users/user1/Desktop/empty.png"));    photo.size = [200,300];          var bt1 = w.add ("button", undefined, "image1");    var bt2 = w.add ("button", undefined, "image2");       bt1.onClick = function(){               // Draw a image1 in the panel.    }    bt2.onClick = function(){               // Draw a image2 in the panel.    }
w.show ();
 }

 

 

Hi.

 

I want to replace the image in the panel, when I press the button.

 

Please tell me the source to be input to onClick function.

 

Thanks.

apple script help needed

$
0
0

In InDesign cc I have the "copy all link information" mapped to the keyboard shortcut shift+option+L. With a image selected, when the script is triggered it displays a dialogue box asking what needs to be done sets that to a variable, then runs the keystroke shift+option+L to copy the link info. Next it creates a text file on the desktop if its not there and appends it with the display box variable and pastes the link information. The problem is that it doesn't copy the link information correctly. Its as if its delayed. For example. If I copy something to the clipboard like the word "capture" and then select the image and run the script it will paste the word "capture" instead of the link information. But if I run it again on a different image it will paste the link information from the first time I ran the script. Its like its delayed by 1. Anyhow if anyone has any idea how to fix this strange behavior I would be grateful. Perhaps it would work with javascript, Im not sure.

 

Thanks,

~David

 

--dialog box

 

display dialog "What do you need done" default answer "Remove Background"

settheAnswerto (text returnedofresult)

 

activateapplication "Adobe InDesign CC 2015"

 

tellapplication "System Events" tokeystroke "L" using {shift down, option down}

end

 

setthis_storyto "

 

------------------- " & theAnswer& " -------------------

 

"

setthis_fileto (((path todesktop folder) asstring) & "ArtCorrections.txt")

mywrite_to_file(this_story, this_file, false)

 

 

onwrite_to_file(this_data, target_file, append_data)

  try

  setthetarget_filetothetarget_fileasstring

  settheopen_target_filetoopen for accessfiletarget_filewithwrite permission

  ifappend_dataistruethenset eofoftheopen_target_fileto 0

  writethis_datatotheopen_target_filestarting ateof

  close accesstheopen_target_file

  returntrue

  onerror

  try

  close accessfiletarget_file

  endtry

  returnfalse

  endtry

endwrite_to_file

 

 

setmyVartothe clipboard

mywrite_to_file(myVar, this_file, false)

 

onwrite_clip_file(myVar, target_file, append_data)

  try

  setthetarget_filetothetarget_fileasstring

  settheopen_target_filetoopen for accessfiletarget_filewithwrite permission

  ifappend_dataistruethenset eofoftheopen_target_fileto 0

  writemyVartotheopen_target_filestarting ateof

  close accesstheopen_target_file

  returntrue

  onerror

  try

  close accessfiletarget_file

  endtry

  returnfalse

  endtry

endwrite_clip_file

Check my GREP?

$
0
0

First, let me say I'm not really a code talker -- I poured in an Excel document for a directory. It's mostly single lines of names with multiple line text for the school names.

So I want to look for a line with two, sometimes three words followed by "elementary or junior or sr or high", and apply a "header" to these. Here's what I cobbled together:

^\w+?( \w+?)? (?i)(elementary|junior|sr|high)

It works. It does what I want, but am wondering if it's "correct" or "efficient".

 

Anyone?

ID CC 2014 plus ExtendScript (Yosemite) slow to the point of not working...

$
0
0

Hi all

Since upgrading to Yosemite ExtendScript is sooooo slow.

I literally watch the editor trying to keep up with me typing.

Anybody else having this issue?

Regards

Romano


Tool tip property extendTool Script

$
0
0

How to enable the tools tip property in extend tool kit.

add parent tag particular range of xml elements

$
0
0

I my in design file having more than start and end tags.

 

I need to add parent tag for all start and end element is this script able

 

<Start>

<para>

<para>

<End>

 

I need to add root tag <sec> like this

<sec>

<Start>

<para>

<para>

<End>

<sec>

How to deselect frame?

$
0
0

Hi.

 

If the frame is selected, I would like to deselect frame.

 

Please tell me JS code.

 

Thanks.

How to save and overwrite the file

$
0
0

Hi experts

 

I got this script:

 

//======================================================================================== =========

var MyFolderWithFiles = Folder.selectDialog ("Choose a folder");
var myFiles = MyFolderWithFiles.getFiles("*.indd");
for(i = 0; i < myFiles.length; i++) {
theFile = myFiles[i];
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
var targetDoc = app.open(theFile, true);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
targetDoc.close(SaveOptions.YES.WITH_OVERWRITE);
}

//======================================================================================== =========

 

aim to save and overwrite the files.

 

but error, could someone help me to fix it.

 

Thanks

 

Regard

John

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

$
0
0

var XMLFile = File.openDialog ('Select XML Files...');

var doc = app.activeDocument;

        if(!app.documents.length)

        {   alert("ERROR: Document not Opened");

             return;

        }

        //doc.importXML(XMLFile);

      

        var firstFigureNode = doc.xmlElements[0].xmlElements[1].xmlElements[0];

        var lableNode = firstFigureNode.xmlElements[0];

        var lableNodeText = lableNode.contents;

      

        var myFrame = doc.textFrames.add ({geometricBounds:[3, -13, 13, -3]});

        lableNodeText.move(LocationOptions.AFTER, myFrame.texts[0]);

 

========================================================

My Requirement is::==>> Move the Contents of an xml element into text frame by inDesign Script, But  XML Structure of InDesign File should not be change & Data in XML Structure should remain as was before.....

 

I have tried above code but it's not working.........

Please anyone can help me, By solving this problem.....

Viewing all 8771 articles
Browse latest View live


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