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:
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.
Let us now use the named expression in our ribbon customization.
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...