On my flight back from Singapore I started thinking about how an app might help people discover what’s new in the AutoCAD UI from release to release. This might also work for custom functionality, but that’s not (currently) my main concern. I was thinking of displaying some kind of palette that cycles through the new commands and features in a release, highlighting the associated ribbon buttons, etc., using the AutoCAD help system’s excellent UI Finder capability.
Over the weekend I started looking at how it might work – whether it was possible to call the UI Finder from an app (not just the web-based help, itself). Here’s what I found out: given the right “help IDs”, we can launch the HelpFindUI() method (which we call using exec() from JavaScript) and have it highlight the UI capability we’re interested in.
Here’s a quick demo to illustrate. At this stage it’s just looping through a fixed set of commands – and with no UI to explain what’s happening – but it should clarify the intention, at least.
There are a couple of points to note: the name of the function we need to call has a new prefix in AutoCAD 2016, so we have to code around that. I also found that we need to launch HELP for the HelpFindUI() method to be available: presumably a module gets loaded or something else gets initialized when this happens. I looked into what, specifically, but ended up deciding to launch HELP when our JavaScript gets loaded… we can tweak that, later on, but it does the trick, for now.
Here’s the JavaScript code to make this happen:
// A few command IDs to loop through
var dispCmds =
["ID_Box",
"ID_Scale",
"ID_Extrude",
"ID_Cone",
"ID_3dalign",
"ID_CONV2SOLID",
"ID_Import",
"ID_Offset",
""
];
// A few topic IDs to loop through
var dispTops =
[
"3DDWF",
"3DPRINT",
"VIEWPLOTDETAILS",
""
];
function findBox() {
locateCommand(dispCmds[0], false); // 1st item in the array
}
function findCmds() {
locateCommands(dispCmds.slice(0), false); // Copies the array
}
function findTops() {
locateCommands(dispTops.slice(0), true); // Copies the array
}
function locateCommands(cmds, topic) {
// Pop the first item off the array
var cmd = cmds.shift();
if (cmd != null) {
// Find a single command/UI element
locateCommand(cmd, topic);
// Find the rest, after a 2 second delay
setTimeout(function () { locateCommands(cmds); }, 2000);
}
}
function locateCommand(id, topic) {
var fn = "HelpFindUI";
// In 2016 onwards we need the help_Api prefix
if (typeof (apiVersion) == 'function' && apiVersion() > 2)
fn = "help_Api." + fn;
// Package up the JSON required to call our function
var json = {
functionName: fn,
invokeAsCommand: false,
functionParams: { ID: id, IsTopic: topic }
};
// Call it (ignore the return value, unless debugging)
var ret = exec(JSON.stringify(json));
}
Acad.Editor.addCommand(
"HELP_CMDS",
"FC",
"FC",
Acad.CommandFlag.MODAL,
findBox
);
Acad.Editor.addCommand(
"HELP_CMDS",
"FCS",
"FCS",
Acad.CommandFlag.MODAL,
findCmds
);
Acad.Editor.addCommand(
"HELP_CMDS",
"FTS",
"FTS",
Acad.CommandFlag.MODAL,
findTops
);
// Launch HELP at the end of the command... this allows the
// UI finder to work properly
Acad.Editor.executeCommand("_.HELP");
If you save this to a .js file, you can then WEBLOAD it into AutoCAD 2015 or 2016 and give it a try.
The code implements a few commands: FC highlights a single command button (the one for BOX), while FCS loops through a sequence of such commands with a 2 second delay between each. FTS does the same but for help topics rather than individual commands, although it doesn’t seem to work as consistently as the command-locating version, for now.
To take this further, I’m going to look at locating the various help IDs from the documentation. I may even end up hitting the command-line for an old school grep & sed session, which might be fun. At some point I’ll also look at implementing some kind of web-based UI to drive this… probably cycling through a list of commands in a palette while highlighting the associated UI elements.