107 lines
3.1 KiB
C#
107 lines
3.1 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Architecture;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.UI.Selection;
|
|
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace Szmedi.RvKits.Civil.RoomReinforcement
|
|
{
|
|
/// <summary>
|
|
/// RoomNamingWin.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class RoomNamingWin
|
|
{
|
|
private readonly UIApplication uiapp;
|
|
|
|
public RoomNamingWin(UIApplication uiapp)
|
|
{
|
|
this.uiapp = uiapp;
|
|
RoomNames = new ObservableCollection<string>();
|
|
ReadSettings();
|
|
DataContext = this;
|
|
InitializeComponent();
|
|
}
|
|
|
|
public ObservableCollection<string> RoomNames { get; set; }
|
|
|
|
private void BtnAddItem_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(TbRoomName.Text))
|
|
{
|
|
RoomNames.Add(TbRoomName.Text);
|
|
Properties.Settings.Default.RoomNames.Add(TbRoomName.Text);
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
|
|
private void BtnDeleteItem_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (LbRoomNames.SelectedItem != null & LbRoomNames.SelectedIndex != -1)
|
|
{
|
|
var name = LbRoomNames.SelectedItem.ToString();
|
|
RoomNames.Remove(name);
|
|
Properties.Settings.Default.RoomNames.Remove(name);
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
}
|
|
|
|
private void ReadSettings()
|
|
{
|
|
foreach (var name in Properties.Settings.Default.RoomNames)
|
|
{
|
|
RoomNames.Add(name);
|
|
}
|
|
}
|
|
|
|
private void BtnPlace_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
OnRenameRoom();
|
|
}
|
|
|
|
private void OnRenameRoom()
|
|
{
|
|
Hide();
|
|
var uidoc = uiapp.ActiveUIDocument;
|
|
var doc = uidoc.Document;
|
|
try
|
|
{
|
|
while (true)
|
|
{
|
|
var refer = uidoc.Selection.PickObject(ObjectType.Element, new GenericFilter<Room>());
|
|
var room = doc.GetElement(refer) as Room;
|
|
doc.Invoke(ts =>
|
|
{
|
|
room.get_Parameter(BuiltInParameter.ROOM_NAME).Set(LbRoomNames.SelectedItem.ToString());
|
|
});
|
|
}
|
|
}
|
|
catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }
|
|
catch (Exception exception)
|
|
{
|
|
Console.WriteLine(exception);
|
|
throw;
|
|
}
|
|
|
|
ShowDialog();
|
|
}
|
|
|
|
private void LbRoomNames_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
OnRenameRoom();
|
|
}
|
|
|
|
private void BtnClearItems_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var result = MessageBox.Show(this, "确定清空房间列表吗?", "警告", MessageBoxButton.OKCancel);
|
|
if (result == MessageBoxResult.OK)
|
|
{
|
|
RoomNames.Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|