Files
Shrlalgo.RvKits/RvAddinTest/CreateWindow.xaml.cs
2025-02-10 20:53:40 +08:00

44 lines
1.3 KiB
C#

using System.Windows;
using System.Windows.Controls;
using Autodesk.Revit.DB;
using Nice3point.Revit.Toolkit.External.Handlers;
namespace RvAddinTest;
/// <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)
{
}
});
}
}