功能更新
This commit is contained in:
@@ -5,9 +5,6 @@ using ShrlAlgoToolkit.RevitAddins.FamMaster;
|
||||
using ShrlAlgoToolkit.RevitAddins.ModelManager;
|
||||
using ShrlAlgoToolkit.RevitAddins.Properties;
|
||||
using ShrlAlgoToolkit.RevitAddins.RvCivil;
|
||||
using ShrlAlgoToolkit.RevitAddins.RvCommon;
|
||||
using ShrlAlgoToolkit.RevitAddins.RvMEP;
|
||||
using ShrlAlgoToolkit.RevitAddins.RvView;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Entry;
|
||||
|
||||
|
||||
66
ShrlAlgoToolkit.RevitAddins/Mep/MappingSystemCmd.cs
Normal file
66
ShrlAlgoToolkit.RevitAddins/Mep/MappingSystemCmd.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Linq;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Mechanical;
|
||||
using Autodesk.Revit.DB.Plumbing;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
namespace Szmedi.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Revit执行命令
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class MappingSystemCmd : IExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
//程序UI界面
|
||||
UIApplication uiapp = commandData.Application;
|
||||
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
|
||||
UIDocument uidoc = uiapp.ActiveUIDocument;
|
||||
//程序
|
||||
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
|
||||
//获取位置和场地 视图(多个视图)管理 获取元素(Revit 项目里的全部元素)
|
||||
Document doc = uidoc.Document;
|
||||
//获取所有打开文档
|
||||
DocumentSet docset = uiapp.Application.Documents;
|
||||
//当前视图
|
||||
View view = doc.ActiveView;
|
||||
var systems=new FilteredElementCollector(doc)
|
||||
.OfClass(typeof(MEPSystem))
|
||||
.WhereElementIsNotElementType().Cast<MEPSystem>().ToList();
|
||||
using (Transaction tx = new Transaction(doc, "Mapping System Names"))
|
||||
{
|
||||
tx.Start();
|
||||
foreach (var sys in systems)
|
||||
{
|
||||
var typeId = sys.GetTypeId();
|
||||
var type = doc.GetElement(typeId) as MEPSystemType;
|
||||
if (sys is MechanicalSystem mechanicalSystem)
|
||||
{
|
||||
var elementSet = mechanicalSystem.DuctNetwork;
|
||||
foreach (Element elem in elementSet)
|
||||
{
|
||||
elem.LookupParameter("三级系统名称")?.Set(type.Name);
|
||||
}
|
||||
}
|
||||
if (sys is PipingSystem pipingSystem)
|
||||
{
|
||||
var elementSet = pipingSystem.PipingNetwork;
|
||||
foreach (Element elem in elementSet)
|
||||
{
|
||||
elem.LookupParameter("三级系统名称")?.Set(type.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
tx.Commit();
|
||||
}
|
||||
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.DirectContext3D;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins.Common.Assists;
|
||||
using ShrlAlgoToolkit.RevitAddins.Standardizer;
|
||||
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Standardizer
|
||||
{
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class WriteParametersCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
//System.Windows.MessageBox.Show(
|
||||
// "若当前视图不是三维且所有元素可见则不会修改参数值",
|
||||
// "注意",
|
||||
// System.Windows.MessageBoxButton.OK,
|
||||
// System.Windows.MessageBoxImage.Information
|
||||
//);
|
||||
//WriteParametersWin win = WpfSingletonHelper<WriteParametersWin>.GetInstance(out bool isNewCreate);
|
||||
//if (isNewCreate)
|
||||
//{
|
||||
// win.DataContext = new WriteParametersViewModel(UiDocument);
|
||||
// win.ShowAhead();
|
||||
//}
|
||||
//win.Activate();
|
||||
WinDialogAssist.ShowOrActivate<WriteParametersView, WriteParametersViewModel>(UiDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<ui:MelWindow
|
||||
x:Class="ShrlAlgoToolkit.RevitAddins.Standardizer.WriteParametersView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:ShrlAlgoToolkit.RevitAddins.Standardizer"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="https://github.com/ShrlAlgo/Melskin"
|
||||
Title="实例参数编辑"
|
||||
Width="500"
|
||||
Height="420"
|
||||
d:DataContext="{d:DesignInstance Type=local:WriteParametersViewModel}"
|
||||
mc:Ignorable="d">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary Source="pack://application:,,,/ShrlAlgoToolkit.RevitAddins;component/WPFUI.xaml" />
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<DataGrid
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
d:ItemsSource="{d:SampleData}"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False"
|
||||
ItemsSource="{Binding Items}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding Name}"
|
||||
Header="参数名"
|
||||
IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Value, UpdateSourceTrigger=PropertyChanged}" Header="参数值" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<UniformGrid
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Center"
|
||||
Rows="1">
|
||||
<CheckBox
|
||||
MinWidth="5"
|
||||
Margin="5"
|
||||
HorizontalAlignment="Center"
|
||||
Content="仅选中"
|
||||
IsChecked="{Binding IsSelectedItems}"
|
||||
ToolTip="选中元素修改,否则全部可见(临时隐藏也算不可见)元素修改" />
|
||||
<CheckBox
|
||||
MinWidth="5"
|
||||
Margin="5"
|
||||
HorizontalAlignment="Center"
|
||||
Content="覆盖现值"
|
||||
IsChecked="{Binding IsOverride}"
|
||||
ToolTip="已有值会被表中填写值覆盖" />
|
||||
<ListBox
|
||||
Margin="5"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="SelectionChanged">
|
||||
<b:InvokeCommandAction Command="{Binding InitCommand}" CommandParameter="{Binding SelectedIndex, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}" />
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
<ListBoxItem Content="土建" ToolTip="加载默认土建填写参数" />
|
||||
<ListBoxItem Content="机电" ToolTip="加载默认机电填写参数" />
|
||||
</ListBox>
|
||||
</UniformGrid>
|
||||
<UniformGrid
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Rows="1">
|
||||
<TextBox
|
||||
Margin="5"
|
||||
ui:InputAssist.PlaceholderText="Excel文件路径"
|
||||
Text="{Binding ExcelPath, UpdateSourceTrigger=PropertyChanged}"
|
||||
ToolTip="输入路径回车读取文件">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Return" Command="{Binding OpenExcelCommand}" />
|
||||
</TextBox.InputBindings>
|
||||
<!--<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="LostFocus">
|
||||
<b:InvokeCommandAction Command="{Binding OpenExcelCommand}" CommandParameter="{Binding Text, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TextBox}}" />
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>-->
|
||||
</TextBox>
|
||||
<!--<TextBox md:HintAssist.Hint="忽略属性" Text="{Binding ExcelPath, UpdateSourceTrigger=PropertyChanged}" ToolTip="输入路径回车读取文件">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Return" Command="{Binding OpenExcelCommand}" />
|
||||
</TextBox.InputBindings>
|
||||
</TextBox>-->
|
||||
<Button
|
||||
Margin="5"
|
||||
Command="{Binding BrowserExcelFileCommand}"
|
||||
Content="打开Excel文件" />
|
||||
<Button
|
||||
Margin="5"
|
||||
Command="{Binding GetParamsCommand}"
|
||||
Content="从构件提取参数" />
|
||||
</UniformGrid>
|
||||
<UniformGrid
|
||||
Grid.Row="3"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Center"
|
||||
Rows="1">
|
||||
<Button
|
||||
Margin="5"
|
||||
Command="{Binding ExportExcelCommand}"
|
||||
Content="导出Excel文件" />
|
||||
<Button
|
||||
Margin="5"
|
||||
HorizontalAlignment="Center"
|
||||
Command="{Binding WriteParamsCommand}"
|
||||
Content="填写属性值"
|
||||
ToolTip="深圳轨道交通标准的属性未填值会默认为“/”并且会跳过修改“ID-100-编号”" />
|
||||
</UniformGrid>
|
||||
</Grid>
|
||||
</ui:MelWindow>
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Standardizer
|
||||
{
|
||||
/// <summary>
|
||||
/// WriteParametersWin.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class WriteParametersView
|
||||
{
|
||||
public WriteParametersView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
using MiniExcelLibs.Attributes;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External.Handlers;
|
||||
|
||||
using ShrlAlgoToolkit.RevitAddins;
|
||||
using ShrlAlgoToolkit.RevitAddins.Common.Assists;
|
||||
using ShrlAlgoToolkit.RevitAddins.Common.Extensions;
|
||||
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Standardizer;
|
||||
|
||||
public partial class WriteParametersViewModel : ObservableObject
|
||||
{
|
||||
public WriteParametersViewModel(UIDocument uIDocument)
|
||||
{
|
||||
this.uiDocument = uIDocument;
|
||||
}
|
||||
|
||||
private readonly ActionEventHandler handler = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isSelectedItems;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isOverride;
|
||||
|
||||
//record class ParameterModel(string Name, object Value);
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ExportExcelCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(WriteParamsCommand))]
|
||||
private List<ParameterModel> items;
|
||||
|
||||
[ObservableProperty]
|
||||
private string excelPath;
|
||||
private readonly UIDocument uiDocument;
|
||||
private bool HasItems => Items?.Any() == true;
|
||||
|
||||
[RelayCommand]
|
||||
private void GetParams()
|
||||
{
|
||||
Items = null;
|
||||
List<ParameterModel> models = [];
|
||||
Document doc = uiDocument.Document;
|
||||
try
|
||||
{
|
||||
Reference reference = uiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "请选择提取参数的元素");
|
||||
Element elem = doc.GetElement(reference);
|
||||
foreach (Parameter param in elem.Parameters)
|
||||
{
|
||||
if (!param.HasValue || string.IsNullOrEmpty(param.AsString()))
|
||||
{
|
||||
models.Add(new ParameterModel() { Name = param.Definition.Name });
|
||||
}
|
||||
}
|
||||
|
||||
Items = models.OrderBy(m => m.Name).ToList();
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenExcel()
|
||||
{
|
||||
if (ExcelPath.StartsWith("\""))
|
||||
{
|
||||
ExcelPath = ExcelPath.TrimStart('\"');
|
||||
}
|
||||
if (ExcelPath.EndsWith("\""))
|
||||
{
|
||||
ExcelPath = ExcelPath.TrimEnd('\"');
|
||||
}
|
||||
if (File.Exists(ExcelPath))
|
||||
{
|
||||
FileInfo file = new(ExcelPath);
|
||||
if (file.Extension != ".xlsx")
|
||||
{
|
||||
MessageBox.Show("请选择xlsx格式的Excel文件");
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadExcel(ExcelPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("文件路径有误");
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(HasItems))]
|
||||
private void ExportExcel()
|
||||
{
|
||||
SaveFileDialog dialog =
|
||||
new()
|
||||
{
|
||||
Filter = "Excel文件(xlsx)|*.xlsx",
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
|
||||
};
|
||||
if (dialog.ShowDialog() != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string excel = dialog.FileName;
|
||||
FileInfo fi = new(excel);
|
||||
Dictionary<string, object> data = new() { { "参数表", Items } };
|
||||
data.SaveAsExcel(excel);
|
||||
MessageBoxResult result = MessageBox.Show("是否打开Excel表?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
Process.Start(excel);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(HasItems))]
|
||||
private void WriteParams()
|
||||
{
|
||||
Document doc = uiDocument.Document;
|
||||
List<Element> elements = IsSelectedItems
|
||||
? uiDocument.Selection.GetElementIds().Select(id => doc.GetElement(id)).ToList()
|
||||
: new FilteredElementCollector(doc, doc.ActiveView.Id)
|
||||
.WhereElementIsNotElementType()
|
||||
.ToElements()
|
||||
.Where(
|
||||
e =>
|
||||
e.CanHaveTypeAssigned()
|
||||
&& e.HasPhases()
|
||||
&& e.get_BoundingBox(doc.ActiveView) != null
|
||||
&& e.Category is { Parent: null, CategoryType: CategoryType.Model }
|
||||
)
|
||||
.ToList();
|
||||
|
||||
StringBuilder sb = new();
|
||||
handler.Raise(_ =>
|
||||
{
|
||||
using (TransactionGroup transG = new(doc, "填写属性值"))
|
||||
{
|
||||
transG.Start();
|
||||
foreach (Element elem in elements)
|
||||
{
|
||||
if (!elem.IsValidObject)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
using Transaction trans = new(doc, "填写属性值");
|
||||
//FailureHandlingOptions options = trans.GetFailureHandlingOptions();
|
||||
//FailuresPreProcessor failuresProcessor = new();
|
||||
//options.SetFailuresPreprocessor(failuresProcessor);
|
||||
//trans.SetFailureHandlingOptions(options);
|
||||
trans.Start();
|
||||
Regex regex = new(@"^\D{2}-\d00");
|
||||
//将“”空值填写“/”
|
||||
foreach (Parameter parameter in elem.Parameters)
|
||||
{
|
||||
//if (parameter.Definition.Name == "ID-100-编号")
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
//不为空时,跳过设置“/”
|
||||
if (!(string.IsNullOrEmpty(parameter.AsString()) && string.IsNullOrEmpty(parameter.AsValueString())))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (regex.IsMatch(parameter.Definition.Name) && !parameter.IsReadOnly)
|
||||
{
|
||||
if (parameter.StorageType is StorageType.Integer or StorageType.Double)
|
||||
{
|
||||
parameter.Set(0);
|
||||
}
|
||||
if (parameter.StorageType == StorageType.String)
|
||||
{
|
||||
parameter.Set("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
doc.Regenerate();
|
||||
//填写表单中的数据
|
||||
foreach (ParameterModel item in Items)
|
||||
{
|
||||
Parameter p1 = elem.GetParameters(item.Name).FirstOrDefault();
|
||||
if (p1 == null)
|
||||
{
|
||||
sb.AppendLine($"构件类别:{elem.Category};构件名:{elem.Name};构件ID:{elem.Id};参数名:{item.Name};异常原因:参数不存在");
|
||||
continue;
|
||||
}
|
||||
//if (p1.Definition.Name == "ID-100-编号")
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
try
|
||||
{
|
||||
if (
|
||||
IsOverride
|
||||
|| (p1.AsString() == "/" || p1.AsValueString() == "/")
|
||||
|| (p1.AsString() == "0" || p1.AsValueString() == "0")
|
||||
) //如果覆盖则填写,否则不操作
|
||||
{
|
||||
if (p1?.IsReadOnly == false)
|
||||
{
|
||||
switch (p1.StorageType)
|
||||
{
|
||||
case StorageType.None:
|
||||
break;
|
||||
case StorageType.Integer:
|
||||
p1.Set(Convert.ToInt16(item.Value));
|
||||
break;
|
||||
case StorageType.Double:
|
||||
p1.Set(Convert.ToDouble(item.Value));
|
||||
break;
|
||||
case StorageType.String:
|
||||
p1.Set(Convert.ToString(item.Value));
|
||||
break;
|
||||
case StorageType.ElementId:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (p1?.IsReadOnly == false)
|
||||
//{
|
||||
// switch (p1.StorageType)
|
||||
// {
|
||||
// case StorageType.None:
|
||||
// break;
|
||||
// case StorageType.Integer:
|
||||
// p1.Set(Convert.ToInt16(item.Value));
|
||||
// break;
|
||||
// case StorageType.Double:
|
||||
// p1.Set(Convert.ToDouble(item.Value));
|
||||
// break;
|
||||
// case StorageType.String:
|
||||
// p1.Set(Convert.ToString(item.Value));
|
||||
// break;
|
||||
// case StorageType.ElementId:
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
sb.AppendLine(
|
||||
$"构件类别:{elem.Category};构件名:{elem.Name};构件ID:{elem.Id};参数名:{p1.Definition.Name};异常原因:{exception.Message}"
|
||||
);
|
||||
}
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
transG.Assimilate();
|
||||
}
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
LogAssist.WriteTextFile( sb.ToString(), "修改异常问题");
|
||||
}
|
||||
MessageBox.Show("修改参数完成!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
});
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void BrowserExcelFile()
|
||||
{
|
||||
OpenFileDialog dialog =
|
||||
new()
|
||||
{
|
||||
CheckFileExists = true,
|
||||
Filter = "Excel文件(*.xlsx)|*.xlsx",
|
||||
Multiselect = false,
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
|
||||
};
|
||||
if (dialog.ShowDialog() != true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//Items?.Clear();
|
||||
ExcelPath = dialog.FileName;
|
||||
ReadExcel(dialog.FileName);
|
||||
}
|
||||
|
||||
private void ReadExcel(string path)
|
||||
{
|
||||
Items= [.. path.ReadExcel<ParameterModel>()];
|
||||
}
|
||||
|
||||
private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
if (!args.Name.Contains("ComponentModel.Annotations"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string assemblyFile = Path.Combine(Variables.DirAssembly, "System.ComponentModel.Annotations.dll");
|
||||
return File.Exists(assemblyFile) ? Assembly.LoadFrom(assemblyFile) : null;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Init(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
Items = GetInitCivilParameterList();
|
||||
}
|
||||
else
|
||||
{
|
||||
Items = index == 1 ? GetInitMEPParameterList() : null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<ParameterModel> GetInitCivilParameterList()
|
||||
{
|
||||
return
|
||||
[
|
||||
new() { Name = "AM-200-模型权属单位", Value = "深圳市地铁集团有限公司" },
|
||||
new() { Name = "AM-200-资产权属单位", Value = "深圳市地铁集团有限公司" },
|
||||
new() { Name = "CM-100-创建单位", Value = "深圳市市政设计研究院有限公司" },
|
||||
new() { Name = "ID-200-BIM对象分类编码执行标准", Value = "《城市轨道交通工程信息模型分类和编码标准》SJG102" },
|
||||
new() { Name = "CM-100-校审单位", Value = "数云科际(深圳)技术有限公司" },
|
||||
new() { Name = "FM-200-产品寿命", Value = "100" },
|
||||
new() { Name = "FM-200-使用年限", Value = "100" },
|
||||
new() { Name = "TC-400-设计使用年限", Value = "100" }
|
||||
];
|
||||
}
|
||||
|
||||
private List<ParameterModel> GetInitMEPParameterList()
|
||||
{
|
||||
return
|
||||
[
|
||||
new() { Name = "AM-200-模型权属单位", Value = "深圳市地铁集团有限公司" },
|
||||
new() { Name = "AM-200-资产权属单位", Value = "深圳市地铁集团有限公司" },
|
||||
new() { Name = "CM-100-创建单位", Value = "深圳市市政设计研究院有限公司" },
|
||||
new() { Name = "CM-100-校审单位", Value = "深圳市市政设计研究院有限公司" },
|
||||
new() { Name = "CM-100-创建人及联系方式", Value = "/" },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public class ParameterModel
|
||||
{
|
||||
[ExcelColumn(Name="参数名")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[ExcelColumn(Name ="参数值")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
@@ -10,11 +10,14 @@ namespace ShrlAlgoToolkit.RevitCore.Assists
|
||||
{
|
||||
public abstract class BaseApplication : IExternalApplication
|
||||
{
|
||||
public UIControlledApplication UiApplication { get; private set; }
|
||||
|
||||
public UIApplication UiApplication { get; private set; }
|
||||
|
||||
public Result OnStartup(UIControlledApplication application)
|
||||
{
|
||||
UiApplication = application;
|
||||
var flag = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod;
|
||||
|
||||
UiApplication = (Autodesk.Revit.UI.UIApplication)application.GetType().InvokeMember("getUIApplication", flag, Type.DefaultBinder, application, null);
|
||||
|
||||
|
||||
// 1. 注册程序集依赖解析事件 (解决第三方库找不到的问题)
|
||||
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
|
||||
|
||||
@@ -114,7 +114,7 @@ public static class ConnectorExtensions
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分支连接
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Architecture;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitCore.Extensions;
|
||||
|
||||
@@ -41,6 +43,251 @@ public static class ElementExtensions
|
||||
ElementTransformUtils.MoveElement(element.Document, element.Id, vector);
|
||||
return element;
|
||||
}
|
||||
public static void MoveElement(this Element item, XYZ vector)
|
||||
{
|
||||
if (item.Pinned || !item.IsValidObject || item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var doc = item.Document;
|
||||
var levels = doc.OfClass<Level>().OfType<Level>().OrderBy(l => l.Elevation).ToList();
|
||||
if (item is FamilyInstance instance)
|
||||
{
|
||||
var baseElev = instance.get_BoundingBox(null).Min.Z + vector.Z;
|
||||
var topElev = instance.get_BoundingBox(null).Max.Z + vector.Z;
|
||||
var baseLevel = GetClosetLevel(levels, baseElev);
|
||||
var topLevel = GetClosetLevel(levels, topElev);
|
||||
|
||||
switch (instance.Symbol.Family.FamilyPlacementType)
|
||||
{
|
||||
//柱
|
||||
case FamilyPlacementType.TwoLevelsBased:
|
||||
{
|
||||
instance.Location.Move(vector);
|
||||
|
||||
instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(baseLevel.Id);
|
||||
instance.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(baseElev - baseLevel.Elevation);
|
||||
|
||||
instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(topLevel.Id);
|
||||
instance.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(topElev - topLevel.Elevation);
|
||||
}
|
||||
break;
|
||||
case FamilyPlacementType.ViewBased:
|
||||
break;
|
||||
case FamilyPlacementType.WorkPlaneBased:
|
||||
{
|
||||
//instance.Location.Move(vector);
|
||||
var param = instance.get_Parameter(BuiltInParameter.INSTANCE_ELEVATION_PARAM);
|
||||
if (param != null && !param.IsReadOnly)
|
||||
{
|
||||
ElementTransformUtils.MoveElement(doc, instance.Id, XYZ.BasisZ * vector.Z);
|
||||
|
||||
//var value = param.AsDouble() + vector.Z;
|
||||
//param.Set(value);
|
||||
}
|
||||
|
||||
doc.Regenerate();
|
||||
|
||||
if (instance.Host == null)
|
||||
{
|
||||
ElementTransformUtils.MoveElement(doc, instance.Id, vector.Flatten());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FamilyPlacementType.OneLevelBased:
|
||||
{
|
||||
ElementTransformUtils.MoveElement(doc, instance.Id, vector);
|
||||
}
|
||||
break;
|
||||
case FamilyPlacementType.OneLevelBasedHosted:
|
||||
{
|
||||
var ins = doc.Create
|
||||
.NewFamilyInstance(
|
||||
instance.GetLocXYZ(),
|
||||
instance.Symbol,
|
||||
instance.Host,
|
||||
baseLevel,
|
||||
StructuralType.NonStructural);
|
||||
ins.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM)
|
||||
.Set(baseElev - baseLevel.Elevation);
|
||||
doc.Delete(instance.Id);
|
||||
}
|
||||
break;
|
||||
case FamilyPlacementType.CurveBased:
|
||||
{
|
||||
instance.Location.Move(vector);
|
||||
//var loc = instance.GetLocCurve().CreateTransformed(Transform.CreateTranslation(vector)) as Line;
|
||||
//doc.Create.NewFamilyInstance(instance.HostFace, loc, instance.Symbol);
|
||||
//doc.Delete(instance.Id);
|
||||
}
|
||||
break;
|
||||
case FamilyPlacementType.CurveBasedDetail:
|
||||
break;
|
||||
//梁
|
||||
case FamilyPlacementType.CurveDrivenStructural:
|
||||
{
|
||||
//instance.Location.Move(vector);
|
||||
var loc = instance.GetCurve().CreateTransformed(Autodesk.Revit.DB.Transform.CreateTranslation(vector));
|
||||
//var newLoc =
|
||||
doc.Create.NewFamilyInstance(loc, instance.Symbol, baseLevel, StructuralType.Beam);
|
||||
doc.Delete(instance.Id);
|
||||
|
||||
//ElementTransformUtils.MoveElement(doc, instance.Id, vector.Flatten());
|
||||
}
|
||||
break;
|
||||
case FamilyPlacementType.Adaptive:
|
||||
break;
|
||||
case FamilyPlacementType.Invalid:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (item is Wall wall)
|
||||
{
|
||||
var flat = vector.Flatten();
|
||||
ElementTransformUtils.MoveElement(doc, wall.Id, flat);
|
||||
doc.Regenerate();
|
||||
SetWallHeight(vector, levels, wall);
|
||||
var elemIds = wall.FindInserts(true, true, true, true);
|
||||
foreach (var id in elemIds)
|
||||
{
|
||||
var elem = doc.GetElement(id);
|
||||
if (elem is Wall nestWall)
|
||||
{
|
||||
SetWallHeight(vector, levels, nestWall);
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveElement(elem, vector);
|
||||
}
|
||||
}
|
||||
//墙饰条
|
||||
var sweeps = doc.OfClass
|
||||
<WallSweep>().OfType<WallSweep>().Where(s => s.GetHostIds().Contains(wall.Id));
|
||||
foreach (var sweep in sweeps)
|
||||
{
|
||||
//ElementTransformUtils.MoveElement(doc, sweep.Id, flat);
|
||||
var boundingBox = sweep.get_BoundingBox(null);
|
||||
var offset = boundingBox.Min.Z + vector.Z;
|
||||
|
||||
var baseLevel = levels.First(l => Math.Abs(l.Elevation - offset) == levels.Min(l => Math.Abs(l.Elevation - offset)));
|
||||
sweep.get_Parameter(BuiltInParameter.WALL_SWEEP_LEVEL_PARAM).Set(baseLevel.Id);
|
||||
sweep.get_Parameter(BuiltInParameter.WALL_SWEEP_OFFSET_PARAM).Set(offset - baseLevel.Elevation);
|
||||
}
|
||||
//依附在墙上的实例
|
||||
var instances = doc.OfClass<FamilyInstance>().OfType<FamilyInstance>().Where(s =>
|
||||
{
|
||||
|
||||
var stackedWallIds = wall.GetStackedWallMemberIds();
|
||||
if (stackedWallIds.Count > 0)
|
||||
{
|
||||
return stackedWallIds.Any(id => s.Host?.Id == id);
|
||||
}
|
||||
return s.Host?.Id == wall.Id;
|
||||
}).ToList();
|
||||
foreach (var ins in instances)
|
||||
{
|
||||
//ins.Location.Move(vector);
|
||||
ElementTransformUtils.MoveElement(doc, ins.Id, vector.Z * XYZ.BasisZ);
|
||||
}
|
||||
|
||||
//ElementTransformUtils.CopyElements(v1, [wall.Id], v2, Transform.Identity, new CopyPasteOptions());
|
||||
//var b = wall.Location.Move(vector);
|
||||
|
||||
//var loc = wall.GetLocCurve();
|
||||
//var c = loc.CreateTransformed(Transform.CreateTranslation(vector));
|
||||
//(wall.Location as LocationCurve).Curve = c; //可以移动,但是偏移量属性没更新
|
||||
}
|
||||
else if (item is Room room)
|
||||
{
|
||||
}
|
||||
else if (item is Stairs stairs)
|
||||
{
|
||||
var flat = vector.Flatten();
|
||||
ElementTransformUtils.MoveElement(doc, item.Id, flat);
|
||||
}
|
||||
else if (item is ModelCurve curve)//房间分割
|
||||
{
|
||||
|
||||
}
|
||||
else if (item is Railing railing)
|
||||
{
|
||||
if (railing.HasHost)
|
||||
{
|
||||
|
||||
}
|
||||
else//连带主体移动
|
||||
{
|
||||
ElementTransformUtils.MoveElement(doc, item.Id, vector);
|
||||
}
|
||||
}
|
||||
//坡道
|
||||
else if (item.Category.ToBuiltInCategory() == BuiltInCategory.OST_Ramps)
|
||||
{
|
||||
var flat = vector.Flatten();
|
||||
ElementTransformUtils.MoveElement(doc, item.Id, flat);
|
||||
}
|
||||
else if (item is TopographySurface surface)
|
||||
{
|
||||
}
|
||||
else if (item is SlabEdge or Fascia or Gutter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//else if (item is CeilingAndFloor ceilingAndFloor)
|
||||
//{
|
||||
// ElementTransformUtils.MoveElement(doc, ceilingAndFloor.Id, vector);
|
||||
//}
|
||||
else if (item is Opening opening)
|
||||
{
|
||||
if (opening.Host is Wall)
|
||||
{
|
||||
ElementTransformUtils.MoveElement(doc, opening.Id, vector.Z * XYZ.BasisZ);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementTransformUtils.MoveElement(doc, item.Id, vector);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置墙高度
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
/// <param name="levels"></param>
|
||||
/// <param name="wall"></param>
|
||||
private static void SetWallHeight(XYZ vector, List<Level> levels, Wall wall)
|
||||
{
|
||||
var boundingBox = wall.get_BoundingBox(null);
|
||||
//底部实际高度
|
||||
var bottomElev = boundingBox.Min.Z + vector.Z;
|
||||
var topElev = boundingBox.Max.Z + vector.Z;
|
||||
//查找距离底部偏移最近的Level
|
||||
var baseLevel = GetClosetLevel(levels, bottomElev);
|
||||
wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Set(baseLevel.Id);
|
||||
wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(bottomElev - baseLevel.Elevation);
|
||||
//是否有顶部约束
|
||||
var topContraint = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();
|
||||
if (topContraint != ElementId.InvalidElementId)
|
||||
{
|
||||
var topLevel = GetClosetLevel(levels, topElev);
|
||||
|
||||
wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(topLevel.Id);
|
||||
wall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).Set(topElev - topLevel.Elevation);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取距离最近的标高
|
||||
/// </summary>
|
||||
/// <param name="levels"></param>
|
||||
/// <param name="elev">高度</param>
|
||||
/// <returns></returns>
|
||||
private static Level GetClosetLevel(List<Level> levels, double elev)
|
||||
{
|
||||
return levels.First(l => Math.Abs(l.Elevation - elev) == levels.Min(l => Math.Abs(l.Elevation - elev)));
|
||||
}
|
||||
/// <summary>
|
||||
/// 旋转元素
|
||||
/// </summary>
|
||||
|
||||
@@ -43,7 +43,44 @@ internal static class FamilyInstanceExtensions
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否已连接
|
||||
/// </summary>
|
||||
/// <param name="ins"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsConnectToSystem(this FamilyInstance ins)
|
||||
{
|
||||
bool hasConnectToSystem = false;
|
||||
if (ins.Category.CategoryType != CategoryType.Model)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (ins.get_BoundingBox(null) != null &&
|
||||
ins.MEPModel?.ConnectorManager != null)
|
||||
{
|
||||
var cons = ins.GetConnectors(false);
|
||||
|
||||
foreach (Connector con in cons)
|
||||
{
|
||||
if (con.Domain != Domain.DomainElectrical && con.Domain != Domain.DomainUndefined)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (con.IsConnected)
|
||||
{
|
||||
hasConnectToSystem = true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasConnectToSystem;
|
||||
|
||||
}
|
||||
public static void Rotate(this Autodesk.Revit.DB.FamilyInstance familyInstance, double radian)
|
||||
{
|
||||
var axis = Line.CreateBound(familyInstance.GetTransform().Origin, familyInstance.GetTransform().Origin + XYZ.BasisZ);
|
||||
|
||||
Reference in New Issue
Block a user