日常更新
This commit is contained in:
66
Szmedi.Test/MappingSystemCmd.cs
Normal file
66
Szmedi.Test/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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user