多项功能优化
This commit is contained in:
233
RvAddinTest/ModifySystemTypeCmd.cs
Normal file
233
RvAddinTest/ModifySystemTypeCmd.cs
Normal file
@@ -0,0 +1,233 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Plumbing;
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
using Sai.Toolkit.Revit.Assist;
|
||||
|
||||
namespace RvAddinTest;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
internal class ModifySystemTypeCmd : IExternalCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取标高
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ElementId GetLevelId(Element model)
|
||||
{
|
||||
// 定义需要检查的参数列表
|
||||
var parametersToCheck = new BuiltInParameter[]
|
||||
{
|
||||
BuiltInParameter.WALL_BASE_CONSTRAINT, // 墙
|
||||
BuiltInParameter.SCHEDULE_BASE_LEVEL_PARAM, // 柱子标高
|
||||
BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM, // 梁标高
|
||||
BuiltInParameter.STAIRS_BASE_LEVEL_PARAM, // 楼梯标高
|
||||
BuiltInParameter.INSTANCE_ELEVATION_PARAM, // 族实例明细表标高
|
||||
BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM,//屋顶
|
||||
BuiltInParameter.INSTANCE_SCHEDULE_ONLY_LEVEL_PARAM,// 族实例明细表标高
|
||||
BuiltInParameter.RBS_START_LEVEL_PARAM// 管线标高
|
||||
};
|
||||
// 依次检查每个参数
|
||||
foreach (var param in parametersToCheck)
|
||||
{
|
||||
var baseLevelId = model.get_Parameter(param)?.AsElementId();
|
||||
if (baseLevelId != ElementId.InvalidElementId && baseLevelId != null)
|
||||
{
|
||||
return baseLevelId;
|
||||
}
|
||||
}
|
||||
|
||||
//最后检查楼板或族基准标高
|
||||
return model.LevelId;
|
||||
}
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
//程序UI界面
|
||||
var uiapp = commandData.Application;
|
||||
//获取元素(选择) 显示元素 视图(活动视图)管理(对象)
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
//程序
|
||||
var app = uiapp.Application;
|
||||
//获取位置和场地 视图(多个视图)管理 获取元素(Revit 项目里的全部元素)
|
||||
var doc = uidoc.Document;
|
||||
//获取所有打开文档
|
||||
var docset = uiapp.Application.Documents;
|
||||
//当前视图
|
||||
var view = doc.ActiveView;
|
||||
|
||||
//var views = doc.OfClass<View>().Cast<View>().Where(v => !v.IsTemplate);
|
||||
//foreach (var v in views)
|
||||
//{
|
||||
// if (v.GetParameter("子视图分类")?.AsString() == "01 平面")
|
||||
// {
|
||||
// MessageBox.Show(v.Id.ToString());
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
#region RegionName
|
||||
//var ins = doc.OfClass<FamilyInstance>().Cast<FamilyInstance>();
|
||||
//var pipes = doc.OfClass<Pipe>().Cast<Pipe>();
|
||||
|
||||
//using (var trans = new Transaction(doc, nameof(ModifySystemTypeCmd)))
|
||||
//{
|
||||
// trans.Start();
|
||||
// var level = doc.OfClass<Level>().Cast<Level>().FirstOrDefault(l => l.Name == "站厅层");
|
||||
// foreach (var pipe in pipes)
|
||||
// {
|
||||
// if (pipe.ReferenceLevel.Name == "站厅层.")
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// pipe.ReferenceLevel = doc.GetElement(level.Id) as Level;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageBox.Show(pipe.Name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// foreach (var instance in ins)
|
||||
// {
|
||||
|
||||
// var e = doc.GetElement(instance.LevelId);
|
||||
// if (e != null && e.Name == "站厅层.")
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// instance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)?.Set(level.Id);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageBox.Show(e.Name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// trans.Commit();
|
||||
//}
|
||||
#endregion
|
||||
|
||||
//var templates = doc.OfClass<View>().Cast<View>().Where(v => v.IsTemplate);
|
||||
//foreach (var template in templates)
|
||||
//{
|
||||
// var filters = template.GetFilters();
|
||||
// foreach (var id in filters)
|
||||
// {
|
||||
// var filterElement = doc.GetElement(id);
|
||||
// if (filterElement is ParameterFilterElement filter)
|
||||
// {
|
||||
// if (filter.Name.Contains("生产生活给水系统"))
|
||||
// {
|
||||
// var ogs = new OverrideGraphicSettings();
|
||||
// ogs.SetProjectionLineColor(new Color(0, 255, 0));
|
||||
// ogs.SetProjectionLineColor(new Color(0, 255, 0));
|
||||
// ogs.SetProjectionLineColor(new Color(0, 255, 0));
|
||||
// ogs.SetProjectionLineColor(new Color(0, 255, 0));
|
||||
// template.SetFilterOverrides(id, ogs);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//var maps = doc.ParameterBindings;
|
||||
//var li = maps.ForwardIterator();
|
||||
//try
|
||||
//{
|
||||
// using (var trans = new Transaction(doc, "修改"))
|
||||
// {
|
||||
// trans.Start();
|
||||
// var pipeCate = Category.GetCategory(doc, BuiltInCategory.OST_PipeCurves);
|
||||
// var cabtrayCate = Category.GetCategory(doc, BuiltInCategory.OST_CableTray);
|
||||
// var conduitCate = Category.GetCategory(doc, BuiltInCategory.OST_Conduit);
|
||||
|
||||
// while (li.MoveNext())
|
||||
// {
|
||||
// var k = li.Key;
|
||||
// if (Regex.IsMatch(k.Name, @"^[A-Z][A-Z](-)\d(00-)"))
|
||||
// {
|
||||
// if (li.Current is InstanceBinding binding && binding.Categories.Contains(pipeCate))
|
||||
// {
|
||||
// //binding.Categories.Insert(cabtrayCate);
|
||||
// //binding.Categories.Insert(conduitCate);
|
||||
// //binding.Categories.Erase(pipeCate);
|
||||
// doc.ParameterBindings.ReInsert(k, binding, BuiltInParameterGroup.PG_ADSK_MODEL_PROPERTIES);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// trans.Commit();
|
||||
// }
|
||||
//}
|
||||
//catch (Exception)
|
||||
//{
|
||||
|
||||
// throw;
|
||||
//}
|
||||
|
||||
#region RegionName
|
||||
//var templates = doc.OfClass<LinePatternElement>()
|
||||
// .Cast<LinePatternElement>()
|
||||
// .Where(e => e.Name.StartsWith("IMPORT"))
|
||||
// .Select(e => e.Id).ToList();
|
||||
//using (var trans = new Transaction(doc, nameof(ModifySystemTypeCmd)))
|
||||
//{
|
||||
// trans.Start();
|
||||
// doc.Delete(templates);
|
||||
// //foreach (var id in uidoc.Selection.GetElementIds())
|
||||
// //{
|
||||
// // var elem = doc.GetElement(id);
|
||||
// // elem.ChangeTypeId(systemType.Id);
|
||||
// //}
|
||||
// trans.Commit();
|
||||
//}
|
||||
#endregion
|
||||
try
|
||||
{
|
||||
|
||||
//var r = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
|
||||
var ids = uidoc.Selection.GetElementIds();
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var elem = doc.GetElement(id);
|
||||
if (elem is not Pipe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var systemType = new FilteredElementCollector(doc).OfClass(typeof(PipingSystemType))
|
||||
.FirstOrDefault(p => p.Name == "气体灭火管网系统") as PipingSystemType;
|
||||
using (var trans = new Transaction(doc, nameof(ModifySystemTypeCmd)))
|
||||
{
|
||||
|
||||
trans.Start();
|
||||
elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM).Set(systemType.Id);
|
||||
|
||||
//foreach (var id in uidoc.Selection.GetElementIds())
|
||||
//{
|
||||
// var elem = doc.GetElement(id);
|
||||
// elem.ChangeTypeId(systemType.Id);
|
||||
//}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user