119 lines
4.3 KiB
C#
119 lines
4.3 KiB
C#
using System.ComponentModel;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Windows;
|
||
|
||
using Autodesk.Revit.Attributes;
|
||
using Autodesk.Revit.DB;
|
||
using Autodesk.Revit.DB.Electrical;
|
||
using Autodesk.Revit.DB.Mechanical;
|
||
using Autodesk.Revit.UI;
|
||
using Autodesk.Revit.UI.Selection;
|
||
|
||
using Microsoft.Win32;
|
||
|
||
using Nice3point.Revit.Toolkit.External;
|
||
|
||
using Szmedi.RevitToolkit.Approval.Models;
|
||
|
||
namespace Szmedi.RevitToolkit.Approval.Commands
|
||
{
|
||
/// <summary>
|
||
/// Revit执行命令
|
||
/// </summary>
|
||
[Transaction(TransactionMode.Manual)]
|
||
[Regeneration(RegenerationOption.Manual)]
|
||
public class AddArchiParametersCmd : ExternalCommand
|
||
{
|
||
public override void Execute()
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
|
||
var allElements = Document.OfAllModelCollector();
|
||
if (allElements == null)
|
||
{
|
||
return;
|
||
}
|
||
var elements = allElements.DistinctBy(e => e.Category.Id);
|
||
var sharedParameters = GlobalAssists.GetArchiSharedParameters();
|
||
|
||
var dir = Path.Combine(GlobalAssists.DirAssembly, "mvdlite");
|
||
var major = Document.GetMajor(out string majorName);
|
||
var result = MessageBox.Show(
|
||
$"""
|
||
通过各专业专业独有的构件
|
||
(建筑-门窗,结构-梁,暖通-风管,电气-桥架,给排水-无风管有水管)
|
||
|
||
当前专业为:{majorName},
|
||
是-继续,否-手动选择mvdlite文件
|
||
""",
|
||
"提示",
|
||
MessageBoxButton.YesNoCancel,
|
||
MessageBoxImage.Question);
|
||
string fileContent;
|
||
if (result == MessageBoxResult.Yes)
|
||
{
|
||
fileContent = Directory.GetFiles(dir, "*.mvdlite")
|
||
.FirstOrDefault(f => f.Contains(majorName)) switch
|
||
{
|
||
string file when !string.IsNullOrEmpty(file) => File.ReadAllText(file),
|
||
_ => throw new FileNotFoundException("未找到对应的MVDLite文件,请检查目录或文件名。")
|
||
};
|
||
}
|
||
else if (result == MessageBoxResult.No)
|
||
{
|
||
OpenFileDialog dialog = new OpenFileDialog()
|
||
{
|
||
Filter = "MVDLite 文件 (*.mvdlite)|*.mvdlite",
|
||
Title = "选择 MVDLite 文件",
|
||
InitialDirectory = dir,
|
||
RestoreDirectory = true
|
||
};
|
||
if (dialog.ShowDialog() != true)
|
||
{
|
||
return;
|
||
}
|
||
fileContent = File.ReadAllText(dialog.FileName);
|
||
}
|
||
else
|
||
{
|
||
return;
|
||
}
|
||
Document.InvokeGroup(
|
||
tg =>
|
||
{
|
||
Document.Invoke(
|
||
ts =>
|
||
{
|
||
//var contents = IOAssists.GetMvdLiteContent(major);
|
||
var data = MvdLiteAssist.Parse(fileContent);
|
||
foreach (var item in elements)
|
||
{
|
||
var sign = item.LookupParameter("深圳构件标识");
|
||
if (sign == null)
|
||
{
|
||
sb.AppendLine($"构件 {item.Id} 构件名 {item.Name} 没有找到标识参数,请检查。");
|
||
continue;
|
||
}
|
||
if (sign != null)
|
||
{
|
||
var value = sign.GetValue()?.ToString();
|
||
|
||
var paramsToAdd = MvdLiteAssist.GetConstraintsByLabel(data, value);
|
||
|
||
SharedParameterAssists.AddArchiParameters(item, paramsToAdd, sharedParameters);
|
||
}
|
||
}
|
||
});
|
||
}, "添加建筑工程参数");
|
||
if (sb.Length > 0)
|
||
{
|
||
TaskDialog.Show("提示", sb.ToString());
|
||
}
|
||
else
|
||
{
|
||
TaskDialog.Show("提示", "所有构件参数添加成功。");
|
||
}
|
||
}
|
||
}
|
||
} |