Files
ShrlAlgoToolkit/ShrlAlgo.Addin.Test/CreateWindow.xaml.cs

44 lines
1.3 KiB
C#
Raw Normal View History

using System.Windows;
2024-12-22 10:26:12 +08:00
using System.Windows.Controls;
using Autodesk.Revit.DB;
using Nice3point.Revit.Toolkit.External.Handlers;
namespace ShrlAlgo.Addin.Test;
2024-12-22 10:26:12 +08:00
/// <summary>
/// CreateWindow.xaml 的交互逻辑
/// </summary>
public partial class CreateWindow
{
private readonly ActionEventHandler handler = new ActionEventHandler();
public CreateWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var button = sender as Button;
handler.Raise(uiapp =>
{
//uiapp.Application.DocumentChanged += Application_DocumentChanged;
try
{
var doc = uiapp.ActiveUIDocument.Document;
var family = new FilteredElementCollector(doc).OfClass(typeof(Family))
.FirstOrDefault(pt => pt.Name.Contains(button.Content.ToString())) as Family;
var fs = doc.GetElement(family.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
if (fs != null && uiapp.ActiveUIDocument.CanPlaceElementType(fs))
{
uiapp.ActiveUIDocument.PromptForFamilyInstancePlacement(fs);
}
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
}
});
}
}