/* ============================================================================== * 功能描述:RenameSystemName * 创 建 者:Garrett * 创建日期:2019/6/20 9:11:31 * ==============================================================================*/ using System; using System.Collections.Generic; using System.IO; using System.Linq; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Electrical; using SAGA.DotNetUtils.Extend; using SAGA.DotNetUtils.NPOI; using SAGA.DotNetUtils.Others; using SAGA.RevitUtils.Extends; namespace Saga.PlugIn.Other { /// /// RenameSystemName /// class RenameSystemName { private static void OperateFloor(string fullPah, List refRenameSystems) { var doc= ExternalDataWrapper.Current.UiApp.Application.OpenDocumentFile(fullPah); using (Transaction trans = new Transaction(doc, "重命名系统名称")) { trans.Start(); try { var types = doc.GetElements(typeof(MEPSystemType)); types.AddRange(doc.GetElements(typeof(CableTrayType))); foreach (ElementType type in types) { string typeName = type.Name; var refPair=refRenameSystems.FirstOrDefault(t => t.OldName == typeName); if (refPair != null) { type.Name = refPair.NewName; } } trans.Commit(); } catch (Exception e) { Console.WriteLine(e); trans.RollBack(); } } } public void Operate(string referPath,string revitDir) { var refPairs = GetReferencePairs(referPath); if (!refPairs.Any()) return; var list = GetRevitFiles(revitDir); if (!list.Any()) return; foreach (string fullPath in list) { OperateFloor(fullPath, refPairs); } } /// /// 获取需要修改的Revit文件 /// /// /// private static List GetRevitFiles(string revitDir) { DirectoryInfo directory=new DirectoryInfo(revitDir); List list=new List(); try { list=directory.GetFiles("*.rvt").Where(t=>!t.FullName.Is000File()).Select(t=>t.FullName).ToList(); } catch (Exception e) { Console.WriteLine(e); } return list; } /// /// 参考-表 /// Sheet1 [SheetInfo(SheetName = "Sheet1", RowStartIndex = 3)] public class Ref_RenameSystem { [CellIndex(2)] public string OldName { get; set; } [CellIndex(3)] public string NewName { get; set; } } /// /// 获取可识别的管道系统名称 /// /// private static List GetReferencePairs(string path) { var list = NPOIHelper .ConvertExcelSheetToModel(path); return list; } } }