Files
ShrlAlgoToolkit/RvAddinTest/CreateWindow.xaml.cs

73 lines
2.2 KiB
C#
Raw Normal View History

2024-12-22 10:26:12 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Nice3point.Revit.Toolkit.External.Handlers;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
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)
{
}
//uiapp.Application.DocumentChanged -= Application_DocumentChanged;
});
}
private void Application_DocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e)
{
if (e.GetAddedElementIds().Count == 1)
{
var id = e.GetAddedElementIds().FirstOrDefault();
var elem = e.GetDocument().GetElement(id);
if (elem is FamilyInstance ins && ins.Symbol.FamilyName.Contains("铜球阀"))
{
}
}
}
}