using Autodesk.Revit.DB; using ShrlAlgoToolkit.Revit.Extensions; using System; using System.IO; using System.Windows; using System.Windows.Interop; namespace ShrlAlgoToolkit.Revit.Extensions { public static class ApplicationExtensions { /// /// 显示窗口 /// /// /// public static void Show(this Window window, IntPtr handle) { // ReSharper disable once ObjectCreationAsStatement _ = new WindowInteropHelper(window) { Owner = handle }; window.Show(); } /// /// 新建族文档 /// /// /// 族样板文件名,不含扩展 /// public static Document NewFamilyDoc( this Autodesk.Revit.ApplicationServices.Application app, string templateFileName) { var dir = $"{app.FamilyTemplatePath}"; if (!Directory.Exists(dir)) { dir = Path.Combine($@"C:\ProgramData\Autodesk\RVT {app.VersionNumber}", @"Family Templates\Chinese"); if(!Directory.Exists(dir)) { throw new InvalidOperationException("未找到族样板路径"); } } //查找路径下templateFileName文件 var files = Directory.GetFiles(dir, $"{templateFileName}.rft", SearchOption.AllDirectories); if (files.Length > 0) { return app.NewFamilyDocument(files[0]); } throw new InvalidOperationException("未找到该族样板"); //var tempatePath = $"{app.FamilyTemplatePath}\\{templateFileName}.rft"; //if(!File.Exists(tempatePath)) //{ // tempatePath = Path.Combine( // $@"C:\ProgramData\Autodesk\RVT {app.VersionNumber}", // @"Family Templates\Chinese", // $"{templateFileName}.rft"); // if(!File.Exists(tempatePath)) // { // return null; // } //} //return app.NewFamilyDocument(tempatePath); } } }