多项功能优化
This commit is contained in:
72
RvAddinTest/CreateWindow.xaml.cs
Normal file
72
RvAddinTest/CreateWindow.xaml.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
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("铜球阀"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user