Hello all! I’ve written an InDesign (CS5.5) script which compares text style ranges within a given paragraph and gives the user a dialog box listing exactly what formatting has changed from one text style range to the next.
So far, so good - this works a treat - but I’d then like to present the user with the option, after having reviewed the change(s), of copying the text formatting from one text style range into the other, thus effectively merging the two text style ranges into one. (Why? Because I’ll later be exporting all the text from the document for translation into another language in an external application (and then reimporting into InDesign), and want to remove any “superfluous” formatting changes (e.g. tracking) first because they complicate subsequent processing (the external application breaks the text up into text style range-sized chunks, which can be nasty for the translator).
If I were performing this task manually in InDesign, I’d simply be using the Eyedropper tool to copy and paste the text formatting - but is there a simple way of doing the same thing via scripting? I’ve had a few ideas (e.g. using character styles, copying/pasting actual text), but none of them seem straightforward to implement. Am I missing an obvious trick? In a perfect world, I’d simply be able to say “copy properties of text style range x to properties of text style range y”, but believe it or not, that doesn’t work.
Please ask if you need to know more about what I’ve done so far and how I did it (clue: it basically involved obtaining the respective text style ranges’ properties as records, and making great big ol’ lists out of them in the format {(…){auto, “leading”},{0.0, “tracking”}, (etc.)} so I could more easily manipulate the data. Of course, it’s always possible I took the long way around there too, and that there’s a simpler way of doing this whole thing.
Thanks for any help anyone can offer, etc.! Creative alternatives to the entire process are especially welcome.
Chris.
Model: iMac
AppleScript: 2.1.2
Browser: Safari 534.59.8
Operating System: Mac OS X (10.8)
if you’re coercing records to lists, be aware that it’s a very fragile thing to do. There’s no guarantee that stuff will always come in the same order; items can be left out, versions can make changes, and plug-ins can add extra properties.
Of course if it’s working for you, and you’re happy with those limitations, fine. But the other side of the coin is that having lists rather than records makes it much harder to do the bit you want to do now.
Ahem. I’m not exactly coercing properties records into lists (do you mean, e.g. “(properties of text style range x) as list”? I wasn’t aware that was even possible!). To come clean, what I’m actually doing is rather more low-tech than that. My script laboriously builds its properties lists by hand, adding several hundred list items one at a time via explicit interrogation of every record item in turn (well, not EVERY record item… I’m obviously excluding properties such as length, offset, object reference, etc., that are bound to change anyway from one text style range to the next). Yes, I wasn’t exactly trumpeting this fact in my original post, because I’m not especially proud of it. :rolleyes: However, it does achieve the desired result… for now at least.
I do take your point about fragility, though, Shane, and if I could think of a better (i.e. elegant and bulletproof) strategy for achieving my ultimate goal I’d use it, if only for my own self-esteem! I don’t mind fixing stuff that breaks a year or two down the line, but I do have a preference for concise code if possible - and this code sure ain’t concise in its present form.
So, if it’s not a cheeky question… any idea where you’d start if you were writing a script to report differences between consecutive text style ranges and then (if requested by the user) merge them into one range? Is there a simple way of comparing two records that I haven’t thought of?
So, if it’s not a cheeky question… any idea where you’d start if you were writing a script to report differences between consecutive text style ranges and then (if requested by the user) merge them into one range?