Peter Kahrel
Community Expert
Peter Kahrel
Community Expert
Activity
‎Apr 02, 2008
09:02 AM
I'm not particularly good at this sort of thing, but the reference says that xmlImportMaps.add() takes two parameters, a markup tag and the mapped style. Take a look at p. 114 of this document:
http://www.adobe.com/products/incopy/scripting/pdfs/InCopy_CS3_Scripting_Guide_JS.pdf
which is for CS3, but what you want to do has not changed much I don't think.
Peter
... View more
‎Apr 02, 2008
06:44 AM
This and many other things are described in some of Adobe's documentation at http://www.adobe.com/products/indesign/scripting/index.html
Peter
... View more
‎Apr 02, 2008
01:00 AM
Ah, that's what's wrong with it. Back to Jongware.
Peter
... View more
‎Mar 31, 2008
11:48 AM
Ugh. "minwidth" should indeed be "minWidth": I consult3ed some code I have and the values I used with "minwidth" happened to be the default, so I never realised that JS ignored the values I gave it. It has been less than helpful in not producing an error. And Dave is right: minWidth works only as a specified value in textEditboxes.
Peter
... View more
‎Mar 31, 2008
09:32 AM
Hi Harper Marie,
Excellent effort! The problem with the front matter can be avoided by using not the document offset of the insertionpoint's parent page, but instead the name of the page:
page_name = myInsertionPoint.parentTextFrames[0].parent.name;
A document with front matter and body will have more than one section: front matter in the first section, body in the second one. Using a page's name always gives you the correct page number. (It could be the case that the section prefix is added, but that doesn't happen over here. I forget when exactly that occurs.)
As to sorting, you can do that with JavaScript. You need to convert the text of the index into an array of strings, sort it, then put the array back into InDesign as a string. Use the text function myString.split("\r") to convert a string into an array, splitting the string on a return; myArray.sort() sorts the array, and myArray.join("\r") converts the array into a string, using \r as separator. Since JavaScript's sort defaults to alphanumerical sorting, you need to supply a separate function for numerical sorting.
To sort your index, insert these three lines at the end of the main part of your script (i.e. before the closing brace of the if (doc.indexes.length > 0) statement):
s = IndexByPage.parentStory.contents.split("\r");
s = s.sort (sortnum);
IndexByPage.contents.contents = s.join("\r");
And this function at the end of the script:
function sortnum (a,b)
{
return a - b
}
Another change is needed to prevent the heading "IndexByPage" from appearing at the bottom of the index.
Peter
(Glad that that paper was of any use)
... View more
‎Mar 31, 2008
06:19 AM
Daniel,
Try minwidth (all lower case).
Peter
... View more
‎Mar 31, 2008
06:12 AM
What's wrong with
find: 0+$
replace with: "" (i.e. nothing)
Peter
... View more
‎Mar 22, 2008
02:40 PM
There's a list for CS2 here: http://www.kahrel.plus.com/indesign/id4-dict.html. It highlights the new script commands for CS2 (InDesign 4), so if you ignore those you get the list for CS (InDesign 3). If you're on Windows, you could also use Teus de Jong's object browser (http://www.teusdejong.nl/, pick "InDesign utilities").
Peter
... View more
‎Mar 20, 2008
06:03 AM
Martin,
You can cycle through Unicode ranges using their hexadecimal numbers:
for (i = 0x0100; i < 0x017F; i++)
$.writeln (String.fromCharCode(i));
writes the characters in Latin Extended A to ESTK's console.
Peter
... View more
‎Mar 20, 2008
12:49 AM
>How can I save the script(included a png) as jsxbin?
File > Export as binary.
Peter
... View more
‎Mar 19, 2008
02:58 PM
Harper Marie,
You need to go through several steps. The first is to change
(1)
Animals
Cat 2, 4
Dog 1, 2, 5
into
(2)
Animals Cat 2, 4
Animals Dog 1, 2, 5
This you want to turn into
(3)
Animals Cat 2
4
Animals Dog 1
2
5
The next step is this:
(4)
Animals Cat 2
Animals Cat 4
Animals Dog 1
Animals Dog 2
Animals Dog 5
Finally, you apply Fred's step, so to speak, to move the page numbers to the beginning in each line and sort the text.
You can do all this in JavaScript, you don't need external disk files. It's probably easiest to work on an array to get from the first to the second stage and from the third to the fourth. The second to the third stage is probably best done on a string. You can manipulate this string using JavaScript's various text functions, including the sort.
In Indesign/JavaScript, to get the contents of a document, place the cursor somewhere in the text and do this:
myString = app.selection[0].parentStory.contents;
which returns the document as a string. To get the contents as an array, do this:
myArray = app.selection[0].parentStory.contents.split('\r');
The string is split on \r, the return character, so in this case you get an array of lines (paragraphs, really). To turn an array into a string, use
myString = myArray.join('\r');
This string can be used to replace the old index with the new one: the last line in your script could be:
app.selection[0].parentStory.contents = myString;
Hope this helps.
Peter
... View more
‎Mar 19, 2008
12:16 PM
We'll see what she says.
... View more
‎Mar 19, 2008
12:06 PM
What Harper Marie probably wants is to turn this sequence:
cat 2, 4
dog 1, 3, 5
into this:
dog 1
cat 2
dog 3
cat 4
dog 5
Peter
... View more
‎Mar 19, 2008
11:51 AM
>those pop-ups are a bit annoying aren't they.
Understatement of the year.
Peter
... View more
‎Mar 19, 2008
11:49 AM
Fred,
Your script moves one page number to the beginning of the paragraph. What about the others?
Peter
... View more
‎Mar 19, 2008
08:14 AM
Ah -- Bob, you think Goldbridge wants to store the PNGs in the jsx file? In that case, why not save the script as jsxbin?
Peter
... View more
‎Mar 19, 2008
12:38 AM
Did this not work: http://www.adobeforums.com/webx/.3bbf275d.3c065b3a/3 ?
Peter
... View more
‎Mar 17, 2008
02:26 PM
I've no idea.
Peter
... View more
‎Mar 17, 2008
08:29 AM
Ah, yes, that should be 0.
... View more
‎Mar 17, 2008
07:46 AM
You get two errors: one for the use of "vat" instead of "var", and when you fix that, you get an error because you need to remove the notes starting at the end of the document. Use
>for(var fn = ftcnt-1; fn >= 0; fn--)
Peter
... View more
‎Mar 17, 2008
06:20 AM
>how can i do that using ur code"
Nice one, jong.
... View more
‎Mar 16, 2008
11:51 PM
app.open (File ('/d/test.indd'));
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.findWhat = 'Brett';
app.changeTextPreferences.changeTo = 'Peter';
app.activeDocument.changeText();
app.activeDocument.save();
app.activeDocument.close();
Then there are several options (for case-sensitivity, whole-word only, etc.) -- see the documentation.
Peter
... View more
‎Mar 16, 2008
11:16 PM
Which InDesign version?
Peter
... View more
‎Mar 14, 2008
09:27 AM
2 Upvotes
Try this:
if(myDoc.characterStyles.item ("cstyle") == null)
myDoc.characterStyles.add({name:"cstyle"});
var myCharStyle = myDoc.characterStyles.item ("cstyle");
"cstyle" is the name you see in the char. style panel, myCharStyle is a variable -- these are not the same thing.
Peter
... View more
‎Mar 13, 2008
06:00 AM
Andreas,
move() takes either (a layer, page or spread) or an array of values as parameter. To move a frame to the next page, you need something like this:
current_page = newFrame.parent.documentOffset;
newFrame.move (app.activeDocument.pages[current_page+1]);
Peter
... View more
‎Mar 12, 2008
06:11 PM
I use a message window (a palette) to display what a script is up to when it is running. A script that processes a bunch of files could display each file name in succession:
// create a message window
mess = create_mess (30, 'Example');
docs = // get a bunch of documents
for (i = 0; i < docs.length; i++)
{
app.open (docs);
// show the current file's name in the message window
mess.text = app.activeDocument.name;
...
...
app.activeDocument.close()
}
function create_mess (le, title)
{
dlg = new Window('palette', title);
dlg.alignChildren = ['left', 'top'];
var txt = dlg.add('statictext', undefined, '');
txt.characters = le;
dlg.show();
return txt
}
... View more
‎Mar 12, 2008
03:13 PM
>How about toggling their visible property?
Right -- hadn't thought about that. Bit of a rash overgeneralisation that the UI isn't available to scripts, which obviously is nonsense given that you can add and remove menu items and toggle panels.
Peter
... View more
‎Mar 12, 2008
08:19 AM
Sandee,
Scripts can't open and close panels in the UI. But you can use the Esc key to close the Tab panel.
Peter
... View more
‎Mar 12, 2008
04:10 AM
>While I have you on the hook I'm going to lazy again
Wriggling on that hook, in terrible pain, all I can think of is to say, Check the properties of "Link". I know there's a property that gives you the file path, just can't remember what its name is.
Peter
... View more
‎Mar 12, 2008
03:46 AM
>Hmm, I ask because Graphics(1).ActualPpi and .EffectivePpi DO work, at least in CS3 for Windows.
I thought I had tried that, but maybe it wasn't an EPS. So when you do Graphics(1).ActualPpi and the graphics is an EPS, it will work.
>How about the color space? The InD info panel shows colorspace for Photoshop EPS files. Any idea if THAT is available in the scripting.
Check the library, should be in there.
Peter
... View more