Customization Blog series: Customizing the Ribbon - Blog 4 of 4

Managing Visibility of Tools

Up to the last blog, we created a workflow, added tabs, groups and tools within them. All seems done! However, just consider a situation where you have a tool that can be used only in a sheet model. You don’t want it to be displayed when a design or drawing model is opened. How do you restrict the display of this tool? The answer is, by selecting appropriate named expressions in the Visibility property in the Customize Ribbon dialog. Not just a tool or button, you can also control the display of a split button, ribbon group, tab, and even a workflow using this property.

Additionally, you can also use the Enable Expression and Sync Item Event properties in the Customize Ribbon dialog. The Enable Expression property allows you to enable/disable a tool based on the named expression evaluation and the Sync Item Event property allows you to select the instance when the expression will be evaluated. For example, to evaluate the state of a button on every model change, select Active Model Changed from the Sync Item Event drop-down.

Before going into how to use these properties, you should know what are Named Expressions. By definition, named expressions are used to retrieve application data structures, and properties of application data, such as files, models, and elements. Practically speaking, named expressions can be used to define conditions under which a UI element (tool, ribbon component, contextual menu, etc.) is shown/hidden or enabled/disabled. You must have already observed that the options in the contextual menu change with the type of element on which you right-click. This is achieved using named expressions.

Named expressions can be defined in a .dgnlib file pointed by the MS_GUIDGNLIBLIST configuration variable. The Named Expressions dialog (Drawing > Utilities > Utilities> Named Expressions) is used to create and manage named expressions.

A named expression is composed of the following:

  • Internal name – Name stored in the .dgnlib.
  • External name – Name displayed where the named expressions are listed.
  • Description – Brief description, visible only in the Named Expressions dialog.
  • Keywords – The selection of keywords define where all the named expression will be visible. For example, to make a named expression visible for use in the ribbon customizations, turn on the User Interface keyword.
  • Symbol Sets – Symbols are values and properties. Symbol sets are a group of symbols. Symbol sets are used to generate the expressions. For example, the IsConfigVarDefined symbol in the ConfigVar symbol set will return whether a configuration variable is defined.
  • Expression – A text string that will be evaluated. An expression contains symbols, operators (arithmetic, comparison, conditional, etc.), and optionally numbers (integers or double precision real), and strings. 

There are many named expressions delivered with the product. You may use them or create your own ones. In this blog, we will create a simple named expression and use it in our ribbon customization. The “Export to DWG” button that we created in the previous blog is useful only if you are in a DGN file and want to convert it to DWG. If you are already in a DWG file, you don’t need this button. To achieve this, we will create a named expression to evaluate the file type. The result of this evaluation will decide whether the button should be displayed.

Let’s start with creating a named expression.

  1. In the UI.dgnlib, open the Named Expressions dialog (Drawing > Utilities > Utilities> Named Expressions).
  2. In the Named Expressions dialog, click New.
  3. In the Internal Name and External Name fields, type ActiveFileDGN.
  4. In the Description field, type “Test to check if the file is DGN.”
  5. In the Keywords list, turn on User Interface.
  6. In the Symbol Sets drop-down, select Session and click Add.
  7. Right-click in the Expression field, and choose Session > Session.IsV8DgnFile().
  8. To check the expression, click the Test button. Since the dgnlib file is V8 DGN based, it will show the result as True.
  9. Click Save.

Let us now use the named expression in our ribbon customization.

  1. In the Customize Ribbon dialog, expand Roadway > Drafting > Common Tools, and select the Export to DWG button.
  2. In the Properties section, click the drop-down for the Visibility property and select ActiveFileDGN.
  3. Click Apply.

Now, to test the effect of this setting, open a DWG file and check the Drafting tab, you will see that the Export to DWG button is not displayed.

This completes the ribbon customization blogs. Next, you will learn about ribbon group pop-up, so do stay tuned...