大量更新

This commit is contained in:
GG Z
2025-12-23 21:37:02 +08:00
parent 3fc465959b
commit b611efeed9
105 changed files with 5814 additions and 371 deletions

16
WebUITest/App.xaml Normal file
View File

@@ -0,0 +1,16 @@
<Application
x:Class="WebUITest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<!--<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ShrlAlgo.Toolkit.Wpf;component/Themes/Colors.xaml"/>
<ResourceDictionary Source="/ShrlAlgo.Toolkit.Wpf;component/Themes/Controls.xaml"/>
<ResourceDictionary Source="/ShrlAlgo.Toolkit.Wpf;component/Themes/Generic.xaml"/>
<ResourceDictionary Source="/ShrlAlgo.Toolkit.Wpf;component/Controls/MaterialWindow.xaml"/>
</ResourceDictionary.MergedDictionaries>-->
</ResourceDictionary>
</Application.Resources>
</Application>

17
WebUITest/App.xaml.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace WebUITest
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}

28
WebUITest/Command.cs Normal file
View File

@@ -0,0 +1,28 @@
using Autodesk.Revit.UI;
using System;
namespace WebUITest
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
try
{
var uiApp = commandData.Application;
var uiDoc = uiApp.ActiveUIDocument;
var wnd = new WebUIWindow(uiDoc);
wnd.Owner = System.Windows.Application.Current?.MainWindow;
wnd.ShowDialog();
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
}
}

44
WebUITest/Html/index.html Normal file
View File

@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>AntD + React</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/antd@4.21.0/dist/antd.min.css" />
<!--<script src="https://cdn.jsdelivr.net/npm/react@17/umd/react.development.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.development.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/antd@4.21.0/dist/antd.min.js"></script>
</head>
<body>
<div id="root"></div>
<script>
const { Button, Input } = antd;
const App = () => {
const [value, setValue] = React.useState("");
return React.createElement("div", { style: { padding: 20 } }, [
React.createElement(Input, {
key: "input",
value,
placeholder: "输入墙标记",
onChange: e => setValue(e.target.value),
style: { marginBottom: 10 }
}),
React.createElement(Button, {
key: "btn",
type: "primary",
onClick: () => {
if (value) {
window.chrome?.webview?.postMessage({ newTag: value });
} else {
alert("请输入内容");
}
}
}, "提交")
]);
};
ReactDOM.render(React.createElement(App), document.getElementById("root"));
</script>
</body>
</html>

20
WebUITest/MainWindow.xaml Normal file
View File

@@ -0,0 +1,20 @@
<Window
x:Class="WebUITest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WebUITest"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid>
<!--<Grid.Background>
<ImageBrush ImageSource="/WebUITest;component/background.avif" Stretch="UniformToFill"/>
</Grid.Background>-->
</Grid>
</Window>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WebUITest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("WebUITest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WebUITest")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("be44de16-ea42-424a-b16f-07c46e157618")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<OutputType>WinExe</OutputType>
<PlatformTarget>x64</PlatformTarget>
<!--<OutputType>Library</OutputType>-->
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>True</UseWPF>
</PropertyGroup>
<ItemGroup>
<None Remove="background.avif" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Html\index.html" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3179.45" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPI" Version="2020.*" PrivateAssets="All" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPIUI" Version="2020.*" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
<Resource Include="background.avif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<Compile Update="WebUIWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<Window x:Class="WebUITest.WebUIWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
Title="批量墙标记修改" Height="600" Width="800">
<Grid>
<wv2:WebView2 x:Name="WebView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
</Window>

View File

@@ -0,0 +1,142 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Shell;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Microsoft.Web.WebView2.Core;
namespace WebUITest
{
public partial class WebUIWindow : Window
{
private UIDocument _uiDoc;
public WebUIWindow(UIDocument uiDoc)
{
InitializeComponent();
_uiDoc = uiDoc;
InitializeWebView();
}
private async void InitializeWebView()
{
string userDataFolder = Path.Combine(Path.GetTempPath(), "WebUI_Revit_UserData");
var env = await CoreWebView2Environment.CreateAsync(null, userDataFolder);
await WebView.EnsureCoreWebView2Async(env);
WebView.CoreWebView2.WebMessageReceived += WebMessageReceived;
// 获取嵌入的 HTML 内容
string htmlContent = GetEmbeddedResource("WebUI_WallBatchTag.Html.index.html");
if (string.IsNullOrEmpty(htmlContent))
{
MessageBox.Show("HTML 内容加载失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// 加载嵌入的 CSS 和 JS 文件
//var cssContent = GetEmbeddedResource("WebUI_WallBatchTag.Resources.antd.min.css");
//var jsContent = GetEmbeddedResource("WebUI_WallBatchTag.Resources.antd.min.js");
//// 将 HTML 写入临时文件并加载
//string tempPath = Path.Combine(Path.GetTempPath(), "index.html");
//File.WriteAllText(tempPath, htmlContent);
//WebView.Source = new Uri(tempPath);
// 在 HTML 内容中注入 CSS 和 JS
//htmlContent = InjectCssAndJs(htmlContent, cssContent, jsContent);
// 尝试加载 HTML
try
{
WebView.NavigateToString(htmlContent);
}
catch (Exception ex)
{
MessageBox.Show($"HTML 加载失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
//private string InjectCssAndJs(string htmlContent, string cssContent, string jsContent)
//{
// // 在 HTML 内容中找到 <head> 标签,插入 CSS
// var cssInjected = $"<style>{cssContent}</style>";
// var jsInjected = $"<script>{jsContent}</script>";
// // 确保注入 CSS
// int headEndIndex = htmlContent.IndexOf("</head>");
// if (headEndIndex >= 0)
// {
// htmlContent = htmlContent.Insert(headEndIndex, cssInjected);
// }
// // 确保注入 JS通常放在 </body> 前
// int bodyEndIndex = htmlContent.IndexOf("</body>");
// if (bodyEndIndex >= 0)
// {
// htmlContent = htmlContent.Insert(bodyEndIndex, jsInjected);
// }
// return htmlContent;
//}
private string InjectCssAndJs(string htmlContent, string cssContent, string jsContent)
{
// 注入 CSS 到 <head>
var cssTag = $"<style>{cssContent}</style>";
htmlContent = htmlContent.Replace("</head>", $"{cssTag}</head>");
// 注入 JS 到 <body> 或 <head>
var jsTag = $"<script>{jsContent}</script>";
htmlContent = htmlContent.Replace("</body>", $"{jsTag}</body>");
return htmlContent;
}
private string GetEmbeddedResource(string resourceName)
{
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
private void WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
string json = e.WebMessageAsJson;
dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
string newTag = data.newTag;
ApplyTagToWalls(newTag);
}
private void ApplyTagToWalls(string tagValue)
{
// 执行墙标记批量修改操作
Document doc = _uiDoc.Document;
var walls = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Walls)
.WhereElementIsNotElementType()
.Cast<Wall>()
.ToList();
using (Transaction tx = new Transaction(doc, "批量修改墙标记"))
{
tx.Start();
foreach (var wall in walls)
{
Parameter p = wall.get_Parameter(BuiltInParameter.ALL_MODEL_MARK);
if (p != null && !p.IsReadOnly)
p.Set(tagValue);
}
tx.Commit();
}
MessageBox.Show($"共修改 {walls.Count} 面墙的标记为 '{tagValue}'。", "完成", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
}

BIN
WebUITest/background.avif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB