Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit .NET API: Create Custom Preview Control (PreviewControl) (pt. 1)

$
0
0

Revit .NET has provided the PreviewControl API since version 2013. In this series of posts, we are going to explore the Revit PreviewControl .NET API step by step.

In this part, we create the simplest custom PreviewControl to get the basic idea first about the PreviewControl API.

•    Use the Revit .NET Addin Wizard (RevitNetAddinWizard) to create a C# addin project for Revit 2014. To make it as simple as possible, what we only need to do is change the default project name from whatsoever to RevitModelPreview and accept any other default settings.
•    Manully upgrade the project type of the RevitModelPreview.csproj from Class Library to WPF User Control Library through adding the <ProjectTypeGuids> element to the Project/PropertyGroup:
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

•    Add a grid to the Window1.xaml and make it look a bit nice:
<Window x:Class="RevitModelPreview.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid Height="234" HorizontalAlignment="Left" Name="grid1" VerticalAlignment="Top" Width="278" />
    </Grid>
</Window>

•    Add the PreviewControl creation code to the Execute callback of the ExtCmd:
                FilteredElementCollector collecotr = new FilteredElementCollector(CachedDoc);
                collecotr.OfClass(typeof(Autodesk.Revit.DB.View));

                Window1 win = new Window1();
                win.grid1.Children.Add(new PreviewControl(CachedDoc, collecotr.FirstElementId()));
                win.ShowDialog();

That is about it. A simple but working custom PreviewControl addin has been successfully done in a couple of minutes and we are ready to go!  If we press the F5 key to give it a try in the Revit 2014, as chosen during the project creation time by Revit .NET Addin Wizard (RevitNetAddinWizard), we will notice the first view of the current document appears nicely in the WPF window.
RevitModelPreview_WPF

Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles