Skip to content

Commit 5e21aed

Browse files
authored
Merge pull request #10 from revit-mcp/feature/split-execution
Feature/split execution
2 parents eca35f2 + 550226e commit 5e21aed

File tree

78 files changed

+2684
-2899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+2684
-2899
lines changed

revit-mcp-plugin/Commands/Access/GetAvailableFamilyTypesCommand.cs renamed to SampleCommandSet/Commands/Access/GetAvailableFamilyTypesCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Autodesk.Revit.UI;
22
using Newtonsoft.Json.Linq;
3-
using revit_mcp_plugin.Commands.Base;
3+
using revit_mcp_plugin.API.Base;
44
using System;
55
using System.Collections.Generic;
66

7-
namespace revit_mcp_plugin.Commands.Access
7+
namespace SampleCommandSet.Access
88
{
99
/// <summary>
1010
/// 获取当前项目中可用族类型的命令

revit-mcp-plugin/Commands/Access/GetAvailableFamilyTypesEventHandler.cs renamed to SampleCommandSet/Commands/Access/GetAvailableFamilyTypesEventHandler.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using Autodesk.Revit.DB;
22
using Autodesk.Revit.UI;
3-
using revit_mcp_plugin.Commands.Interfaces;
3+
using revit_mcp_plugin.API.Interfaces;
4+
using SampleCommandSet.Extensions;
5+
using SampleCommandSet.Models;
46
using System;
57
using System.Collections.Generic;
68
using System.Linq;
79
using System.Threading;
810

9-
namespace revit_mcp_plugin.Commands.Access
11+
namespace SampleCommandSet.Access
1012
{
1113
public class GetAvailableFamilyTypesEventHandler : IExternalEventHandler, IWaitableExternalEventHandler
1214
{
@@ -68,7 +70,7 @@ public void Execute(UIApplication app)
6870
{
6971
filteredElements = filteredElements.Where(et =>
7072
{
71-
var categoryId = et.Category?.Id.Value;
73+
var categoryId = et.Category?.Id.GetIdValue();
7274
return categoryId != null && validCategoryIds.Contains((int)categoryId.Value);
7375
});
7476
}
@@ -108,7 +110,7 @@ public void Execute(UIApplication app)
108110
}
109111
return new FamilyTypeInfo
110112
{
111-
FamilyTypeId = et.Id.Value,
113+
FamilyTypeId = et.Id.GetIdValue(),
112114
UniqueId = et.UniqueId,
113115
FamilyName = familyName,
114116
TypeName = et.Name,
@@ -132,13 +134,4 @@ public string GetName()
132134
return "获取可用族类型";
133135
}
134136
}
135-
136-
public class FamilyTypeInfo
137-
{
138-
public long FamilyTypeId { get; set; }
139-
public string UniqueId { get; set; }
140-
public string FamilyName { get; set; }
141-
public string TypeName { get; set; }
142-
public string Category { get; set; }
143-
}
144137
}

revit-mcp-plugin/Commands/Access/GetCurrentViewElementsCommand.cs renamed to SampleCommandSet/Commands/Access/GetCurrentViewElementsCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Autodesk.Revit.UI;
22
using Newtonsoft.Json.Linq;
3-
using revit_mcp_plugin.Commands.Base;
3+
using revit_mcp_plugin.API.Base;
44
using System;
55
using System.Collections.Generic;
66

