123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- 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.Navigation;
- using System.Windows.Shapes;
- using Autodesk.RevitAddIns;
- using LRH.Controls;
- using RevitVersion;
- namespace LRH
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : WindowBase
- {
- public MainWindow()
- {
- InitializeComponent();
- this.Loaded += MainWindow_Loaded;
- }/// <summary>
- /// 删除指定控件的指定事件
- /// </summary>
- /// <param name="control"></param>
- /// <param name="eventname"></param>
- public void ClearEvent(System.Windows.Forms.Control control, string eventname)
- {
- if (control == null) return;
- if (string.IsNullOrEmpty(eventname)) return;
- BindingFlags mPropertyFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
- BindingFlags mFieldFlags = BindingFlags.Static | BindingFlags.NonPublic;
- Type controlType = typeof(System.Windows.Forms.Control);
- PropertyInfo propertyInfo = controlType.GetProperty("Events", mPropertyFlags);
- EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(control, null);
- FieldInfo fieldInfo = (typeof(System.Windows.Forms.Control)).GetField("Event" + eventname, mFieldFlags);
- Delegate d = eventHandlerList[fieldInfo.GetValue(control)];
- if (d == null) return;
- EventInfo eventInfo = controlType.GetEvent(eventname);
- foreach (Delegate dx in d.GetInvocationList())
- eventInfo.RemoveEventHandler(control, dx);
- }
- private void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- Button_Click(sender,e);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- var application = GetAddInApplication();
- AddInManager.StartRevit(StartType.Start,application);
- this.Close();
- }
- public RevitAddInApplication GetAddInApplication()
- {
- string fileName = System.IO.Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "LRH.RevitApplication.dll");
- RevitAddInApplication application = new RevitAddInApplication("LRH", fileName, Guid.NewGuid(), "LRH.RevitApplication.XHApplication", "FWindSoft");
- return application;
-
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- var application = GetAddInApplication();
- AddInManager.StartRevit(StartType.StartAuto, application);
- this.Close();
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- var application = GetAddInApplication();
- AddInManager.StartRevit(StartType.Attach, application);
- }
- private void Button_Click_3(object sender, RoutedEventArgs e)
- {
- var application = GetAddInApplication();
- AddInManager.StartRevit(StartType.Cancel, application);
- }
- }
- }
|