日常更新

This commit is contained in:
ShrlAlgo
2026-01-16 17:07:43 +08:00
parent b611efeed9
commit 3650f8550e
74 changed files with 2040 additions and 2151 deletions

View File

@@ -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();
}
}
}