Monday, June 27, 2011

Creating an AutoCAD ribbon component

It might always seem that everyone is using the most recent version of AutoCAD, this is not necessarily true though. I work for a global consulting engineering firm and we have been on AutoCAD 2008 up until just earlier this year. The same goes for several of our clients and it is not uncommon for us to deliver packages in pre-AutoCAD 2008 environments.

This sounds archaic and out-dated but the real world has many variables that come into play and it is not feasible to always upgrade as soon as a new version of AutoCAD is released. Sure, if your company is working strictly with Autodesk products upgrades can be smooth and more timely, but when you rely on several different AutoCAD vertical packages and customized environments upgrades can become a time consuming effort that requires planning and strategy.

Regardless of what version of AutoCAD you may be working with I thought it might be helpful to do a post on User Interface (UI) and specifically talk about converting a pre-AutoCAD 2009 toolbar button to an AutoCAD 2011 ribbon component.

Let's say you have a custom toolbar in AutoCAD 2008 with a button that executes a command defined in mnl or dll that inserts a valve on a specific layer, breaks a line, allows rotation, etc. You want the same functionality in AutoCAD 2011 but you would like for your users to be able to execute the command from a custom ribbon. The command behind the button will not change, it can still execute with the same definition (unless it is in .net and the dll needs to be recompiled using the updated api files) we just need to make the command available via the ribbon.

To get started: Copy your custom content (cui, mnl, etc) to a new folder. Open AutoCAD 2011 and create a new user profile (Options | Profiles | Add To List)



To migrate a legacy cui file type in cui or select cui, User Interface from the Manage tab on the AutoCAD 2011 ribbon. From the Customize User Interface dialog click the Transfer tab. On the right side of the transfer tab (Customizations in New File) click Open. Note: to see .cui files (which are legacy since they are not .cuix) you will need to select .cui in the file type dropdown list.



Browse to the new folder created above and open the cui file. As soon as the cui file is open click the save icon and a new cuix file is created.



You can now choose how the architecture of your new profile will be built, I will partially load the new cuix file in to my main AutoCAD cui file. Later, we can come back and load it as the enterprise cui but while we are developing it we need to be able to write to it.

Just by partially loading the cuix file you will have the functionality that was in the legacy cui environment. This is all that is required to transfer functionality of a legacy menu system into a newer version of AutoCAD. Now let's create a new ribbon tab instead of offering only toolbars.

A quick note on the architecture of the ribbon. There is one ribbon with multiple tabs (these are the different areas that are selected at the top of the ribbon) each tab is divided into panels. We will create 1 new tab with a panel that contains our valve command. There is quite a bit more detail that can happen at the panel level such as sub-panels, panel rows, dropdowns, and separators but we will just focus on the ribbon tab and a single panel in this post.

Open the cui, scroll down to Partial Customization Files and select our custom cui file. Click the Ribbon node, right click on Tabs and select New Tab.



The ribbon tab is a container that will contain a panel or multiple panels. Create a new panel.



Populating a panel with commands that are already defined is simply a matter of dragging the command from the cui command list up to the panel.



To associate the panel with a tab drag the panel up into the tab



This association only needs to be created once. As the commands within the panel are changed (added or removed) they will reflect on the tab.

In order for the new ribbon tab to be available it needs to be toggled to display for the current workspace (similar to other toolbars, menus, and ribbon tabs).



The new ribbon tab now shows up in the main AutoCAD ribbon



And when it is selected the new panel (or panels) display with the commands that were added to each panel (Note, the order of the commands on the panel is controlled back in the cui by dragging the commands to their desired row and order).

When the new panel component is selected the same command is invoked! You have streamlined the migration of a legacy toolbar button to a new sexy ribbon component. Depending on how your new Ribbon/Tab/Panel layout ends up you may want to take the time to create new graphics for the components and if you choose to do so it is just a matter of pointing to the new image file from the ribbon element.