Forum Replies Created
-
AuthorPosts
-
Brian Pifer
ParticipantIf you’re sure you are passing a Document reference to myFindGlyph(doc) in main, only other thing I can think of is to ensure the find font is installed and you have the right glyph ID.
Brian Pifer
ParticipantWhere do you call the function in your main code? Are you sure you are passing a Document reference to it?
Also are you sure that is the correct font in the findWhat? One has XE in the font name, while the change font name does not.
Brian Pifer
ParticipantIn your function definition, you are passing an argument called myobject, but you are referencing myDocument in the function, which is not declared in scope, so it is undefined.
Brian Pifer
ParticipantAre you just changing one or two existing Paragraph Styles with this new hyphenation? If so, probably just easier to set up corresponding Paragraph Styles with the right hyphenation settings and doing a Find/Replace. Also, what is that dropdown at the end of your image? I don’t see it in my Hyphenation settings. Maybe a plugin? Not sure that would be scriptable, unless I’m missing something.
February 4, 2020 at 3:14 pm in reply to: GREP > finding roman brackets next to italic character or numeral #14323143Brian Pifer
ParticipantDisclaimer: GREP is not my strong suit, but I think this can be accomplished via script. The following will find all bracketed content, and compare the brackets to the first and last characters within the brackets to compare their applied fonts. Not sure if my app.findGrepPreferences.findWhat line will match exactly all the time — if you already have a good GREP you’re using, feel free to sub it in (add an additional escape backslash for the script purposes. I haven’t fully tested, but you can give it a shot.
var doc = app.activeDocument;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = “[(w*| *){1,}]”;
var finds = doc.findGrep();for (var i = 0; i < finds.length; i++) {
var firstBrack = finds[i].characters[0];
var lastBrack = finds[i].characters[-1];
var firstChar = finds[i].characters[1];
var lastChar = finds[i].characters[-2];
if (firstChar.appliedFont.fullName.toLowerCase().indexOf(“italic”) >= 0 && lastChar.appliedFont.fullName.toLowerCase().indexOf(“italic”) >= 0)
{
firstBrack.appliedFont = firstChar.appliedFont;
lastBrack.appliedFont = firstChar.appliedFont;
}
else if (firstChar.appliedFont.fullName.toLowerCase().indexOf(“italic”) == -1 && lastChar.appliedFont.fullName.toLowerCase().indexOf(“italic”) == -1) {
firstBrack.appliedFont = firstChar.appliedFont;
lastBrack.appliedFont = firstChar.appliedFont;
}
}app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;January 21, 2020 at 12:30 pm in reply to: Resizing all my frames at once by a certain amount #14323248Brian Pifer
ParticipantHi Mark,
You can try this script: https://raw.githubusercontent.com/jpobojewski/InDesign-Toolbox/master/Resize%20Selected%20Items.jsx
You can also select all the objects you want, and set the anchor point to the top center or left center point (the grid in properties), then type -.25 in the W (width) property.
If you want to roll your own, here’s how to get started:
This line of code will get you the current selection as an “array”, meaning you can select multiple text frames and iterate through them.
var selections = app.selection;
The iteration looks like this:
for (var i = 0; i < selections.length; i++) {
}
Inside the bracket, you’ll want to get the frame’s coordinates and use either resize or reframe. This part is a bit complicated, but essentially you are using the “resolve” method of a frame to get its current coordinates, then performing math on those coordinates and using resize or reframe using points (9 points = .125 in).
var frame = selections[i];
var topleft = frame.resolve(AnchorPoint.TOP_LEFT_ANCHOR, CoordinateSpaces.INNER_COORDINATES, true)[0];
var bottomright = frame.resolve(AnchorPoint.BOTTOM_RIGHT_ANCHOR, CoordinateSpaces.INNER_COORDINATES, true)[0];
var x1 = topleft[0] + 9;
var y1 = topleft[1];
var x2 = bottomright[0] – 9;
var y2 = bottomright[1];
frame.reframe(CoordinateSpaces.INNER_COORDINATES, [[x1, y1], [x2, y2]], true);In that math, you are moving the x1 coordinate inward by 9 points (.125 in) and shrinking the x2 coordinate by .125. If you to change the height, you’d do the same operations on the y coordinates.
The full code put together:
var selections = app.selection;
for (var i = 0; i < selections.length; i++) {
var frame = selections[i];
var topleft = frame.resolve(AnchorPoint.TOP_LEFT_ANCHOR, CoordinateSpaces.INNER_COORDINATES)[0];
var bottomright = frame.resolve(AnchorPoint.BOTTOM_RIGHT_ANCHOR, CoordinateSpaces.INNER_COORDINATES)[0];
var x1 = topleft[0] + 9;
var y1 = topleft[1];
var x2 = bottomright[0] – 9;
var y2 = bottomright[1];
frame.reframe(CoordinateSpaces.INNER_COORDINATES, [[x1, y1], [x2, y2]]);
}This also assumes you don’t need to resize the containing images after the resize. There’s lots of things that go into writing a script to do what you want to do, but hope this gives you a good starting point for understanding.
Brian Pifer
ParticipantSo weird that you have to select a cell in rows.itemByRange, but there you have it. Michel also PM’d me with a similar solution. Thanks, Peter!
Brian Pifer
ParticipantResurrecting this thread, as I’m struggling to get certain rows selected in a table.
I want to select all rows after a certain point in the table using itemByRange. I’m trying the following.
var rowsToMove = table.rows.itemByRange(i, rowCount-1).getElements();
app.select(rowsToMove, SelectionOptions.REPLACE_WITH);I get the following error on the app.select line: Error Code# 30477: Invalid value for parameter ‘selectableItems’ of method ‘select’. Expected Object, Array of Objects, NothingEnum enumerator or SelectAll enumerator, but received (Row, Row, Row, Row, Row, Row)
I’ve tried setting app.selection[0] = rowsToMove; I’ve tried rowsToMove without the getElements(). Mind-boggling.
Any thoughts? Thanks.
Brian Pifer
ParticipantBe sure you copied what I have above into a plain text editor such as Notepad, then save as a .jsx, not a word processing application like Word.
Brian Pifer
ParticipantSure. With the text in question selected:
var chars = app.selection[0].characters;
var fonts = [“Font1”, “Font2”, “Font3”, “Font4”];
for (var i = 0; i < chars.length; i++) {
var rando = Math.floor(Math.random() * Math.floor(4));
chars[i].appliedFont = fonts[rando];
}Brian Pifer
ParticipantAgree it’s probably easier to use to preflight as you can navigate to the textframe in question through the panel, but here you go.
var tfs = app.documents[0].textFrames;
var oversetPageNums = [];for (var i = 0; i < tfs.length; i++) {
if (tfs[i].overflows) {
oversetPageNums.push(tfs[i].parentPage.name);
}
}alert(oversetPageNums);
December 15, 2019 at 8:57 am in reply to: Paragraph with 3 lines or less indented till after first word #14323448Brian Pifer
ParticipantThis is a pretty niche thing, so don’t think a script exists for it. You could create a paragraph style that does what you want, then cycle through the paragraphs, see if they have 3 or fewer lines, and apply the paragraph style to those lines?
Brian Pifer
ParticipantThis will hit the insertion point at the start of every paragraph on the first page of a document.
var pagePars = app.document[0].pages[0].textFrames.everyItem().paragraphs.everyItem().getElements();
for (var i = 0; i < pagePars.length;i++) {
var ip = pagePars[i].insertionPoints[0];
//do something at each insertionPoint
}There are other ways to get to whichever paragraphs you need. For instance, if you had a textFrame selected with the black arrow tool, you could get the textFrame’s parent story paragraphs with this:
var psPars = app.selection[0].parent.paragraphs;
for (var i = 0; i < psPars.length; i++) {
var ip = psPars[i].insertionPoints[0];
//do something at each insertionPoint}
Brian Pifer
ParticipantAre you using string.replace? Have you tried changing one graf with GREP. If that works, you could set a GREP replace script instead of string.replace, replacing with that arrow character with the character that copies over and maybe setting that character with a style that you can apply on the GREP replace?
Brian Pifer
ParticipantRelatedly, I just discovered that each file above is a multipage PDF. So, essentially, I am attempting to automate the placement of multiple multipage pdfs. I figure I can handle each page using PDFPlacePreference.pageNumber, but I need to know the total number of pages in each multipage PDF before doing that. I can’t seem to find where this info would be exposed though. Does anyone have any thoughts?
-
AuthorPosts
