- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to show (and edit) relevant (project specific) Revit Element Parameters in a DockablePane.
I had a look at The Building Coder: A Simpler Dockable Panel Sample (typepad.com) and many other resources and was able to register the dockable Pane and have a Button to Show/Hide it (CodeSample [1]).
Next Step i tried to Edit the Content of the XAML File before Registering the Dockable Pane which also worked (Line 52-53 CodeSample[2])
Now i want to access/edit the XAML File from a different External Command ( UpdateDockpane CodeSample [3] ) but I cant figure out how to access it.
Is my approach wrong or do I miss something?
There are more challenges for me ahead...
- automatically updating DockpaneContent when selection is changed
- write ParameterValues back to Revit Selected Elements from UserInput in DockablePane
which i will take care after clearing this problem...
Any help will be appreciated.
Best Regards,
Dominik
Code Samples:
[1] Show/Hide DockablePane:
namespace ILF_Parameters.core
{
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
/// <summary>
/// Schow ILF Parameters dokckable pane.
/// </summary>
/// <seealso cref="Autodesk.Revit.UI.IExternalCommand"/>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class ShowILFParametersPaneCommand : IExternalCommand
{
public bool dpIsVisible;
#region public methods
/// <summary>
/// Executes the specified command data.
/// </summary>
/// <param name="commandData"></param>
/// <param name="message"></param>
/// <param name="elements"></param>
/// <returns></returns>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var dpid = new DockablePaneId(PaneIdentifiers.Get_ILF_Parameters_PaneIdentifier());
var dp = commandData.Application.GetDockablePane(dpid);
if (dp.IsShown()){
dp.Hide();
}
else
{
dp.Show();
}
return Result.Succeeded;
}
/// <summary>
/// Gets the full namespace path to this command.
/// </summary>
/// <returns></returns>
public static string GetPath()
{
// Return constructed namespace path.
return typeof(ShowILFParametersPaneCommand).Namespace + "." + nameof(ShowILFParametersPaneCommand);
}
#endregion
}
}
[2] Register the Dockable Pane
namespace ILF_Parameters.ui
{
using System.Windows;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using core;
using Autodesk.Revit.UI.Events;
using ILF_Parameters;
using System.Windows.Controls;
/// <summary>
/// Register ILF Parameters Dockable .
/// </summary>
/// <seealso cref="Autodesk.Revit.UI.IExternalCommand"/>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Register_ILF_Parameters_Pane_Command : IExternalCommand
{
#region public methods
/// <summary>
/// Executes the specified command data.
/// </summary>
/// <param name="commandData"></param>
/// <param name="message"></param>
/// <param name="elements"></param>
/// <returns></returns>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
return Execute(commandData.Application);
}
/// <summary>
/// Register dockable pane.
/// </summary>
/// <param name="uIApplication"></param>
/// <returns></returns>
public Result Execute(UIApplication uIApplication)
{
var data = new DockablePaneProviderData();
var ILFParametersPage = new ILFParametersMainPage();
TextBlock txtwhatchthis = (TextBlock) ILFParametersPage.FindName("MyTextBlock");
txtwhatchthis.Text = txtwhatchthis.Text + " - OVERWRITTEN @Anonymous";
data.FrameworkElement = ILFParametersPage as FrameworkElement;
// Setup initial state.
var state = new DockablePaneState
{
DockPosition = DockPosition.Right,
};
// Use unique guid identifier for this dockable pane.
var dpid = new DockablePaneId(PaneIdentifiers.Get_ILF_Parameters_PaneIdentifier());
uIApplication.RegisterDockablePane(dpid, "ILF Parameters", (IDockablePaneProvider)ILFParametersPage);
return Result.Succeeded;
}
#endregion
}
}
[3] UpdateDockpane Command:
namespace ILF_Parameters.core
{
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
/// <summary>
/// Command code to be executed when button is clicked.
/// </summary>
/// <seealso cref="Autodesk.Revit.UI.IexternalCommand"/>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class UpdateDockpane : IExternalCommand
{
#region public methods
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
TaskDialog.Show("Revit", "TestyDoesMybuttonWork?");
var dpid = new DockablePaneId(PaneIdentifiers.Get_ILF_Parameters_PaneIdentifier());
var dp = commandData.Application.GetDockablePane(dpid);
//How to edit XAML here?
return Autodesk.Revit.UI.Result.Succeeded;
}
/// <summary>
/// Gets the full namespace path to this command.
/// </summary>
/// <returns></returns>
public static string GetPath()
{
// Return constructed namespace path.
return typeof(UpdateDockpane).Namespace + "." + nameof(UpdateDockpane);
}
#endregion
}
}
[4] Xaml File
<Page x:Class="ILF_Parameters.ui.ILFParametersMainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ILF_Parameters.ui"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="ILF Parameters">
<Grid Background="White" >
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions >
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<TextBlock Margin ="0" Grid.Column="1" FontSize="12" Foreground="Black" TextWrapping="Wrap" FontFamily="Arial">Selected Elements Classification:</TextBlock>
<TextBlock Name="SlctElementsClassification" Margin ="5,20,0,0" Grid.Column="1" FontSize="14" Foreground="CadetBlue" TextWrapping="NoWrap" FontFamily="Arial">nothing Selected</TextBlock>
</Grid>
<Grid Grid.Row="1">
<TextBlock Name="MyTextBlock"
Margin ="5,5,5,5" Grid.Column="1"
FontSize="10" Foreground="Black"
TextWrapping="Wrap"
FontFamily="Arial">
Mytestinfo1<LineBreak></LineBreak>Mytestinfo2
</TextBlock>
<TextBox x:Name="Userinput1"
Text="TextyText"
Margin ="5,40,5,5"
Height ="20"
Width ="Auto"
HorizontalAlignment="Left"
VerticalAlignment="Top"
/>
</Grid>
</Grid>
</Page>
[5] XAML.CS
namespace ILF_Parameters.ui
{
using System;
using System.Windows;
using System.Windows.Controls;
using Autodesk.Revit.UI;
using core;
/// <summary>
/// Interaktionslogik für ILFParametersMainPage.xaml
/// </summary>
public partial class ILFParametersMainPage : Page, IDockablePaneProvider
{
#region constructor
/// <summary>
/// Default constructor.
/// Initializes a new instance of the <see cref="ILFParametersMainPage"/> class.
/// </summary>
public ILFParametersMainPage()
{
InitializeComponent();
}
#endregion
#region public methods
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <exception cref="NotImplementedException"></exception>
public void Dispose()
{
this.Dispose();
}
/// <summary>
/// Setups the dockable pane.
/// </summary>
/// <param name="data"></param>
/// <exception cref="NotImplementedException"></exception>
public void SetupDockablePane(DockablePaneProviderData data)
{
data.FrameworkElement = this as FrameworkElement;
// Define inital pane position in Revit UI.
data.InitialState = new DockablePaneState
{
DockPosition = DockPosition.Right,
};
}
#endregion
}
}
Solved! Go to Solution.