RevitAPI C#:如何取消停靠 DockablePane onStart
RevitAPI C#: How to undock DockablePane onStart
我正在尝试做一个定制 dockablePane
并且我能够成功地制作一个。但是,我当前的实现似乎 show
并停靠 dockablePane
onStart
,这不是我想要的。我只想在点击 ribbonButton
.
时 show
窗格
我目前的实现是这样的:
//Application onStart
namespace DockablePane
{
public class SetupLaunchPane : IExternalApplication
{
Result IExternalApplication.OnShutdown(UIControlledApplication application)
{
throw new NotImplementedException();
}
Result IExternalApplication.OnStartup(UIControlledApplication application)
{
//Create a ribbon panel at the top
RibbonPanel ribbonPanel = application.CreateRibbonPanel("Dockable Pane");
//Get url to the DockablePane.dll
string assemblyPath = Assembly.GetExecutingAssembly().Location;
//Create a push button and add to ribbon panel
PushButtonData buttonData = new PushButtonData("launchPane", "Launch Pane", assemblyPath, "DockablePane.LaunchPane");
PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;
//Register dockable pane
application.ControlledApplication.ApplicationInitialized += RegLaunchPane;
return Result.Succeeded;
}
private void RegLaunchPane(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
{
var registerPaneCommand = new RegisterDockablePaneManager();
registerPaneCommand.Execute(new UIApplication(sender as Autodesk.Revit.ApplicationServices.Application));
}
}
}
//Show the dockable pane on button pressed
namespace DockablePane
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class LaunchPane : IExternalCommand
{
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var dpid = new DockablePaneId(DockablePaneIdentifierManager.GetPanelIdentifier());
var dp = commandData.Application.GetDockablePane(dpid);
dp.Show();
return Result.Succeeded;
}
}
}
//Registering the dockable pane
namespace DockablePane
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
class RegisterDockablePaneManager : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
return Execute(commandData.Application);
}
public Result Execute(UIApplication application)
{
try
{
var data = new DockablePaneProviderData();
var pane = new ViewPane();
data.FrameworkElement = pane as FrameworkElement;
var dpid = new DockablePaneId(DockablePaneIdentifierManager.GetPanelIdentifier());
application.RegisterDockablePane(dpid, "Pane", pane as IDockablePaneProvider);
return Result.Succeeded;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return Result.Failed;
}
}
}
}
//At ViewPane.xaml.cs
namespace DockablePane
{
/// <summary>
/// Interaction logic for ViewPane.xaml
/// </summary>
public partial class ViewPane : Page, IDisposable, IDockablePaneProvider
{
public ViewPane()
{
InitializeComponent();
}
public void Dispose()
{
this.Dispose();
}
public void SetupDockablePane(DockablePaneProviderData data)
{
data.FrameworkElement = this as FrameworkElement;
data.InitialState = new DockablePaneState
{
DockPosition = DockPosition.Right
};
}
}
}
如您所见,在 onStart
我只注册了 dockablePane
而没有调用 show
,但是当 Revit 启动时它似乎停靠在右侧。我错过了什么?
里面public void SetupDockablePane(DockablePaneProviderData data)
data.VisibleByDefault = false;
我正在尝试做一个定制 dockablePane
并且我能够成功地制作一个。但是,我当前的实现似乎 show
并停靠 dockablePane
onStart
,这不是我想要的。我只想在点击 ribbonButton
.
show
窗格
我目前的实现是这样的:
//Application onStart
namespace DockablePane
{
public class SetupLaunchPane : IExternalApplication
{
Result IExternalApplication.OnShutdown(UIControlledApplication application)
{
throw new NotImplementedException();
}
Result IExternalApplication.OnStartup(UIControlledApplication application)
{
//Create a ribbon panel at the top
RibbonPanel ribbonPanel = application.CreateRibbonPanel("Dockable Pane");
//Get url to the DockablePane.dll
string assemblyPath = Assembly.GetExecutingAssembly().Location;
//Create a push button and add to ribbon panel
PushButtonData buttonData = new PushButtonData("launchPane", "Launch Pane", assemblyPath, "DockablePane.LaunchPane");
PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton;
//Register dockable pane
application.ControlledApplication.ApplicationInitialized += RegLaunchPane;
return Result.Succeeded;
}
private void RegLaunchPane(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
{
var registerPaneCommand = new RegisterDockablePaneManager();
registerPaneCommand.Execute(new UIApplication(sender as Autodesk.Revit.ApplicationServices.Application));
}
}
}
//Show the dockable pane on button pressed
namespace DockablePane
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class LaunchPane : IExternalCommand
{
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var dpid = new DockablePaneId(DockablePaneIdentifierManager.GetPanelIdentifier());
var dp = commandData.Application.GetDockablePane(dpid);
dp.Show();
return Result.Succeeded;
}
}
}
//Registering the dockable pane
namespace DockablePane
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
class RegisterDockablePaneManager : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
return Execute(commandData.Application);
}
public Result Execute(UIApplication application)
{
try
{
var data = new DockablePaneProviderData();
var pane = new ViewPane();
data.FrameworkElement = pane as FrameworkElement;
var dpid = new DockablePaneId(DockablePaneIdentifierManager.GetPanelIdentifier());
application.RegisterDockablePane(dpid, "Pane", pane as IDockablePaneProvider);
return Result.Succeeded;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return Result.Failed;
}
}
}
}
//At ViewPane.xaml.cs
namespace DockablePane
{
/// <summary>
/// Interaction logic for ViewPane.xaml
/// </summary>
public partial class ViewPane : Page, IDisposable, IDockablePaneProvider
{
public ViewPane()
{
InitializeComponent();
}
public void Dispose()
{
this.Dispose();
}
public void SetupDockablePane(DockablePaneProviderData data)
{
data.FrameworkElement = this as FrameworkElement;
data.InitialState = new DockablePaneState
{
DockPosition = DockPosition.Right
};
}
}
}
如您所见,在 onStart
我只注册了 dockablePane
而没有调用 show
,但是当 Revit 启动时它似乎停靠在右侧。我错过了什么?
里面public void SetupDockablePane(DockablePaneProviderData data)
data.VisibleByDefault = false;