Files
Shrlalgo.RvKits/ShrlAlgoToolkit.Revit/Extensions/ApplicationExtensions.cs

65 lines
2.3 KiB
C#
Raw Normal View History

2025-04-24 20:56:44 +08:00
using Autodesk.Revit.DB;
2025-07-11 09:20:23 +08:00
using System.IO;
2025-04-24 20:56:44 +08:00
using System.Windows;
2024-09-22 11:05:41 +08:00
using System.Windows.Interop;
2025-04-24 20:56:44 +08:00
namespace ShrlAlgoToolkit.Revit.Extensions
2024-09-22 11:05:41 +08:00
{
2025-04-24 20:56:44 +08:00
public static class ApplicationExtensions
2024-09-22 11:05:41 +08:00
{
/// <summary>
/// 显示窗口
/// </summary>
/// <param name="window"></param>
/// <param name="handle"></param>
public static void Show(this Window window, IntPtr handle)
{
// ReSharper disable once ObjectCreationAsStatement
_ = new WindowInteropHelper(window) { Owner = handle };
window.Show();
}
2025-07-11 09:20:23 +08:00
2024-09-22 11:05:41 +08:00
/// <summary>
/// 新建族文档
/// </summary>
/// <param name="app"></param>
/// <param name="templateFileName">族样板文件名,不含扩展</param>
/// <returns></returns>
2025-07-11 09:20:23 +08:00
public static Document NewFamilyDoc(
this Autodesk.Revit.ApplicationServices.Application app,
string templateFileName)
2024-09-22 11:05:41 +08:00
{
2025-07-11 09:20:23 +08:00
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);
2024-09-22 11:05:41 +08:00
}
}
}