- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am new to the forum so hello to everyone 🙂
I have some issues implementing a seemingly simple task using the Revit API.
I would like to have two or more buttons in the Revit UI, which both open the same WPF window, but different pages, depending on which button was clicked.
At the time my code looks like this:
The buttons are created at the start of the application. Each of them calls which has the "IExternalCommand" interface. However if I create a new WPFWindow in each of them, I have two windows, not one.
Do you have any suggestions on which might be the best structure to implement this to only open one window and use this one window for all further pages? Where in the project should I declare and initialize the WPF window so it is accessible from both commands?
A link to a project which uses similar structures might be enought to help me.
Thanks 🙂
Apps.cs:
public Result OnStartup(UIControlledApplication a)
{
string path = Assembly.GetExecutingAssembly().Location;
//Create Tab
a.CreateRibbonTab("MyButtons");
//Panel
Autodesk.Revit.UI.RibbonPanel revitTools = a.CreateRibbonPanel("MyButtons", "MyPanel");
PushButtonData button1data = new PushButtonData("Button 1", "This is button one", path, "WPFWindowProblem.CommandButton1");
PushButton button1 = revitTools.AddItem(button1data) as PushButton;
button1.ToolTip = "This is button one";
PushButtonData button2data = new PushButtonData("Button 2", "This is button two", path, "WPFWindowProblem.CommandButton2");
PushButton button2 = revitTools.AddItem(button2data) as PushButton;
button2.ToolTip = "This is button two";
return Result.Succeeded;
}
CommandButton1.cs:
public class CommandButton1 : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
TaskDialog.Show("Info", "Button one was clicked");
WPFWindow window = new WPFWindow();
Page01 page1 = new Page01();
window.Content = page1;
window.Show();
return Result.Succeeded;
}
}
CommandButton2.cs
public class CommandButton2 : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
TaskDialog.Show("Info", "Button two was clicked");
WPFWindow window = new WPFWindow();
Page02 page2 = new Page02();
window.Content = page2;
window.Show();
return Result.Succeeded;
}
}
Revit 2020, .NET 4.7, VS2019, C'#
Solved! Go to Solution.