日常更新
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Architecture;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Windows;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
@@ -24,6 +29,28 @@ namespace Szmedi.Test
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
//UiApplication.Application.DocumentOpening+= (s, e) =>
|
||||
//{
|
||||
// MessageBox.Show("DocumentOpening");
|
||||
//};
|
||||
//UiApplication.Application.FamilyLoadingIntoDocument += (s, e) =>
|
||||
//{
|
||||
// MessageBox.Show("FamilyLoadingIntoDocument");
|
||||
//};
|
||||
//UiApplication.Application.FamilyLoadedIntoDocument += (s, e) =>
|
||||
//{
|
||||
// MessageBox.Show("FamilyLoadedIntoDocument");
|
||||
//};
|
||||
//var ptr = ComponentManager.ApplicationWindow;
|
||||
|
||||
var win = GetWindowFromHwnd(Process.GetCurrentProcess().MainWindowHandle);
|
||||
win?.Drop += (s, e) =>
|
||||
{
|
||||
MessageBox.Show("Drop");
|
||||
};
|
||||
//UIApplication.DoDragDrop(, new DropHandler());
|
||||
|
||||
return;
|
||||
|
||||
#if false
|
||||
var refer = UiDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
|
||||
@@ -64,7 +91,45 @@ namespace Szmedi.Test
|
||||
|
||||
//LogAssists.WriteTxtFile("内建类别", sb.ToString());
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过窗口句柄安全地获取WPF窗口对象
|
||||
/// </summary>
|
||||
/// <param name="hwnd">窗口句柄</param>
|
||||
/// <returns>对应的WPF窗口对象,如果找不到则返回null</returns>
|
||||
public static Window GetWindowFromHwnd(IntPtr hwnd)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 从句柄获取HwndSource
|
||||
var hwndSource = HwndSource.FromHwnd(hwnd);
|
||||
if (hwndSource == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查RootVisual是否为Window类型
|
||||
if (hwndSource.RootVisual is DependencyObject rootVisual)
|
||||
{
|
||||
// 通过可视化树向上查找Window
|
||||
DependencyObject current = rootVisual;
|
||||
while (current != null)
|
||||
{
|
||||
if (current is Window window)
|
||||
{
|
||||
return window;
|
||||
}
|
||||
current = VisualTreeHelper.GetParent(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 可以在此记录异常或进行其他处理
|
||||
Console.WriteLine($"获取窗口失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private static void MoveElement(Element item, XYZ vector)
|
||||
{
|
||||
if (item.Pinned || !item.IsValidObject || item == null)
|
||||
@@ -150,7 +215,7 @@ namespace Szmedi.Test
|
||||
case FamilyPlacementType.CurveDrivenStructural:
|
||||
{
|
||||
//instance.Location.Move(vector);
|
||||
var loc = instance.GetLocCurve().CreateTransformed(Transform.CreateTranslation(vector));
|
||||
var loc = instance.GetLocCurve().CreateTransformed(Autodesk.Revit.DB.Transform.CreateTranslation(vector));
|
||||
//var newLoc =
|
||||
doc.Create.NewFamilyInstance(loc, instance.Symbol, baseLevel, StructuralType.Beam);
|
||||
doc.Delete(instance.Id);
|
||||
@@ -327,4 +392,17 @@ namespace Szmedi.Test
|
||||
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "修改的元素.txt"), sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public class DropHandler : IControllableDropHandler
|
||||
{
|
||||
public bool CanExecute(UIDocument document, object data, ElementId dropViewId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Execute(UIDocument document, object data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,6 +187,30 @@ namespace Szmedi.Test
|
||||
// {
|
||||
// Document.FamilyManager.ReplaceParameter(parameter, "测试", BuiltInParameterGroup.PG_TEXT, true);
|
||||
// });
|
||||
var docs = Application.Documents;
|
||||
if (docs.Size != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var doc1 = docs.OfType<Document>().First();
|
||||
var doc2 = docs.OfType<Document>().Last();
|
||||
var elements1 = doc1.OfCollector().WhereElementIsNotElementType().Where(e => e.Category?.CategoryType == CategoryType.Model && e.get_BoundingBox(null) != null);
|
||||
var elements2 = doc2.OfCollector().WhereElementIsNotElementType().Where(e => e.Category?.CategoryType == CategoryType.Model && e.get_BoundingBox(null) != null);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (var e1 in elements1)
|
||||
{
|
||||
foreach (var e2 in elements2)
|
||||
{
|
||||
if (e1.Id.IntegerValue == e2.Id.IntegerValue)
|
||||
{
|
||||
stringBuilder.Append($"重复图元:{e1.Id};");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show(stringBuilder.ToString());
|
||||
return;
|
||||
var doc = Document;
|
||||
if (doc.IsFamilyDocument)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user