多项功能优化
This commit is contained in:
105
RvAddinTest/SeparateModelWin.xaml.cs
Normal file
105
RvAddinTest/SeparateModelWin.xaml.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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 Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Sai.Toolkit.Revit.Assist;
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
using UIFrameworkServices;
|
||||
|
||||
namespace RvAddinTest;
|
||||
/// <summary>
|
||||
/// SeparateModelWin.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SeparateModelWin
|
||||
{
|
||||
ActionEventHandler separate = new ActionEventHandler();
|
||||
public SeparateModelWin()
|
||||
{
|
||||
InitializeComponent();
|
||||
TbFolder.Text = "F:\\燃气改造项目\\归档";
|
||||
}
|
||||
|
||||
private void MetroButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
separate.Raise(
|
||||
uiapp =>
|
||||
{
|
||||
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
var doc = uidoc.Document;
|
||||
var list = uidoc.Selection.GetElementIds();
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
MessageBox.Show("未选中元素", "提示");
|
||||
return;
|
||||
}
|
||||
var walls = list.Select(id => doc.GetElement(id)).Where(e => e is Wall).Select(e => e.Id).ToList();
|
||||
var others = list.Select(id => doc.GetElement(id)).Where(e => e is not Wall).Select(e => e.Id).ToList();
|
||||
SpearateByIds(doc, walls, true);
|
||||
SpearateByIds(doc, others, false);
|
||||
using (Transaction trans = new Transaction(doc, "删除选中"))
|
||||
{
|
||||
try
|
||||
{
|
||||
trans.Start();
|
||||
doc.Delete(list);
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void SpearateByIds(Document doc, ICollection<ElementId> list, bool isA)
|
||||
{
|
||||
var allOthers = doc.OfModelCollector()
|
||||
.Excluding(list)
|
||||
.ToElementIds();
|
||||
var ids = doc.OfClass<ImportInstance>().ToElementIds();
|
||||
var modelLineIds = doc.OfCollector().OfCategory(BuiltInCategory.OST_Lines).Select(e => e.Id).ToList();
|
||||
var texts = doc.OfCollector().OfCategory(BuiltInCategory.OST_TextNotes).Select(e => e.Id).ToList();
|
||||
using (Transaction trans = new Transaction(doc, "拆分模型"))
|
||||
{
|
||||
try
|
||||
{
|
||||
trans.Start();
|
||||
doc.Delete(allOthers);
|
||||
doc.Delete(ids);
|
||||
doc.Delete(modelLineIds);
|
||||
doc.Delete(texts);
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
if (!Directory.Exists(TbFolder.Text))
|
||||
{
|
||||
Directory.CreateDirectory(TbFolder.Text);
|
||||
}
|
||||
var fileName = isA ? TbFileName.Text + "-A" : TbFileName.Text + "-GE";
|
||||
var filePath = Path.Combine(TbFolder.Text, $"{fileName}.rvt");
|
||||
SaveAsOptions options = new SaveAsOptions() { OverwriteExistingFile = true, PreviewViewId = doc.ActiveView.Id, Compact = true };
|
||||
|
||||
doc.SaveAs(filePath, options);
|
||||
QuickAccessToolBarService.performMultipleUndoRedoOperations(true, 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user