7-
namespace revit_mcp_plugin.Commands.Access
7+
namespace SampleCommandSet.Access
88
{
99
/// <summary>
1010
/// 获取当前视图元素的命令

revit-mcp-plugin/Commands/Access/GetCurrentViewElementsEventHandler.cs renamed to SampleCommandSet/Commands/Access/GetCurrentViewElementsEventHandler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Threading;
7-
using revit_mcp_plugin.Commands.Interfaces;
7+
using SampleCommandSet.Extensions;
8+
using revit_mcp_plugin.API.Interfaces;
89

9-
namespace revit_mcp_plugin.Commands.Access
10+
namespace SampleCommandSet.Access
1011
{
1112
/// <summary>
1213
/// 获取当前视图元素的事件处理器
@@ -142,7 +143,7 @@ public void Execute(UIApplication app)
142143
// 构建结果
143144
var elementInfos = elements.Select(e => new ElementInfo
144145
{
145-
Id = e.Id.Value,
146+
Id = e.Id.GetIdValue(),
146147
UniqueId = e.UniqueId,
147148
Name = e.Name,
148149
Category = e.Category?.Name ?? "unknow",
@@ -151,7 +152,7 @@ public void Execute(UIApplication app)
151152

152153
ResultInfo = new ViewElementsResult
153154
{
154-
ViewId = activeView.Id.Value,
155+
ViewId = activeView.Id.GetIdValue(),
155156
ViewName = activeView.Name,
156157
TotalElementsInView = new FilteredElementCollector(doc, activeView.Id).GetElementCount(),
157158
FilteredElementCount = elementInfos.Count,
@@ -174,7 +175,7 @@ private Dictionary<string, string> GetElementProperties(Element element)
174175
var properties = new Dictionary<string, string>();
175176

176177
// 添加通用属性
177-
properties.Add("ElementId", element.Id.Value.ToString());
178+
properties.Add("ElementId", element.Id.GetIdValue().ToString());
178179

179180
if (element.Location != null)
180181
{
@@ -208,7 +209,7 @@ private Dictionary<string, string> GetElementProperties(Element element)
208209
else if (param.StorageType == StorageType.Integer)
209210
properties.Add(paramName, param.AsInteger().ToString());
210211
else if (param.StorageType == StorageType.ElementId)
211-
properties.Add(paramName, param.AsElementId().Value.ToString());
212+
properties.Add(paramName, param.AsElementId().GetIdValue().ToString());
212213
}
213214
}
214215

revit-mcp-plugin/Commands/Access/GetCurrentViewInfoCommand.cs renamed to SampleCommandSet/Commands/Access/GetCurrentViewInfoCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Autodesk.Revit.UI;
22
using Newtonsoft.Json.Linq;
3-
using revit_mcp_plugin.Commands.Base;
3+
using revit_mcp_plugin.API.Base;
44
using revit_mcp_plugin.Models;
55
using System;
66

7-
namespace revit_mcp_plugin.Commands.Access
7+
namespace SampleCommandSet.Access
88
{
99
public class GetCurrentViewInfoCommand : ExternalEventCommandBase
1010
{

revit-mcp-plugin/Commands/Access/GetCurrentViewInfoEventHandler.cs renamed to SampleCommandSet/Commands/Access/GetCurrentViewInfoEventHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using Autodesk.Revit.UI;
2-
using revit_mcp_plugin.Commands.Interfaces;
2+
using revit_mcp_plugin.API.Interfaces;
33
using revit_mcp_plugin.Models;
44
using System;
55
using System.Threading;
6+
using SampleCommandSet.Extensions;
67

7-
namespace revit_mcp_plugin.Commands.Access
8+
namespace SampleCommandSet.Access
89
{
910
public class GetCurrentViewInfoEventHandler: IExternalEventHandler, IWaitableExternalEventHandler
1011
{
@@ -31,7 +32,7 @@ public void Execute(UIApplication app)
3132

3233
ResultInfo = new ViewInfo
3334
{
34-
Id = activeView.Id.Value,
35+
Id = activeView.Id.GetIdValue(),
3536
UniqueId = activeView.UniqueId,
3637
Name = activeView.Name,
3738
ViewType = activeView.ViewType.ToString(),

revit-mcp-plugin/Commands/Access/GetSelectedElementsCommand.cs renamed to SampleCommandSet/Commands/Access/GetSelectedElementsCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using Autodesk.Revit.UI;
22
using Newtonsoft.Json.Linq;
3-
using revit_mcp_plugin.Commands.Base;
3+
using revit_mcp_plugin.API.Base;
44
using System;
55

6-
namespace revit_mcp_plugin.Commands.Access
6+
namespace SampleCommandSet.Access
77
{
88
/// <summary>
99
/// 获取当前选中元素的命令

revit-mcp-plugin/Commands/Access/GetSelectedElementsEventHandler.cs renamed to SampleCommandSet/Commands/Access/GetSelectedElementsEventHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using Autodesk.Revit.DB;
22
using Autodesk.Revit.UI;
3-
using revit_mcp_plugin.Commands.Interfaces;
3+
using revit_mcp_plugin.API.Interfaces;
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Threading;
8+
using SampleCommandSet.Extensions;
89

9-
namespace revit_mcp_plugin.Commands.Access
10+
namespace SampleCommandSet.Access
1011
{
1112
public class GetSelectedElementsEventHandler : IExternalEventHandler, IWaitableExternalEventHandler
1213
{
@@ -46,7 +47,7 @@ public void Execute(UIApplication app)
4647
// 转换为ElementInfo列表
4748
ResultElements = selectedElements.Select(element => new ElementInfo
4849
{
49-
Id = element.Id.Value,
50+
Id = element.Id.GetIdValue(),
5051
UniqueId = element.UniqueId,
5152
Name = element.Name,
5253
Category = element.Category?.Name
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Autodesk.Revit.UI;
2+
using revit_mcp_plugin.API.Base;
3+
using System;
4+
using Newtonsoft.Json.Linq;
5+
6+
namespace SampleCommandSet.Create
7+
{
8+
/// <summary>
9+
/// 创建墙命令
10+
/// </summary>
11+
public class CreateWallCommand : ExternalEventCommandBase
12+
{
13+
private CreateWallEventHandler _handler => (CreateWallEventHandler)Handler;
14+
15+
/// <summary>
16+
/// 命令名称
17+
/// </summary>
18+
public override string CommandName => "create_Wall";
19+
20+
/// <summary>
21+
/// 构造函数
22+
/// </summary>
23+
/// <param name="uiApp">Revit UIApplication</param>
24+
public CreateWallCommand(UIApplication uiApp)
25+
: base(new CreateWallEventHandler(), uiApp)
26+
{
27+
}
28+
29+
/// <summary>
30+
/// 执行命令
31+
/// </summary>
32+
/// <param name="parameters">JSON参数</param>
33+
/// <param name="requestId">请求ID</param>
34+
/// <returns>命令执行结果</returns>
35+
public override object Execute(JObject parameters, string requestId)
36+
{
37+
try
38+
{
39+
// 解析墙参数
40+
double startX = parameters["startX"].Value<double>();
41+
double startY = parameters["startY"].Value<double>();
42+
double endX = parameters["endX"].Value<double>();
43+
double endY = parameters["endY"].Value<double>();
44+
double height = parameters["height"].Value<double>();
45+
double thickness = parameters["thickness"].Value<double>();
46+
47+
// 设置墙体参数
48+
_handler.SetWallParameters(startX, startY, endX, endY, height, thickness);
49+
50+
// 触发外部事件并等待完成
51+
if (RaiseAndWaitForCompletion(10000))
52+
{
53+
return _handler.CreatedWallInfo;
54+
}
55+
else
56+
{
57+
throw new TimeoutException("创建墙体操作超时");
58+
}
59+
}
60+
catch (Exception ex)
61+
{
62+
throw new Exception($"创建墙体失败: {ex.Message}");
63+
}
64+
}
65+
}
66+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using Autodesk.Revit.DB;
2+
using Autodesk.Revit.UI;
3+
using revit_mcp_plugin.API.Interfaces;
4+
using SampleCommandSet.Models;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading;
10+
using System.Threading.Tasks;
11+
12+
namespace SampleCommandSet.Create
13+
{
14+
/// <summary>
15+
/// 创建墙的外部事件处理器
16+
/// </summary>
17+
public class CreateWallEventHandler : IExternalEventHandler, IWaitableExternalEventHandler
18+
{
19+
// 创建墙的参数
20+
private double _startX;
21+
private double _startY;
22+
private double _endX;
23+
private double _endY;
24+
private double _height;
25+
private double _thickness;
26+
27+
// 创建的墙体信息
28+
private Wall _createdWall;
29+
public WallInfo CreatedWallInfo { get; private set; }
30+
31+
// 标记操作是否完成
32+
private bool _taskCompleted;
33+
34+
// 事件等待对象
35+
private readonly ManualResetEvent _resetEvent = new ManualResetEvent(false);
36+
37+
/// <summary>
38+
/// 设置创建墙的参数
39+
/// </summary>
40+
public void SetWallParameters(double startX, double startY, double endX, double endY, double height, double thickness)
41+
{
42+
_startX = startX;
43+
_startY = startY;
44+
_endX = endX;
45+
_endY = endY;
46+
_height = height;
47+
_thickness = thickness;
48+
49+
_taskCompleted = false;
50+
_resetEvent.Reset();
51+
}
52+
53+
/// <summary>
54+
/// 等待墙创建完成
55+
/// </summary>
56+
/// <param name="timeoutMilliseconds">超时时间(毫秒)</param>
57+
/// <returns>操作是否在超时前完成</returns>
58+
public bool WaitForCompletion(int timeoutMilliseconds = 10000)
59+
{
60+
return _resetEvent.WaitOne(timeoutMilliseconds);
61+
}
62+
63+
/// <summary>
64+
/// IExternalEventHandler.Execute 实现
65+
/// </summary>
66+
public void Execute(UIApplication app)
67+
{
68+
try
69+
{
70+
Document doc = app.ActiveUIDocument.Document;
71+
72+
using (Transaction trans = new Transaction(doc, "创建墙体"))
73+
{
74+
trans.Start();
75+
76+
// 创建墙的起点和终点
77+
XYZ startPoint = new XYZ(_startX, _startY, 0);
78+
XYZ endPoint = new XYZ(_endX, _endY, 0);
79+
80+
// 创建墙的曲线
81+
Line curve = Line.CreateBound(startPoint, endPoint);
82+
83+
// 获取当前文档中的墙类型
84+
FilteredElementCollector collector = new FilteredElementCollector(doc);
85+
collector.OfClass(typeof(WallType));
86+
WallType wallType = collector.FirstOrDefault(w => w.Name.Contains("常规")) as WallType;
87+
88+
// 创建墙
89+
_createdWall = Wall.Create(
90+
doc,
91+
curve,
92+
wallType.Id,
93+
doc.ActiveView.GenLevel.Id,
94+
_height,
95+
0.0, // 墙基点偏移
96+
false, // 不翻转
97+
false); // 不是结构墙
98+
99+
trans.Commit();
100+
101+
// 获取墙的详细信息
102+
CreatedWallInfo = new WallInfo
103+
{
104+
ElementId = _createdWall.Id.IntegerValue,
105+
StartPoint = new Models.Point { X = startPoint.X, Y = startPoint.Y, Z = 0 },
106+
EndPoint = new Models.Point { X = endPoint.X, Y = endPoint.Y, Z = 0 },
107+
Height = _height,
108+
Thickness = _thickness,
109+
};
110+
}
111+
}
112+
catch (Exception ex)
113+
{
114+
TaskDialog.Show("错误", $"创建墙体时出错: {ex.Message}");
115+
116+
}
117+
finally
118+
{
119+
_taskCompleted = true;
120+
_resetEvent.Set(); // 通知等待线程操作已完成
121+
}
122+
}
123+
124+
/// <summary>
125+
/// IExternalEventHandler.GetName 实现
126+
/// </summary>
127+
public string GetName()
128+
{
129+
return "创建墙体";
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)