Forum Replies Created
-
AuthorPosts
-
Peter KahrelMemberHere you go:
try { app.documents[0].layers.item('Layer 1').name = 'art'; app.documents[0].layers.add ({name: 'die line', layerColor: UIColors.RED}).move(LocationOptions.AT_BEGINNING); app.documents[0].pages[0].rectangles.add ( app.documents[0].layers.item('die line'), { name: 'die line', // More bonus points! (The box is easy to identify in the layers panel) geometricBounds: app.documents[0].pages[0].bounds, strokeWeight: '1 pt', fillColor: 'die line' } ); } catch (e) { alert (e); }Now, what would all those bonus points give me. . .
Peter
Peter KahrelMemberDavid: you can swap the contents of two (consecutive) paragraphs, but not the paragraph objects. So you risk losing all formatting. And you need to reapply the paragraph styles.
Kathy: You can use this script to swap Red and Blue. Works only to swap Red/Blue, Red/Blue, etc. To change Blue/Red, Blue/Red, exchange ‘Red’ and ‘Blue’ in the script:
(function () { var i; var red; var next; app.findGrepPreferences = null; app.findGrepPreferences.appliedParagraphStyle = 'Red'; red = app.documents[0].findGrep(); for (i = red.length-1; i >= 0; i--) { next = red[i].insertionPoints[-1].paragraphs[0]; if (next.characters[-1].contents !== '\r') { next.insertionPoints[-1].contents = '\r'; } if (next.appliedParagraphStyle.name == 'Blue') { red[i].move (LocationOptions.AFTER, next.insertionPoints[-1]); } } }());Peter
Peter KahrelMemberYes, it does:
Find what: (.)
Change to: $1This would replace any character (except the paragraph return) with itself. The parentheses create a referent, which is referenced by $1. You can do 10 references:
Find what: (.)(.)
Change to: $1$2etc.
Peter KahrelMemberYou may not have properly emptied the Find what and Change to fields.
You don’t need Grep, you can do this in both the Text and the Grep panels:1. Make sure that the Find what and Change to fields are empty.
2. In the Find format panel, enter -0.75 points
3. In the Change format panel, enter 0 points. This will be displayed as ‘+not shifted’ in the panel.
4. Do the replacement.Works for me.
Peter
Peter KahrelMemberYou can do that with Find/Change. In the Text tab,
Find what: your search string
Change to: ^c (formatted) or ^C (unformatted)(Use ~c or ~C in the Grep tab)
Peter
Peter KahrelMemberEmiel,
If your dummy footnotes are formatted [[Abc]] and a footnote should be created with content Abc to replace [[Abc]], then you’d need something like this script:
(function () { var i; var placeholders; var fnote; app.findGrepPreferences = null; app.findGrepPreferences.findWhat = '[[(.+?)]]'; placeholders = app.documents[0].findGrep(); for (i = placeholders.length-1; i >= 0; i--) { fnote = placeholders[i].insertionPoints[0].footnotes.add(); placeholders[i].move (LocationOptions.AFTER, fnote.insertionPoints[-1]); } }());You end up with [[ and ]] in your footnotes, which you can remove with some find/replace operation.
Peter
August 11, 2016 at 3:06 am in reply to: Convert text of this type: [1,2,3,4] to superscript 1,2,3,4 #87358
Peter KahrelMemberDo a GREP find/change:
Find what: \[([-\d,]+)\]
Change to: $1
Change format: select superscriptPeter
Peter KahrelMemberYou need to replace ^lt; with the less-than symbol.
P.
Peter KahrelMemberThanks for fixing the brace and parentheses, Ari. Cursed copy gremlins!
As to the page numbering setting, that must be by section because otherwise Bryan’s workflow doesn’t work at all.P.
Peter KahrelMemberHere’s a script that sorts book files by their (first) page number.
(function () { var list = []; var docs = app.books[0].bookContents; for (var i = 0; i < docs.length; i++) { list.push ({name: docs[i].name, firstPage: Number(docs[i].documentPageRange.replace(/-\d+/,''))}); } list.sort (function (a,b) {return a.firstPage - b.firstPage}) for (i = list.length-1; i >= 0; i--) { docs.item(list[i].name).move (LocationOptions.AT_BEGINNING); } }Peter
Peter KahrelMember> wouldn’t that script apply the ‘Hide’ character style to the last two characters
No:
lines[j].characters[-2]means ‘the one-before-last character in lines[j]’> in a line that ends with a discretionary line break; even if the line ended with a discretionary line break following a letter?
That’s true. But in Mike’s example that wasn’t the case.
P.
Peter KahrelMember> can discretionary line breaks be imported in XML?
Probably. Their hex code is 200B, you can use that. Not sure how, though.
> you are hiding every comma, not just the comma at the end of a link where a wrap occurred. Am I correct?
Not really. The script first unhides all commas, then hides the commas at the end of each line. That’s really only needed if you change the width of a column table, because the styles aren’t updated automatically when you resize a column. If you never resize, then lines 5 and 6 can be deleted (the two lines starting with cells[i].texts[0]).
P.
Peter KahrelMemberQuestion #1: Add a discretionary line break after every comma. That’ll keep the digits together.
Question #2: Not automatically. A Grep style won’t work because you can’t find the end of turn lines (except when you add forced line breaks, which you probably don’t want). But a script can do that.
Create a character style Hide (set just the colour to Paper), then click somewhere in the table and run the script.
(function () { var i, lines, cells; cells = app.selection[0].parent.parent.cells.everyItem().getElements(); for (i = 0; i < cells.length; i++) { cells[i].texts[0].appliedCharacterStyle = app.documents[0].characterStyles[0]; cells[i].texts[0].clearOverrides (OverrideType.CHARACTER_ONLY); lines = cells[i].lines; for (j = 0; j < lines.length; j++) { if (lines[j].characters[-1].contents == SpecialCharacters.DISCRETIONARY_LINE_BREAK) { lines[j].characters[-2].appliedCharacterStyle = 'Hide'; } } } }());Peter
Peter KahrelMemberYou say you’re new to scripting, so before you get into file renaming you should read chapter 3 in the JavaScript Tools guide, see Help > JavaScript Tools Guide CC (or CS6, etc.) in the ESTK.
You can’t rename an open document, but what you can is save it under a different name and delete the original. Here’s some code to get you started (including a simple dialog to get a page number):
(function () { // Get a page number from the user var page = prompt ('Page number: ', '0'); // If the user pressed Escape or just closed the window, 'page' is null if (page !== null) { // Store the document's name var docPath = app.documents[0].fullName; // Create the new name by replacing the initial number with the user input var outfile = File (app.documents[0].filePath+'/'+app.documents[0].name.replace (/^\d+/, page)); // Save the document using the new name app.documents[0].save (outfile); app.documents[0].close(); // Delete the original document docPath.remove(); } }Peter
Peter KahrelMemberNo, with GREP styles you can look for text only, not any formatting.
By the way, do you really need that character style? Many modern fonts have old-style figures built in, which you can set in your paragraph style at ‘Default figure style’ (sorry, had to ask).Peter
-
AuthorPosts
