Peter Kahrel
Community Expert
Peter Kahrel
Community Expert
Activity
‎Jun 04, 2008
02:24 AM
Get the contents of the whole folder in an array, then you can check each item to see if it matches some criterium. In Javascript (VB should be similar):
function find_file (dir, mask)
{
var f = Folder (dir).getFiles ('*.*');
for (var i = 0; i < f.length; i++)
if ( // compare f.name and mask here
return f;
}
This returns the first file in "dir" that matches "mask".
Peter
... View more
‎Jun 04, 2008
02:17 AM
>Is there a problem in CS3 when using GeometricBounds for frames in frames?
Generally not. And the JS equivalent of your code works fine. Maybe it's a VB thing.
Peter
... View more
‎Jun 02, 2008
11:56 PM
The three methods you describe all do the job. This one:
>var myTitle = mp.textFrames.add(myDocument.layers.item("Slug"), {geometricBounds:[myPa..........
allegedly is the quickest: you create an object with all the specified properties in place (there's no need to use "undefined" as a place filler, by the way). The two other methods are equivalent. I guess the choice for one or the other is partly a matter of taste. Some people avoid "with" statements as they can cause problems (apparently with referencing but I don't know the details). They are a bit slower than the first method, but realistically, the difference will show only when you create a coupke of hundred frames. You won't see any difference when you place a handful of frames.
Peter
... View more
‎Jun 02, 2008
08:20 AM
You'll need<br />><myB>.+?<myB><br /><br />Without that question mark the expression matches everything between the first and the last <myB> in the document (or strory maybe), including any <myB> that intervene. If there's a chance that the <myB> codes span a return, enable single-line processing, as the dot doesn't match returns:<br /><br />(?s)<myB>.+?<myB><br /><br />Peter
... View more
‎Jun 02, 2008
12:25 AM
>Would it be possible to add a text frame to all the master templates?
You'd have to cycle through the pages on the master spreads:
mp = app.activeDocument.masterSpreads.everyItem().pages.everyItem().getElements();
for (i = 0; i < mp.length; i++)
//add textframe to mp
Peteer
... View more
‎Jun 01, 2008
09:40 PM
John,
Maybe this code answers your last two posts (in #9 and #10):
newDocSection = myDocument.pages[0].appliedSection;
if (newDocSection.marker != "slug")
var newDocSection = myDocument.sections.add(myDocument.pages[0]);
newDocSection.continueNumbering = false;
newDocSection.pageNumberStart = parseInt(myPageNo);
It is a replacement for your code in #10, and I think it answers your question in #11: by assigning an applied section to a variable, you can check its marker name. If it doesn't exist, create a new section marker; if it does exist, just change it. (The name "newDocSection" is now a bit confusing, but I didn't want to change it.)
>the Start Section is ticked and grayed out.
This is the case in one-page documents. Seems reasonable: when you create a new document a section is created as well (because each document must have at least one section), and while the document has just one page, you can't add a section (because it already has one). When you add a page, the "Start Section" is no longer grayed out.
>I'm also finding that in the numbering option under Section Prefix Sec1:is being added for some reason. Is this default of the sections.add()?
It is. But you can disable that in the Pages panel.
Peter
... View more
‎May 31, 2008
09:46 AM
First you need a handle on a cell. Once you have that cell, set the height of its parent row and the width of its parent column.
Peter
c = get_cell();
c.parentRow.height = "24pt";
c.parentColumn.width = "24pt";
// return a cell if you can
function get_cell()
{
if (app.selection.length > 0)
{
if (app.selection[0].parent instanceof Cell)
return app.selection[0].parent;
else if (app.selection[0] instanceof Cell )
return app.selection[0];
}
}
... View more
‎May 30, 2008
04:27 AM
Ah -- yes. I was using the wrong options: what I needed was not baselineFrameGridOptions but GridPreferences (to set the document's grid increment). Time for a break!
Thanks,
Peter
... View more
‎May 30, 2008
04:15 AM
You could store it in the document's label. But the person on the receiving end would then have to know how to get that script out of the label and installed as a script. [Maybe there is a script to extract a script from a label and run it?]
Peter
... View more
‎May 30, 2008
04:10 AM
I'm trying to set a document's baseline framegrid options but can't get this to work:
>app.activeDocument.baselineFrameGridOptions.baselineFrameGridIncrement = '13.2 pt';
When I look in the preferences under Grids, it shows the value that it had before I ran the above one-liner (12), so it looks as if nothing has happened. But when I then run this line:
>app.activeDocument.baselineFrameGridOptions.baselineFrameGridIncrement
ESTK says 13.2. So ESTK says 13.2, the interface, 12. I don't understand this. Am I looking in the wrong place?
Peter
... View more
‎May 27, 2008
10:53 AM
I too have some intuitive reservation against try/catch, which I feel boils down to closing your eyes and hoping for the best. Somehow it seems better first to try whether it's safe to do something -- look before you leap, as it were. Still, try/catch is useful and I use it a lot, especially when it's not evident which exceptions to test for.
As to "how do you know if you have more than 1 returned?", maybe you could use this:
>if (myDoc.textFrames.item("MyLabel").getElements().length > 0)
to see if there are more than one textframes labelled "MyLabel".
Peter
... View more
‎May 26, 2008
06:17 AM
This finds everything between [ and ]:
>myString.match (/\[[^\]]+\]/g)
Peter
... View more
‎May 26, 2008
03:58 AM
You can say
>app.activeDocument.textFrames.item ("JSLabel").contents = "..."
Peter
... View more
‎May 22, 2008
10:45 PM
For
>pageNumberStart = myPageNo
use
>pageNumberStart = Number (myPageNo)
Peter
... View more
‎May 21, 2008
08:02 PM
A much longed-for feature ...
Peter
... View more
‎May 21, 2008
06:21 AM
Tim,
I'm afraid I don't know anything about clipping paths. Maybe someone else has an idea.
Peter
... View more
‎May 21, 2008
04:56 AM
>I've tried using try/catch without any luck.
Make sure that in the ESTK "Don't break on guarded exceptions" (in the Debug menu) is checked. (Though this is probably relevant only when you run scripts from the ESTK.)
To check if an object has a property, try this:
>myGraphic.hasOwnProperty ('clippingPath')
Peter
... View more
‎May 21, 2008
12:55 AM
PÃ¥l,
I use the function listed below to incorporate the text in inlines into the main text. It moves text rather than copying&pasting, so the problem you encountered shouldn't occur. It handles multiply embedded inlines. It shouldn't be too hard to convert it to VB.
Peter
function inlines (doc)
{
var st = doc.stories;
for (var i = doc.stories.length-1; i > -1; i--)
while (st.textFrames.length > 0 )
{
var ix = st.textFrames[-1].parent.index;
st.textFrames[-1].texts[0].move (LocationOptions.after,
st.insertionPoints[ix]);
st.textFrames[-1].locked = false;
st.textFrames[-1].remove();
}
}
... View more
‎May 20, 2008
07:29 AM
This is a bit messy and, I think, buggy. I recently ran into the problem that in some cases, you have to use the English term in localised apps (I checked English Intn'l, French, and German installations), and in other cases you need the localised term. For example, in the French ID you need to specify Black as "Black" (not "Noir", as the interface would suggest). On the other hand, the French version doesn't like "Dashed" as a line style, you need "Tirets". The German version has the same asymmetry.
One approach is always to use a try/catch statement, trying the localised version and if that fails, doing the English version, but that's not exactly what you want. The trouble is that to find this out systematically, you need to bother people with different installations to try and find out what works and what doesn't.
Apart from Dave's reference, you can also check "JavaScript Tools Guide CS3" (in ESTK, Help > SDK), from pp. 92 and 206.
Peter
... View more
‎May 20, 2008
02:09 AM
That sounds very useful -- thanks.
Peter
... View more
‎May 19, 2008
11:30 AM
Fair enough -- thanks.
Peter
... View more
‎May 19, 2008
11:09 AM
>A guide does not have a name property
But it does have a label, and it's sort of usable. It still doesn't make any sense to me why certain object can be addressed using their label, and others not.
Peter
... View more
‎May 19, 2008
04:34 AM
Well, ok, if it's intended behaviour it's not a bug (just a nuisance). I can't see the rationale, though. It would be very useful if you could refer to guides (and stories, tables, and what not) using their label.
Peter
... View more
‎May 19, 2008
01:54 AM
The 'opeless-type apostrophes can be found using this grep: ~]\< (closing quote followed by beginning of word), and word-internal apostrophes (l'ennui, couldn't) are also found. The remaining problem is word-final apostrophes (friggin'); I don't think it's possible to distinguish these from closing quotes.
Peter
... View more
‎May 18, 2008
03:44 PM
Daniel,
>.guides[0] won't work for me since . . .
Sorry -- I wasn't very clear on that. All I meant was that there are several ways in which you could get a handle on a guide, but not through its label.
> Why was this bug not fixed?
I don't know when this bug was first reported, but I reported it just a couple of weeks ago. We'll have to wait and see what happens.
>. . . then the script I want to create is impossible?
That's what I thought until a few minutes ago, and in fact I recently ditched an approach because of this bug, but, of course, Dave's remark ("but you can cycle through all guides and look for the one with the label you want.") provides the solution:
g = app.activeDocument.guides;
for (i = 0; i < g.length; i++)
if (g.label == 'myGuide')
g.location = 2;
Peter
... View more
‎May 18, 2008
12:18 AM
This is a bug. You can't address guides through their label. app.selection[0] (when a guide is selected) and app.activeDocument.guides[0] work ok, but app.activeDocument.guides.item('xxx') doesn't work.
Peter
... View more
‎May 18, 2008
12:04 AM
‎May 16, 2008
12:28 AM
>Another case is the substitution of a character at the end of a word: Freud instead of Freude.
Ah -- yes, in English you have those, too, such as grabbin'. And at the beginning of words, like 'phone and 'ere. And in contractions, like they're and can't. It's a 'opeless freekin' mess.
Peter
... View more
‎May 16, 2008
12:06 AM
Martin,
You're quite right, that script works well only when the quotes are balanced. I put it like that as a working alternative to elic elico's approach.
>You first have to make all non-typographical quotes to one specific typographical quote (right or wrong) or a placeholder. And than you have to change the specific typographical quotes to the non-typographical quotes (sic!).
Aha! I didn't know that. Very useful, thanks. Makes life a lot easier. In your grep replacements you could use the quote wildcards, could you not? In grep, " finds any double quote, ' any single quote. So could you not say theChangeGrep ( '"', '\\x{2018}' ); with the same result?
As to apostrophes, maybe you could define them as "single quotes preceded and followed by a letter", which in greppian would be >[\u\l]'[\u\l]
This doesn't catch certain apostrophes in English, such as possessive plurals ("the programmers' plight"). For French and German it might wotk, though.
Peter
... View more
‎May 15, 2008
11:40 PM
Dave,
>I wonder if ESTK itself can be scripted to do this -- probably.
Strangely, it looks as if you can't. In ESTK 1 you could do this:
#target estoolkit-1.0
documents[0].text
To show in the console the contents of whatever documents[0] contains, or documents[0].selectedText to show whatever is selected in documents[0]. Other properties can be seen in the databrowser, or displayed using document.reflect.properties
But in ESTK2 all this appears not to work. The databrowser doesn't reveal anything. When you select ESTK and do app.name it duly says "ExtendScript Toolkit", and app.reflect.properties tells you just "name, version, activeScript, reflect". Not a lot to go by.
By the way, here's an alternative to your initialCap():
function toJS (s)
{
return s.toLowerCase().replace (/_(.)/g,
function() {return arguments[1].toUpperCase()})
}
Peter
... View more