In the last post we looked at some simple JavaScript code to automate AutoCAD’s UI Finder, locating a sequence of commands in the ribbon. In this post we’re going to look at how to generate a more extensive list directly from AutoCAD’s documentation.
The first step I took was to download and install the offline help for AutoCAD 2016. This gives us a set of HTML and JavaScript files in a local folder (c:\Program Files\Autodesk\AutoCAD 2016 Help/English/Help on my system). To parse the files I ended up using some old-school UNIX commands via my OS X environment (which shares the above folder via Parallels). I’m sure you can get these tools for Windows, too, but it seemed simplest (for me) to do it this way.
Here’s what I ended up writing to get the help IDs from the HTML source. I used grep to identify the lines of interest – although as these files are ultimately a single line all this really does is identify and concatenate the files containing the search string – and then piped the data into sed, allowing us to extract the help identifiers from the input.
To make it simpler to copy/paste the data into a JavaScript file, I surrounded each ID by double quotes and suffixed a comma.
grep -r '<span class=\\"uifinderbtn\\" data-id=\\"' * | \
sed 's/.*<span class=\\"uifinderbtn\\" data-id=\\"\([0-9A-Z_a-z ]*\)\\">Find<\/span>.*/"\1",/g' | \
sort | uniq
From there I used sort & uniq to get rid of any duplicates from the list.
Looking for help topics was very similar – it’s only the attribute name that changes slightly:
grep -r '<span class=\\"uifinderbtn\\" data-helptopic=\\"' * | \
sed 's/.*<span class=\\"uifinderbtn\\" data-helptopic=\\"\([0-9A-Z_a-z ]*\)\\">Find<\/span>.*/"\1",/g' | \
sort | uniq
I won’t post the list of IDs these two command sequences generated… suffice it to say that at 2 seconds per command I was waiting for several minutes watching the UI Finder do its thing. Which was cool in a very geeky way.
To take this series further, I’m going to need to spend some time writing a palette-based UI. I won’t be doing that immediately, though… today I managed to get side-tracked by an interesting project someone brought to me in desperation: for an internal team-building activity they need a 60-piece circular jigsaw puzzle (whether they end up 3D printing it or – and this was my suggestion – use a laser cutter to create it). So yes, this afternoon I spent some time writing a basic AutoCAD app to help generate jigsaw puzzles. Which we’ll look at next time. :-)