Issue
I'm looking at a ContentGeneratorWPF sample in the REX SDK. I want to add my own menu items to the Revit extension menu. I can add the commands and menuItem in the MainControl.xaml file and it appears fine in the VS2010 designer, but when I run the menu is not visible. I tried setting the visibility in the OnLayout overload but still had no success. How can we add an item to the extension?
Solution
In the sample ContentGeneratorWPF in the SDK, you will see MainControl.xaml. There is a menu item called Calculations in the design view. It doesn’t appear when running in the Revit.
In order to make the menu visible, you will need to modify the code in:
Extension.cs >> OnCreateLayout(), and add:
| (long)REXUI.SetupOptions.Menu;
and
UI.ShowCommand(REXUI.CommandOptions.MenuCalculation);
UI.ShowCommand(REXUI.CommandOptions.MenuCalculationRun);
Below is the whole OnCreateLayout() method:
public override void OnCreateLayout()
{
base.OnCreateLayout();
System.SetCaption();
global::System.Windows.Media.Imaging.BitmapImage
logoImage =
REXLibrary.GetResourceImage(GetType().Assembly,
"Resources/Other/Images/REX_logo.png");
// UI.SetLogo(logoImage);
Layout.ConstOptions =
(long)REXUI.SetupOptions.HSplitFixed
| (long)REXUI.SetupOptions.VSplitFixed
| (long)REXUI.SetupOptions.TabDialog
| (long)REXUI.SetupOptions.List
| (long)REXUI.SetupOptions.FormFixed
// (1) added the menu on the dialog
| (long)REXUI.SetupOptions.Menu;
Layout.AddLayout(new REXLayoutItem(
REXLayoutItem.LayoutType.Layout, "Element", "",
"Element", (long)0, SelectedElementControlRef,
null, logoImage));
Layout.AddLayout(new REXLayoutItem(
REXLayoutItem.LayoutType.Layout, "Recognition",
"", "Recognition", (long)0, CGReadControlRef,
null, logoImage));
Layout.AddLayout(new REXLayoutItem(
REXLayoutItem.LayoutType.Layout, "Creation",
"", "Creation", (long)0, CGCreateControlRef,
null, logoImage));
// (2) added
//
// Menu is visible
UI.ShowCommand(REXUI.CommandOptions.MenuCalculation);
// Command is visible
UI.ShowCommand(REXUI.CommandOptions.MenuCalculationRun);
////
// insert code here.
if (ExtensionRef != null)
ExtensionRef.OnCreateLayout();
SelectedElementControlRef.SetDialog();
CGReadControlRef.SetDialog();
CGCreateControlRef.SetDialog();
}
After this modification, the menu becomes visible.