using System.Windows; using System.Windows.Controls; using Autodesk.Revit.DB; using Nice3point.Revit.Toolkit.External.Handlers; namespace RvAddinTest; /// /// CreateWindow.xaml 的交互逻辑 /// 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) { } }); } }