From 7f6aa20a5f2a0402ad55a32038a9b23fc641e1e9 Mon Sep 17 00:00:00 2001
From: Shiwu <49446319+shichuyibushishiwu@users.noreply.github.com>
Date: Fri, 17 Nov 2023 18:50:54 +0800
Subject: [PATCH 1/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ribbon=E7=9A=84=E6=8A=BD?=
=?UTF-8?q?=E8=B1=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sample/Tuna.Sample/App.cs | 4 +-
.../Commands/ElementFilterCommand.cs | 6 +-
.../Tuna.Sample/Commands/SelectionCommand.cs | 19 +-
.../SelectionFilterExtension.cs | 2 +-
src/Extensions/UIExtension.cs | 180 ++++++++++--------
src/{Interfaces => Ribbon}/IRibbonButton.cs | 2 +-
src/Ribbon/IRibbonPanel.cs | 14 ++
src/Ribbon/IRibbonTab.cs | 14 ++
src/Ribbon/RibbonTab.cs | 17 ++
src/TestCommand.cs | 14 ++
src/Tuna.Revit.Extension.csproj | 2 +-
11 files changed, 181 insertions(+), 93 deletions(-)
rename src/{Interfaces => Ribbon}/IRibbonButton.cs (96%)
create mode 100644 src/Ribbon/IRibbonPanel.cs
create mode 100644 src/Ribbon/IRibbonTab.cs
create mode 100644 src/Ribbon/RibbonTab.cs
diff --git a/sample/Tuna.Sample/App.cs b/sample/Tuna.Sample/App.cs
index 22ee39b..38c07fb 100644
--- a/sample/Tuna.Sample/App.cs
+++ b/sample/Tuna.Sample/App.cs
@@ -24,7 +24,9 @@ public Result OnShutdown(UIControlledApplication application)
public Result OnStartup(UIControlledApplication application)
{
- throw new NotImplementedException();
+
+
+ return Result.Succeeded;
}
}
}
diff --git a/sample/Tuna.Sample/Commands/ElementFilterCommand.cs b/sample/Tuna.Sample/Commands/ElementFilterCommand.cs
index 6fb12fe..2a510de 100644
--- a/sample/Tuna.Sample/Commands/ElementFilterCommand.cs
+++ b/sample/Tuna.Sample/Commands/ElementFilterCommand.cs
@@ -36,7 +36,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
document.GetElements(new ElementClassFilter(typeof(Wall)));
- document.GetElements(BuiltInCategories.Wall);
+ document.GetElements(BuiltInCategories.Wall, BuiltInCategories.Wall);
document.GetElements(BuiltInCategory.OST_Walls);
@@ -68,7 +68,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
//这个方法可以获取结构相关的族
document.GetStructualFamilies(StructuralMaterialType.Steel);
-
+
var elems = uIDocument.ActiveGraphicalView.GetElements(BuiltInCategory.OST_Walls);
@@ -77,7 +77,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
uIDocument.SelectElement(BuiltInCategory.OST_Walls, "选择墙体");
-
+
diff --git a/sample/Tuna.Sample/Commands/SelectionCommand.cs b/sample/Tuna.Sample/Commands/SelectionCommand.cs
index 85a87aa..de5ff01 100644
--- a/sample/Tuna.Sample/Commands/SelectionCommand.cs
+++ b/sample/Tuna.Sample/Commands/SelectionCommand.cs
@@ -16,27 +16,40 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+
using Tuna.Revit.Extension;
namespace Tuna.Sample.Commands
{
+ ///
+ ///
+ ///
+ ///
[Transaction(TransactionMode.Manual)]
internal class SelectionCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDocument = commandData.Application.ActiveUIDocument;
+ Document document = uiDocument.Document;
uiDocument.SelectObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
-
+ SelectionResult result = commandData.Application.ActiveUIDocument.SelectObject(Autodesk.Revit.UI.Selection.ObjectType.Face,
+ referencePredicate: parameters => parameters.Reference.ConvertToStableRepresentation(document).Contains("SURFACE"), "asd");
+ if (result.Succeeded)
+ {
+
+ }
+
+
- var doors = commandData.Application.ActiveUIDocument.Document.GetElements(BuiltInCategories.Door);
+ commandData.Application.ActiveUIDocument.SelectObject(Autodesk.Revit.UI.Selection.ObjectType.LinkedElement,
+ element => element.Category.Id == BuiltInCategories.Wall, "asd");
- TaskDialog.Show("count", doors.Count().ToString());
return Result.Succeeded;
}
diff --git a/src/Data/SelectionFilters/SelectionFilterExtension.cs b/src/Data/SelectionFilters/SelectionFilterExtension.cs
index 8a6638e..de84cbb 100644
--- a/src/Data/SelectionFilters/SelectionFilterExtension.cs
+++ b/src/Data/SelectionFilters/SelectionFilterExtension.cs
@@ -108,7 +108,7 @@ public GeometrySelectionFilter(Document document, IEnumerable element
public GeometrySelectionFilter(Document document, BuiltInCategory builtInCategory, IEnumerable elementIds = null, Func filterCodition = null)
{
_document = document;
- _builtInCategory = builtInCategory;
+ _builtInCategory = builtInCategory;
_elementIds = elementIds;
_filterCodition = filterCodition;
}
diff --git a/src/Extensions/UIExtension.cs b/src/Extensions/UIExtension.cs
index ec369fe..ae3c7d7 100644
--- a/src/Extensions/UIExtension.cs
+++ b/src/Extensions/UIExtension.cs
@@ -17,95 +17,109 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
-using Tuna.Revit.Extension.Interfaces;
-namespace Tuna.Revit.Extension
+
+namespace Tuna.Revit.Extension;
+
+///
+/// Revit ribbon ui extensions
+///
+public static class UIExtension
{
///
- /// Revit ribbon ui extensions
+ /// Create ribbon push button
///
- public static class UIExtension
+ /// IExternalCommand
+ ///
+ ///
+ ///
+ public static RibbonPanel CreatePushButton(this RibbonPanel panel, Action action) where T : class, IExternalCommand, new()
{
- ///
- /// Create ribbon push button
- ///
- /// IExternalCommand
- ///
- ///
- ///
- public static RibbonPanel CreatePushButton(this RibbonPanel panel, Action action) where T : class, IExternalCommand, new()
- {
- ArgumentNullExceptionUtils.ThrowIfNull(panel);
- ArgumentNullExceptionUtils.ThrowIfNull(action);
-
-
- Type commandType = typeof(T);
- string name = commandType.Name;
- PushButtonData pushButtonData = new PushButtonData($"btn_{name}", name, commandType.Assembly.Location, commandType.FullName);
- action.Invoke(pushButtonData);
- panel.AddItem(pushButtonData);
- return panel;
- }
-
- ///
- /// Create a revit ribbon push button
- ///
- ///
- ///
- private static PushButtonData CreatePushButton() where TCommand : class, IExternalCommand, IRibbonButton, new()
- {
- IRibbonButton button = Activator.CreateInstance();
- Type commandType = typeof(TCommand);
- PushButtonData pushButtonData = new PushButtonData($"btn_{commandType.Name}", button.Text, commandType.Assembly.Location, commandType.FullName)
- {
- Image = button.Image.ConvertToBitmapSource(),
- LargeImage = button.LargeImage.ConvertToBitmapSource(),
- ToolTipImage = button.ToolTipImage.ConvertToBitmapSource(),
- ToolTip = button.ToolTip,
- LongDescription = button.LongDescription,
- };
- pushButtonData.SetContextualHelp(button.ContextualHelp);
- //pushButtonData.SetAvailability(commandType);
- return pushButtonData;
- }
-
- ///
- /// Create a revit ribbon push button
- ///
- ///
- ///
- ///
- ///
- public static PushButton CreatePushButton(this RibbonPanel panel) where TCommand : class, IExternalCommand, IRibbonButton, new()
- {
- ArgumentNullExceptionUtils.ThrowIfNull(panel);
- return panel.AddItem(CreatePushButton()) as PushButton;
- }
-
- ///
- /// Create a revit ribbon push button
- ///
- ///
- ///
- ///
- ///
- public static PushButton CreatePushButton(this PulldownButton pulldownButton) where TCommand : class, IExternalCommand, IRibbonButton, new()
+ ArgumentNullExceptionUtils.ThrowIfNull(panel);
+ ArgumentNullExceptionUtils.ThrowIfNull(action);
+
+
+ Type commandType = typeof(T);
+ string name = commandType.Name;
+ PushButtonData pushButtonData = new PushButtonData($"btn_{name}", name, commandType.Assembly.Location, commandType.FullName);
+ action.Invoke(pushButtonData);
+ panel.AddItem(pushButtonData);
+ return panel;
+ }
+
+ ///
+ /// Create a revit ribbon push button
+ ///
+ ///
+ ///
+ private static PushButtonData CreatePushButton() where TCommand : class, IExternalCommand, IRibbonButton, new()
+ {
+ IRibbonButton button = Activator.CreateInstance();
+ Type commandType = typeof(TCommand);
+ PushButtonData pushButtonData = new PushButtonData($"btn_{commandType.Name}", button.Text, commandType.Assembly.Location, commandType.FullName)
{
- ArgumentNullExceptionUtils.ThrowIfNull(pulldownButton);
- return pulldownButton.AddPushButton(CreatePushButton());
- }
-
- ///
- /// Create a revit ribbon push button
- ///
- ///
- ///
- ///
- ///
- public static PushButton CreatePushButton(this SplitButton splitButton) where TCommand : class, IExternalCommand, IExternalCommandAvailability, IRibbonButton, new()
+ Image = button.Image.ConvertToBitmapSource(),
+ LargeImage = button.LargeImage.ConvertToBitmapSource(),
+ ToolTipImage = button.ToolTipImage.ConvertToBitmapSource(),
+ ToolTip = button.ToolTip,
+ LongDescription = button.LongDescription,
+ };
+ pushButtonData.SetContextualHelp(button.ContextualHelp);
+ //pushButtonData.SetAvailability(commandType);
+ return pushButtonData;
+ }
+
+ ///
+ /// Create a revit ribbon push button
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static PushButton CreatePushButton(this RibbonPanel panel) where TCommand : class, IExternalCommand, IRibbonButton, new()
+ {
+ ArgumentNullExceptionUtils.ThrowIfNull(panel);
+ return panel.AddItem(CreatePushButton()) as PushButton;
+ }
+
+ ///
+ /// Create a revit ribbon push button
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static PushButton CreatePushButton(this PulldownButton pulldownButton) where TCommand : class, IExternalCommand, IRibbonButton, new()
+ {
+ ArgumentNullExceptionUtils.ThrowIfNull(pulldownButton);
+ return pulldownButton.AddPushButton(CreatePushButton());
+ }
+
+ ///
+ /// Create a revit ribbon push button
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static PushButton CreatePushButton(this SplitButton splitButton) where TCommand : class, IExternalCommand, IExternalCommandAvailability, IRibbonButton, new()
+ {
+ ArgumentNullExceptionUtils.ThrowIfNull(splitButton);
+ return splitButton.AddPushButton(CreatePushButton());
+ }
+
+
+
+
+
+ public static void CreateRibbonTab(this UIControlledApplication application, string name,Action action)
+ {
+ application.CreateRibbonTab(name);
+ action.Invoke(new RibbonTab()
{
- ArgumentNullExceptionUtils.ThrowIfNull(splitButton);
- return splitButton.AddPushButton(CreatePushButton());
- }
+
+ });
}
+
+
}
diff --git a/src/Interfaces/IRibbonButton.cs b/src/Ribbon/IRibbonButton.cs
similarity index 96%
rename from src/Interfaces/IRibbonButton.cs
rename to src/Ribbon/IRibbonButton.cs
index 2c7b73b..a9a2293 100644
--- a/src/Interfaces/IRibbonButton.cs
+++ b/src/Ribbon/IRibbonButton.cs
@@ -11,7 +11,7 @@
using Autodesk.Revit.UI;
using System.Drawing;
-namespace Tuna.Revit.Extension.Interfaces;
+namespace Tuna.Revit.Extension;
///
/// Revit ribbon ui push button information
diff --git a/src/Ribbon/IRibbonPanel.cs b/src/Ribbon/IRibbonPanel.cs
new file mode 100644
index 0000000..0745cf8
--- /dev/null
+++ b/src/Ribbon/IRibbonPanel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension;
+
+public interface IRibbonPanel
+{
+ string Name { get; }
+
+
+}
diff --git a/src/Ribbon/IRibbonTab.cs b/src/Ribbon/IRibbonTab.cs
new file mode 100644
index 0000000..e91a216
--- /dev/null
+++ b/src/Ribbon/IRibbonTab.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension;
+
+public interface IRibbonTab
+{
+ string TabName { get; }
+
+ void CreateRibbonPanel(string name, Action action);
+}
diff --git a/src/Ribbon/RibbonTab.cs b/src/Ribbon/RibbonTab.cs
new file mode 100644
index 0000000..272337f
--- /dev/null
+++ b/src/Ribbon/RibbonTab.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension;
+
+internal class RibbonTab : IRibbonTab
+{
+ public string TabName { get; internal set; }
+
+ public void CreateRibbonPanel(string name, Action action)
+ {
+ throw new NotImplementedException();
+ }
+}
diff --git a/src/TestCommand.cs b/src/TestCommand.cs
index 57fb4db..ceca048 100644
--- a/src/TestCommand.cs
+++ b/src/TestCommand.cs
@@ -31,3 +31,17 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
return Result.Succeeded;
}
}
+
+internal class TestApplication : IExternalApplication
+{
+ public Result OnShutdown(UIControlledApplication application)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Result OnStartup(UIControlledApplication application)
+ {
+ application.CreateRibbonTab("ad", tab => tab.CreateRibbonPanel("", panel => panel);
+ return Result.Succeeded;
+ }
+}
diff --git a/src/Tuna.Revit.Extension.csproj b/src/Tuna.Revit.Extension.csproj
index 72d6581..caa6201 100644
--- a/src/Tuna.Revit.Extension.csproj
+++ b/src/Tuna.Revit.Extension.csproj
@@ -198,7 +198,7 @@
-
+
From 87b6f49b436a28f96ebe0c0b5e5156b042417db4 Mon Sep 17 00:00:00 2001
From: Shiwu <49446319+shichuyibushishiwu@users.noreply.github.com>
Date: Wed, 22 Nov 2023 18:15:27 +0800
Subject: [PATCH 2/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E6=AD=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Services/ExternalEventService.cs | 46 ++++++++++++++++++++++++++-
src/Services/IExternalEventService.cs | 5 +--
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/src/Services/ExternalEventService.cs b/src/Services/ExternalEventService.cs
index f490e61..edd0bcb 100644
--- a/src/Services/ExternalEventService.cs
+++ b/src/Services/ExternalEventService.cs
@@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
+using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
@@ -40,9 +42,51 @@ public void Execute(UIApplication app)
///
///
///
- public void PostCommand()
+ public async Task PostCommandAsync(Action handle)
{
ExternalEventRequest request = _externalEvent.Raise();
+ if (request == ExternalEventRequest.Accepted)
+ {
+ await InternalPostCommandAsync(handle);
+ }
+ }
+
+ private async Task InternalPostCommandAsync(Action handle)
+ {
+ _handle = handle;
+
+ await Task.CompletedTask;
+ }
+
+ private Action _handle;
+
+ public void PostCommand(Action handle)
+ {
+ _handle = handle;
+ _externalEvent.Raise();
+ }
+ }
+
+ ///
+ ///
+ ///
+ public static class Extensions
+ {
+ public static Task CommandAsync(this ExternalEventService service, Action handle)
+ {
+ var tsc = new TaskCompletionSource();
+ service.PostCommand(uiapp =>
+ {
+ try
+ {
+ handle.Invoke(uiapp);
+ }
+ catch (Exception e)
+ {
+ tsc.SetException(e);
+ }
+ });
+ return tsc.Task;
}
}
}
diff --git a/src/Services/IExternalEventService.cs b/src/Services/IExternalEventService.cs
index 357dc1c..a8b2196 100644
--- a/src/Services/IExternalEventService.cs
+++ b/src/Services/IExternalEventService.cs
@@ -1,4 +1,5 @@
-using System;
+using Autodesk.Revit.UI;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -14,6 +15,6 @@ public interface IExternalEventService
///
///
///
- void PostCommand();
+ Task PostCommandAsync(Action handle);
}
}
From 76e222f10f8f78da4025a83d94724fe1cf8e0f19 Mon Sep 17 00:00:00 2001
From: Shiwu <49446319+shichuyibushishiwu@users.noreply.github.com>
Date: Fri, 24 Nov 2023 11:13:20 +0800
Subject: [PATCH 3/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=96=E9=83=A8?=
=?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9A=84=E5=BC=82=E6=AD=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Constants/BuiltInCategories.cs | 46 ++++++--
src/Constants/BuiltInParameters.cs | 1 +
src/Services/ExternalEventService.cs | 101 ++++++------------
src/Services/ExternalEventServiceExtension.cs | 56 ++++++++++
src/Services/IExternalEventService.cs | 19 ++--
src/TestCommand.cs | 4 +-
src/Tuna.Revit.Extension.csproj | 3 +-
7 files changed, 140 insertions(+), 90 deletions(-)
create mode 100644 src/Services/ExternalEventServiceExtension.cs
diff --git a/src/Constants/BuiltInCategories.cs b/src/Constants/BuiltInCategories.cs
index ded7320..1b5e7d3 100644
--- a/src/Constants/BuiltInCategories.cs
+++ b/src/Constants/BuiltInCategories.cs
@@ -9,12 +9,8 @@
************************************************************************************/
using Autodesk.Revit.DB;
-using System;
using System.Collections.Generic;
using System.Linq;
-using System.Numerics;
-using System.Text;
-using System.Threading.Tasks;
namespace Tuna.Revit.Extension;
@@ -569,12 +565,6 @@ public class BuiltInCategories
///
public static ElementId DuctLinings { get; set; } = new ElementId(BuiltInCategory.OST_DuctLinings);
- ///
- /// 部件标记
- ///
- ///
- public static ElementId AssemblyTags { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyTags);
-
///
/// 零件标记
///
@@ -1559,6 +1549,42 @@ public class BuiltInCategories
///
public static ElementId WireTags { get; set; } = new ElementId(BuiltInCategory.OST_WireTags);
+ ///
+ /// 部件
+ ///
+ ///
+ public static ElementId Assemblies { get; set; } = new ElementId(BuiltInCategory.OST_Assemblies);
+
+ ///
+ /// 部件原点
+ ///
+ ///
+ public static ElementId AssemblyOrigin { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin);
+
+ ///
+ ///
+ ///
+ ///
+ public static ElementId AssemblyOrigin_Lines { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin_Lines);
+
+ ///
+ ///
+ ///
+ ///
+ public static ElementId AssemblyOrigin_Planes { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin_Planes);
+
+ ///
+ ///
+ ///
+ ///
+ public static ElementId AssemblyOrigin_Points { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin_Points);
+
+ ///
+ /// 部件标记
+ ///
+ ///
+ public static ElementId AssemblyTags { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyTags);
+
///
/// 根据视图的规程过滤出可见性相关的类别
/// Get category by
diff --git a/src/Constants/BuiltInParameters.cs b/src/Constants/BuiltInParameters.cs
index d9a7910..4834f78 100644
--- a/src/Constants/BuiltInParameters.cs
+++ b/src/Constants/BuiltInParameters.cs
@@ -46,6 +46,7 @@ public class View
/// VIEW_SCALE
///
public static ElementId Scale { get; } = new ElementId(BuiltInParameter.VIEW_SCALE);
+
}
diff --git a/src/Services/ExternalEventService.cs b/src/Services/ExternalEventService.cs
index edd0bcb..9d66a15 100644
--- a/src/Services/ExternalEventService.cs
+++ b/src/Services/ExternalEventService.cs
@@ -7,86 +7,51 @@
using System.Text;
using System.Threading.Tasks;
-namespace Tuna.Revit.Extension.Services
+namespace Tuna.Revit.Extension;
+
+///
+/// 通用的外部事件
+///
+public class ExternalEventService : IExternalEventService, IExternalEventHandler
{
+ private readonly ExternalEvent _externalEvent;
+ private Action _handle;
+
///
- ///
+ /// 初始化外部事件,只能在有效上下文进行
///
- public class ExternalEventService : IExternalEventService, IExternalEventHandler
- {
- private readonly ExternalEvent _externalEvent;
-
- ///
- ///
- ///
- public ExternalEventService()
- {
- _externalEvent = ExternalEvent.Create(this);
- }
-
- ///
- ///
- ///
- ///
- public void Execute(UIApplication app)
- {
-
- }
-
- ///
- ///
- ///
- ///
- public string GetName() => "Tuna external event";
-
- ///
- ///
- ///
- public async Task PostCommandAsync(Action handle)
- {
- ExternalEventRequest request = _externalEvent.Raise();
- if (request == ExternalEventRequest.Accepted)
- {
- await InternalPostCommandAsync(handle);
- }
- }
-
- private async Task InternalPostCommandAsync(Action handle)
- {
- _handle = handle;
-
- await Task.CompletedTask;
- }
-
- private Action _handle;
+ public ExternalEventService() => _externalEvent = ExternalEvent.Create(this);
- public void PostCommand(Action handle)
+ ///
+ ///
+ ///
+ ///
+ public void Execute(UIApplication app)
+ {
+ if (_handle == null)
{
- _handle = handle;
- _externalEvent.Raise();
+ throw new ArgumentNullException("handle can not be null");
}
+ _handle.Invoke(app);
}
///
- ///
+ ///
+ ///
+ ///
+ public string GetName() => "Tuna external event";
+
+ ///
+ ///
///
- public static class Extensions
+ ///
+ public void PostCommand(Action handle)
{
- public static Task CommandAsync(this ExternalEventService service, Action handle)
+ ArgumentNullExceptionUtils.ThrowIfNull(handle);
+ _handle = handle;
+ if (_externalEvent.Raise() != ExternalEventRequest.Accepted)
{
- var tsc = new TaskCompletionSource();
- service.PostCommand(uiapp =>
- {
- try
- {
- handle.Invoke(uiapp);
- }
- catch (Exception e)
- {
- tsc.SetException(e);
- }
- });
- return tsc.Task;
+ throw new Exception("handle can not accepted");
}
}
}
diff --git a/src/Services/ExternalEventServiceExtension.cs b/src/Services/ExternalEventServiceExtension.cs
new file mode 100644
index 0000000..51d0ebb
--- /dev/null
+++ b/src/Services/ExternalEventServiceExtension.cs
@@ -0,0 +1,56 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension;
+
+///
+/// 外部事件对异步的扩展
+///
+public static class ExternalEventServiceExtension
+{
+ ///
+ /// 用异步的方式发布外部事件
+ /// Asynchronously post an external command to revit
+ ///
+ /// 外部事件的服务
+ /// 执行的内容
+ ///
+ public static Task PostCommandAsync(this IExternalEventService service, Action handle)
+ {
+ return service.PostCommandAsync((uiApp) =>
+ {
+ handle(uiApp);
+ return default(object);
+ });
+ }
+
+ ///
+ /// 用异步的方式发布外部事件
+ /// Asynchronously post an external command to revit
+ ///
+ /// 返回的结果
+ /// 外部事件的服务
+ /// 执行的内容
+ ///
+ public static Task PostCommandAsync(this IExternalEventService service, Func handle)
+ {
+ ArgumentNullExceptionUtils.ThrowIfNull(service);
+ var tsc = new TaskCompletionSource();
+ service.PostCommand(uiapp =>
+ {
+ try
+ {
+ tsc.SetResult(handle.Invoke(uiapp));
+ }
+ catch (Exception e)
+ {
+ tsc.SetException(e);
+ }
+ });
+ return tsc.Task;
+ }
+}
diff --git a/src/Services/IExternalEventService.cs b/src/Services/IExternalEventService.cs
index a8b2196..e6d18fc 100644
--- a/src/Services/IExternalEventService.cs
+++ b/src/Services/IExternalEventService.cs
@@ -5,16 +5,17 @@
using System.Text;
using System.Threading.Tasks;
-namespace Tuna.Revit.Extension.Services
+namespace Tuna.Revit.Extension;
+
+///
+/// 外部事件的常规服务
+///
+public interface IExternalEventService
{
///
- ///
+ /// 发布外部事件
+ /// Post an external command to revit
///
- public interface IExternalEventService
- {
- ///
- ///
- ///
- Task PostCommandAsync(Action handle);
- }
+ /// 可执行的任务
+ void PostCommand(Action handle);
}
diff --git a/src/TestCommand.cs b/src/TestCommand.cs
index ceca048..c784b12 100644
--- a/src/TestCommand.cs
+++ b/src/TestCommand.cs
@@ -8,6 +8,8 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
+
namespace Tuna.Revit.Extension;
@@ -41,7 +43,7 @@ public Result OnShutdown(UIControlledApplication application)
public Result OnStartup(UIControlledApplication application)
{
- application.CreateRibbonTab("ad", tab => tab.CreateRibbonPanel("", panel => panel);
+ //application.CreateRibbonTab("ad", tab => tab.CreateRibbonPanel("", panel => panel);
return Result.Succeeded;
}
}
diff --git a/src/Tuna.Revit.Extension.csproj b/src/Tuna.Revit.Extension.csproj
index caa6201..4bf5419 100644
--- a/src/Tuna.Revit.Extension.csproj
+++ b/src/Tuna.Revit.Extension.csproj
@@ -30,7 +30,6 @@
True
https://github.com/shichuyibushishiwu/Tuna.Revit.Extensions
shichuyibushishiwu
- zh;en
MIT
@@ -198,7 +197,7 @@
-
+
From 00c75e6d8f06bc418368b759eac388198d728d8d Mon Sep 17 00:00:00 2001
From: Shiwu <49446319+shichuyibushishiwu@users.noreply.github.com>
Date: Fri, 24 Nov 2023 17:59:13 +0800
Subject: [PATCH 4/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86ribbon?=
=?UTF-8?q?=E4=BB=A3=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Extensions/UIExtension.cs | 140 +++++++++---------
src/Ribbon/{ => Abstraction}/IRibbonButton.cs | 0
.../IRibbonItem.cs} | 9 +-
.../Abstraction/IRibbonItemsCollector.cs | 15 ++
src/Ribbon/Abstraction/IRibbonPanel.cs | 29 ++++
src/Ribbon/{ => Abstraction}/IRibbonTab.cs | 12 +-
src/Ribbon/Proxy/RibbonButtonProxy.cs | 14 ++
src/Ribbon/Proxy/RibbonComboBoxProxy.cs | 13 ++
src/Ribbon/Proxy/RibbonElementProxy.cs | 16 ++
src/Ribbon/Proxy/RibbonPanelProxy.cs | 63 ++++++++
src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs | 31 ++++
src/Ribbon/Proxy/RibbonTabProxy.cs | 24 +++
src/Ribbon/RibbonExtension.cs | 97 ++++++++++++
src/Ribbon/RibbonTab.cs | 17 ---
src/TestCommand.cs | 15 +-
15 files changed, 405 insertions(+), 90 deletions(-)
rename src/Ribbon/{ => Abstraction}/IRibbonButton.cs (100%)
rename src/Ribbon/{IRibbonPanel.cs => Abstraction/IRibbonItem.cs} (56%)
create mode 100644 src/Ribbon/Abstraction/IRibbonItemsCollector.cs
create mode 100644 src/Ribbon/Abstraction/IRibbonPanel.cs
rename src/Ribbon/{ => Abstraction}/IRibbonTab.cs (50%)
create mode 100644 src/Ribbon/Proxy/RibbonButtonProxy.cs
create mode 100644 src/Ribbon/Proxy/RibbonComboBoxProxy.cs
create mode 100644 src/Ribbon/Proxy/RibbonElementProxy.cs
create mode 100644 src/Ribbon/Proxy/RibbonPanelProxy.cs
create mode 100644 src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs
create mode 100644 src/Ribbon/Proxy/RibbonTabProxy.cs
create mode 100644 src/Ribbon/RibbonExtension.cs
delete mode 100644 src/Ribbon/RibbonTab.cs
diff --git a/src/Extensions/UIExtension.cs b/src/Extensions/UIExtension.cs
index ae3c7d7..64bb5dd 100644
--- a/src/Extensions/UIExtension.cs
+++ b/src/Extensions/UIExtension.cs
@@ -26,100 +26,108 @@ namespace Tuna.Revit.Extension;
///
public static class UIExtension
{
- ///
- /// Create ribbon push button
- ///
- /// IExternalCommand
- ///
- ///
- ///
- public static RibbonPanel CreatePushButton(this RibbonPanel panel, Action action) where T : class, IExternalCommand, new()
+ static PushButtonData CreatePushButtonData(string text = null) where T : class, new()
{
- ArgumentNullExceptionUtils.ThrowIfNull(panel);
- ArgumentNullExceptionUtils.ThrowIfNull(action);
-
-
+ //按钮的类型
Type commandType = typeof(T);
+
+ //按钮的名称
string name = commandType.Name;
- PushButtonData pushButtonData = new PushButtonData($"btn_{name}", name, commandType.Assembly.Location, commandType.FullName);
- action.Invoke(pushButtonData);
- panel.AddItem(pushButtonData);
- return panel;
+
+ //实例化一个按钮的数据
+ return new PushButtonData($"btn_{name}", text ?? name, commandType.Assembly.Location, commandType.FullName);
}
- ///
- /// Create a revit ribbon push button
- ///
- ///
- ///
- private static PushButtonData CreatePushButton() where TCommand : class, IExternalCommand, IRibbonButton, new()
+ static PushButtonData CreatePushButtonData() where T : class, IRibbonButton, new()
{
- IRibbonButton button = Activator.CreateInstance();
- Type commandType = typeof(TCommand);
- PushButtonData pushButtonData = new PushButtonData($"btn_{commandType.Name}", button.Text, commandType.Assembly.Location, commandType.FullName)
- {
- Image = button.Image.ConvertToBitmapSource(),
- LargeImage = button.LargeImage.ConvertToBitmapSource(),
- ToolTipImage = button.ToolTipImage.ConvertToBitmapSource(),
- ToolTip = button.ToolTip,
- LongDescription = button.LongDescription,
- };
+ //创建抽象按钮的实例
+ IRibbonButton button = Activator.CreateInstance();
+
+ //实例化一个按钮的数据
+ PushButtonData pushButtonData = CreatePushButtonData(button.Text);
+
+ //对参数进行赋值
+ pushButtonData.Image = button.Image.ConvertToBitmapSource();
+ pushButtonData.LargeImage = button.LargeImage.ConvertToBitmapSource();
+ pushButtonData.ToolTipImage = button.ToolTipImage.ConvertToBitmapSource();
+ pushButtonData.ToolTip = button.ToolTip;
+ pushButtonData.LongDescription = button.LongDescription;
pushButtonData.SetContextualHelp(button.ContextualHelp);
- //pushButtonData.SetAvailability(commandType);
+
return pushButtonData;
}
+
+ public static ComboBox CreateComboBox(this RibbonPanel panel, string name, Action handle = null)
+ {
+ ArgumentNullExceptionUtils.ThrowIfNull(panel);
+ ComboBoxData combo = new ComboBoxData(name);
+ handle?.Invoke(combo);
+ return panel.AddItem(combo) as ComboBox;
+ }
+
///
- /// Create a revit ribbon push button
+ /// 在面板上创建一个按钮
+ /// Create a ribbon push button on the panel
///
- ///
- ///
- ///
- ///
- public static PushButton CreatePushButton(this RibbonPanel panel) where TCommand : class, IExternalCommand, IRibbonButton, new()
+ /// 外部命令,必须是一个自定义类型,且继承于,且必须存在一个无参的构造函数
+ /// 要添加按钮的面板
+ /// 对按钮的参数进行赋值
+ /// 创建的按钮
+ public static PushButton CreatePushButton(this RibbonPanel panel, Action handle) where T : class, IExternalCommand, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(panel);
- return panel.AddItem(CreatePushButton()) as PushButton;
+ ArgumentNullExceptionUtils.ThrowIfNull(handle);
+
+ //实例化一个按钮的数据
+ PushButtonData pushButtonData = CreatePushButtonData();
+
+ //用户自己添加按钮的其他数据
+ handle.Invoke(pushButtonData);
+
+ //添加到面板,并返回给调用方
+ return panel.AddItem(pushButtonData) as PushButton;
}
///
- /// Create a revit ribbon push button
+ /// 在面板上创建一个按钮
+ /// Create a ribbon push button on the panel
///
- ///
- ///
- ///
+ /// 外部命令,必须是一个自定义类型,且继承于 和 ,且必须存在一个无参的构造函数
+ /// 要添加按钮的面板
+ /// 创建的按钮
///
- public static PushButton CreatePushButton(this PulldownButton pulldownButton) where TCommand : class, IExternalCommand, IRibbonButton, new()
+ public static PushButton CreatePushButton(this RibbonPanel panel) where T : class, IExternalCommand, IRibbonButton, new()
{
- ArgumentNullExceptionUtils.ThrowIfNull(pulldownButton);
- return pulldownButton.AddPushButton(CreatePushButton());
+ ArgumentNullExceptionUtils.ThrowIfNull(panel);
+ return panel.AddItem(CreatePushButtonData()) as PushButton;
}
///
- /// Create a revit ribbon push button
+ /// 在下拉按钮上创建一个按钮
+ /// Create a ribbon push button on the panel
///
- ///
- ///
- ///
+ /// 外部命令,必须是一个自定义类型,且继承于 和 ,且必须存在一个无参的构造函数
+ /// 要添加按钮的下拉按钮
+ /// 创建的按钮
///
- public static PushButton CreatePushButton(this SplitButton splitButton) where TCommand : class, IExternalCommand, IExternalCommandAvailability, IRibbonButton, new()
+ public static PushButton CreatePushButton(this PulldownButton pulldownButton) where T : class, IExternalCommand, IRibbonButton, new()
{
- ArgumentNullExceptionUtils.ThrowIfNull(splitButton);
- return splitButton.AddPushButton(CreatePushButton());
+ ArgumentNullExceptionUtils.ThrowIfNull(pulldownButton);
+ return pulldownButton.AddPushButton(CreatePushButtonData());
}
-
-
-
-
- public static void CreateRibbonTab(this UIControlledApplication application, string name,Action action)
+ ///
+ /// 在下拉按钮上创建一个按钮
+ /// Create a ribbon push button on the panel
+ ///
+ /// 外部命令,必须是一个自定义类型,且继承于 和 ,且必须存在一个无参的构造函数
+ /// 要添加按钮的下拉按钮
+ /// 创建的按钮
+ ///
+ public static PushButton CreatePushButton(this SplitButton splitButton) where T : class, IExternalCommand, IExternalCommandAvailability, IRibbonButton, new()
{
- application.CreateRibbonTab(name);
- action.Invoke(new RibbonTab()
- {
-
- });
+ ArgumentNullExceptionUtils.ThrowIfNull(splitButton);
+ return splitButton.AddPushButton(CreatePushButtonData());
}
-
-
}
diff --git a/src/Ribbon/IRibbonButton.cs b/src/Ribbon/Abstraction/IRibbonButton.cs
similarity index 100%
rename from src/Ribbon/IRibbonButton.cs
rename to src/Ribbon/Abstraction/IRibbonButton.cs
diff --git a/src/Ribbon/IRibbonPanel.cs b/src/Ribbon/Abstraction/IRibbonItem.cs
similarity index 56%
rename from src/Ribbon/IRibbonPanel.cs
rename to src/Ribbon/Abstraction/IRibbonItem.cs
index 0745cf8..b370b46 100644
--- a/src/Ribbon/IRibbonPanel.cs
+++ b/src/Ribbon/Abstraction/IRibbonItem.cs
@@ -1,4 +1,5 @@
-using System;
+using Autodesk.Revit.UI;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,9 +7,7 @@
namespace Tuna.Revit.Extension;
-public interface IRibbonPanel
+internal interface IRibbonItem
{
- string Name { get; }
-
-
+ RibbonItemType Type { get; }
}
diff --git a/src/Ribbon/Abstraction/IRibbonItemsCollector.cs b/src/Ribbon/Abstraction/IRibbonItemsCollector.cs
new file mode 100644
index 0000000..0ea048b
--- /dev/null
+++ b/src/Ribbon/Abstraction/IRibbonItemsCollector.cs
@@ -0,0 +1,15 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tuna.Revit.Extension.Ribbon.Abstraction;
+using Tuna.Revit.Extension.Ribbon.Proxy;
+
+namespace Tuna.Revit.Extension;
+
+internal interface IRibbonItemsCollector
+{
+ public IEnumerable GetItems();
+}
diff --git a/src/Ribbon/Abstraction/IRibbonPanel.cs b/src/Ribbon/Abstraction/IRibbonPanel.cs
new file mode 100644
index 0000000..0e0e7e1
--- /dev/null
+++ b/src/Ribbon/Abstraction/IRibbonPanel.cs
@@ -0,0 +1,29 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension;
+
+public interface IRibbonPanel
+{
+ string Name { get; }
+
+ void AddSlideOut();
+
+ void AddSeparator();
+
+ //public void CreatePulldownButton();
+
+ //public void CreatePushButton() where TCommand : IExternalCommand;
+
+ //public void CreateSplitButton();
+
+ //public void CreateRadioButtonGroup();
+
+ //public void CreateTextBox();
+
+ //public void CreateComboBox();
+}
diff --git a/src/Ribbon/IRibbonTab.cs b/src/Ribbon/Abstraction/IRibbonTab.cs
similarity index 50%
rename from src/Ribbon/IRibbonTab.cs
rename to src/Ribbon/Abstraction/IRibbonTab.cs
index e91a216..ce2071d 100644
--- a/src/Ribbon/IRibbonTab.cs
+++ b/src/Ribbon/Abstraction/IRibbonTab.cs
@@ -6,9 +6,19 @@
namespace Tuna.Revit.Extension;
+///
+///
+///
public interface IRibbonTab
{
+ ///
+ ///
+ ///
string TabName { get; }
- void CreateRibbonPanel(string name, Action action);
+ ///
+ ///
+ ///
+ ///
+ IRibbonPanel CreateRibbonPanel(string name);
}
diff --git a/src/Ribbon/Proxy/RibbonButtonProxy.cs b/src/Ribbon/Proxy/RibbonButtonProxy.cs
new file mode 100644
index 0000000..df06d4b
--- /dev/null
+++ b/src/Ribbon/Proxy/RibbonButtonProxy.cs
@@ -0,0 +1,14 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+
+namespace Tuna.Revit.Extension.Ribbon.Proxy;
+
+internal class RibbonButtonProxy : RibbonElementProxy, IRibbonItem
+{
+ public RibbonItemType Type => RibbonItemType.PushButton;
+}
diff --git a/src/Ribbon/Proxy/RibbonComboBoxProxy.cs b/src/Ribbon/Proxy/RibbonComboBoxProxy.cs
new file mode 100644
index 0000000..4d1018f
--- /dev/null
+++ b/src/Ribbon/Proxy/RibbonComboBoxProxy.cs
@@ -0,0 +1,13 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls.Ribbon;
+
+namespace Tuna.Revit.Extension.Ribbon.Proxy;
+
+internal class RibbonComboBoxProxy : RibbonElementProxy
+{
+}
diff --git a/src/Ribbon/Proxy/RibbonElementProxy.cs b/src/Ribbon/Proxy/RibbonElementProxy.cs
new file mode 100644
index 0000000..4bb9d0d
--- /dev/null
+++ b/src/Ribbon/Proxy/RibbonElementProxy.cs
@@ -0,0 +1,16 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tuna.Revit.Extension.Ribbon.Abstraction;
+
+namespace Tuna.Revit.Extension.Ribbon.Proxy;
+
+internal abstract class RibbonElementProxy
+{
+ public T OriginalObject { get; set; }
+
+ public string Name { get; set; }
+}
diff --git a/src/Ribbon/Proxy/RibbonPanelProxy.cs b/src/Ribbon/Proxy/RibbonPanelProxy.cs
new file mode 100644
index 0000000..e4cfccf
--- /dev/null
+++ b/src/Ribbon/Proxy/RibbonPanelProxy.cs
@@ -0,0 +1,63 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension.Ribbon.Proxy;
+
+internal class RibbonPanelProxy : RibbonElementProxy, IRibbonPanel, IRibbonItemsCollector
+{
+ private readonly List _items = new List();
+
+ public RibbonTabProxy Parent { get; internal set; }
+
+ public void AddSlideOut() => OriginalObject.AddSlideOut();
+
+ public void AddSeparator() => OriginalObject.AddSeparator();
+
+ public void AddPushButton() where TCommand : class, IExternalCommand, IRibbonButton, new()
+ {
+ RibbonButton ribbonButton = this.OriginalObject.CreatePushButton();
+ RibbonButtonProxy ribbonButtonProxy = new RibbonButtonProxy()
+ {
+ OriginalObject = ribbonButton,
+ Name = ribbonButton.Name,
+ };
+ _items.Add(ribbonButtonProxy);
+ }
+
+ public void AddComboBox()
+ {
+
+ }
+
+ public void CreatePulldownButton()
+ {
+
+
+ }
+
+ public void CreatePushButton() where TCommand : IExternalCommand
+ {
+
+ }
+
+ public void CreateRadioButtonGroup()
+ {
+
+ }
+
+ public void CreateSplitButton()
+ {
+
+ }
+
+ public void CreateTextBox()
+ {
+
+ }
+
+ public IEnumerable GetItems() => _items;
+}
diff --git a/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs b/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs
new file mode 100644
index 0000000..1f8f518
--- /dev/null
+++ b/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs
@@ -0,0 +1,31 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tuna.Revit.Extension.Ribbon.Proxy
+{
+ internal class RibbonPulldownButtonProxy : RibbonElementProxy, IRibbonItem, IRibbonItemsCollector
+ {
+ private readonly List _items = new List();
+
+ public RibbonItemType Type => RibbonItemType.PulldownButton;
+
+ public void AddPushButton() where TCommand : class, IExternalCommand, IRibbonButton, new()
+ {
+ RibbonButton ribbonButton = this.OriginalObject.CreatePushButton();
+ RibbonButtonProxy ribbonButtonProxy = new RibbonButtonProxy()
+ {
+ OriginalObject = ribbonButton,
+ Name = ribbonButton.Name,
+ };
+ _items.Add(ribbonButtonProxy);
+ }
+
+
+
+ public IEnumerable GetItems() => _items;
+ }
+}
diff --git a/src/Ribbon/Proxy/RibbonTabProxy.cs b/src/Ribbon/Proxy/RibbonTabProxy.cs
new file mode 100644
index 0000000..b7af7a0
--- /dev/null
+++ b/src/Ribbon/Proxy/RibbonTabProxy.cs
@@ -0,0 +1,24 @@
+using Autodesk.Revit.DB;
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace Tuna.Revit.Extension.Ribbon.Proxy;
+
+internal class RibbonTabProxy : IRibbonTab
+{
+ public string TabName { get; internal set; }
+
+ public UIControlledApplication Application { get; internal set; }
+
+ public IRibbonPanel CreateRibbonPanel(string name) => new RibbonPanelProxy()
+ {
+ Parent = this,
+ Name = name,
+ OriginalObject = Application.CreateRibbonPanel(TabName, name)
+ };
+}
diff --git a/src/Ribbon/RibbonExtension.cs b/src/Ribbon/RibbonExtension.cs
new file mode 100644
index 0000000..f4825fe
--- /dev/null
+++ b/src/Ribbon/RibbonExtension.cs
@@ -0,0 +1,97 @@
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using Tuna.Revit.Extension.Ribbon.Proxy;
+
+namespace Tuna.Revit.Extension;
+
+///
+/// 对UI的扩展
+///
+public static class RibbonExtension
+{
+ ///
+ /// 创建Tab
+ ///
+ ///
+ ///
+ ///
+ public static void CreateRibbonTab(this UIControlledApplication application, string name, Action action)
+ {
+ application.CreateRibbonTab(name);
+ action.Invoke(new RibbonTabProxy()
+ {
+ Application = application,
+ TabName = name,
+ });
+ }
+
+ ///
+ /// 创建面板
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IRibbonTab CreateRibbonPanel(this IRibbonTab tab, string name, Action handle)
+ {
+ IRibbonPanel ribbonPanel = tab.CreateRibbonPanel(name);
+ handle?.Invoke(ribbonPanel);
+ return tab;
+ }
+
+
+ public static IRibbonPanel AddComboBox(this IRibbonPanel ribbonPanel)
+ {
+ return ribbonPanel;
+ }
+
+ public static IRibbonPanel AddTextBox(this IRibbonPanel ribbonPanel)
+ {
+ return ribbonPanel;
+ }
+
+ public static IRibbonPanel AddPulldownButton(this IRibbonPanel ribbonPanel)
+ {
+ return ribbonPanel;
+ }
+
+
+
+ public static IRibbonPanel AddSplitButton(this IRibbonPanel ribbonPanel)
+ {
+ return ribbonPanel;
+ }
+
+ public static IRibbonPanel AddPushButton(this IRibbonPanel ribbonPanel) where TCommand : class, IExternalCommand, IRibbonButton, new()
+ {
+ ribbonPanel.AddPushButton();
+ return ribbonPanel;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static IRibbonPanel AddSeparator(this IRibbonPanel ribbonPanel)
+ {
+ ribbonPanel.AddSeparator();
+ return ribbonPanel;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void AddSlideOut(this IRibbonPanel ribbonPanel, Action handle)
+ {
+ ribbonPanel.AddSlideOut();
+ handle?.Invoke(ribbonPanel);
+ }
+}
diff --git a/src/Ribbon/RibbonTab.cs b/src/Ribbon/RibbonTab.cs
deleted file mode 100644
index 272337f..0000000
--- a/src/Ribbon/RibbonTab.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Tuna.Revit.Extension;
-
-internal class RibbonTab : IRibbonTab
-{
- public string TabName { get; internal set; }
-
- public void CreateRibbonPanel(string name, Action action)
- {
- throw new NotImplementedException();
- }
-}
diff --git a/src/TestCommand.cs b/src/TestCommand.cs
index c784b12..3bbeb86 100644
--- a/src/TestCommand.cs
+++ b/src/TestCommand.cs
@@ -43,7 +43,20 @@ public Result OnShutdown(UIControlledApplication application)
public Result OnStartup(UIControlledApplication application)
{
- //application.CreateRibbonTab("ad", tab => tab.CreateRibbonPanel("", panel => panel);
+ application.CreateRibbonTab("tuna", tab => tab
+
+ .CreateRibbonPanel("archi", panel => panel
+ .AddPulldownButton()
+ .AddSplitButton()
+ .AddTextBox()
+ .AddComboBox()
+ .AddSlideOut(panel => panel
+ .AddSplitButton()))
+
+ .CreateRibbonPanel("struct", panel => panel
+ .AddSplitButton()));
+
+
return Result.Succeeded;
}
}
From 1003c83ef89def23682ddc4dd59717081be37619 Mon Sep 17 00:00:00 2001
From: Shiwu <49446319+shichuyibushishiwu@users.noreply.github.com>
Date: Mon, 27 Nov 2023 08:37:32 +0800
Subject: [PATCH 5/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0options?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/Extensions/UIExtension.cs | 15 +++--
.../Abstraction/IRibbonItemsCollector.cs | 1 -
src/Ribbon/Abstraction/IRibbonPanel.cs | 2 +
src/Ribbon/Proxy/RibbonComboBoxProxy.cs | 3 +-
src/Ribbon/Proxy/RibbonElementProxy.cs | 2 +-
src/Ribbon/Proxy/RibbonPanelProxy.cs | 16 +++--
src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs | 4 +-
src/Ribbon/RibbonExtension.cs | 4 +-
src/Ribbon/RibbonOptions.cs | 17 ++++++
src/TestCommand.cs | 61 +++++++++++++++++--
10 files changed, 103 insertions(+), 22 deletions(-)
create mode 100644 src/Ribbon/RibbonOptions.cs
diff --git a/src/Extensions/UIExtension.cs b/src/Extensions/UIExtension.cs
index 64bb5dd..1416980 100644
--- a/src/Extensions/UIExtension.cs
+++ b/src/Extensions/UIExtension.cs
@@ -61,11 +61,22 @@ public static class UIExtension
public static ComboBox CreateComboBox(this RibbonPanel panel, string name, Action handle = null)
{
ArgumentNullExceptionUtils.ThrowIfNull(panel);
+
ComboBoxData combo = new ComboBoxData(name);
handle?.Invoke(combo);
return panel.AddItem(combo) as ComboBox;
}
+ public static PulldownButton CreatePulldown(this RibbonPanel panel, string name, string text, Action handle = null)
+ {
+ ArgumentNullExceptionUtils.ThrowIfNull(panel);
+
+ PulldownButtonData data = new PulldownButtonData(name, text);
+ handle?.Invoke(data);
+
+ return panel.AddItem(data) as PulldownButton;
+ }
+
///
/// 在面板上创建一个按钮
/// Create a ribbon push button on the panel
@@ -79,13 +90,9 @@ public static ComboBox CreateComboBox(this RibbonPanel panel, string name, Actio
ArgumentNullExceptionUtils.ThrowIfNull(panel);
ArgumentNullExceptionUtils.ThrowIfNull(handle);
- //实例化一个按钮的数据
PushButtonData pushButtonData = CreatePushButtonData();
-
- //用户自己添加按钮的其他数据
handle.Invoke(pushButtonData);
- //添加到面板,并返回给调用方
return panel.AddItem(pushButtonData) as PushButton;
}
diff --git a/src/Ribbon/Abstraction/IRibbonItemsCollector.cs b/src/Ribbon/Abstraction/IRibbonItemsCollector.cs
index 0ea048b..3df54e9 100644
--- a/src/Ribbon/Abstraction/IRibbonItemsCollector.cs
+++ b/src/Ribbon/Abstraction/IRibbonItemsCollector.cs
@@ -4,7 +4,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using Tuna.Revit.Extension.Ribbon.Abstraction;
using Tuna.Revit.Extension.Ribbon.Proxy;
namespace Tuna.Revit.Extension;
diff --git a/src/Ribbon/Abstraction/IRibbonPanel.cs b/src/Ribbon/Abstraction/IRibbonPanel.cs
index 0e0e7e1..98772d2 100644
--- a/src/Ribbon/Abstraction/IRibbonPanel.cs
+++ b/src/Ribbon/Abstraction/IRibbonPanel.cs
@@ -15,6 +15,8 @@ public interface IRibbonPanel
void AddSeparator();
+ void AddPushButton() where T : class, IExternalCommand, IRibbonButton, new();
+
//public void CreatePulldownButton();
//public void CreatePushButton() where TCommand : IExternalCommand;
diff --git a/src/Ribbon/Proxy/RibbonComboBoxProxy.cs b/src/Ribbon/Proxy/RibbonComboBoxProxy.cs
index 4d1018f..74e70e1 100644
--- a/src/Ribbon/Proxy/RibbonComboBoxProxy.cs
+++ b/src/Ribbon/Proxy/RibbonComboBoxProxy.cs
@@ -8,6 +8,7 @@
namespace Tuna.Revit.Extension.Ribbon.Proxy;
-internal class RibbonComboBoxProxy : RibbonElementProxy
+internal class RibbonComboBoxProxy : RibbonElementProxy, IRibbonItem
{
+ public RibbonItemType Type => RibbonItemType.ComboBox;
}
diff --git a/src/Ribbon/Proxy/RibbonElementProxy.cs b/src/Ribbon/Proxy/RibbonElementProxy.cs
index 4bb9d0d..7721180 100644
--- a/src/Ribbon/Proxy/RibbonElementProxy.cs
+++ b/src/Ribbon/Proxy/RibbonElementProxy.cs
@@ -4,7 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using Tuna.Revit.Extension.Ribbon.Abstraction;
+
namespace Tuna.Revit.Extension.Ribbon.Proxy;
diff --git a/src/Ribbon/Proxy/RibbonPanelProxy.cs b/src/Ribbon/Proxy/RibbonPanelProxy.cs
index e4cfccf..a235056 100644
--- a/src/Ribbon/Proxy/RibbonPanelProxy.cs
+++ b/src/Ribbon/Proxy/RibbonPanelProxy.cs
@@ -9,7 +9,7 @@ namespace Tuna.Revit.Extension.Ribbon.Proxy;
internal class RibbonPanelProxy : RibbonElementProxy, IRibbonPanel, IRibbonItemsCollector
{
- private readonly List _items = new List();
+ private readonly List _items = new();
public RibbonTabProxy Parent { get; internal set; }
@@ -33,16 +33,20 @@ public void AddComboBox()
}
- public void CreatePulldownButton()
+ public void AddPulldownButton(string name, string text)
{
+ PulldownButton pulldownButton = this.OriginalObject.CreatePulldown(name, text);
-
+ RibbonPulldownButtonProxy pulldownButtonProxy = new RibbonPulldownButtonProxy()
+ {
+ OriginalObject = pulldownButton,
+ Name = pulldownButton.Name,
+ Text = text
+ };
+ _items.Add(pulldownButtonProxy);
}
- public void CreatePushButton() where TCommand : IExternalCommand
- {
- }
public void CreateRadioButtonGroup()
{
diff --git a/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs b/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs
index 1f8f518..b48af7d 100644
--- a/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs
+++ b/src/Ribbon/Proxy/RibbonPulldownButtonProxy.cs
@@ -9,7 +9,7 @@ namespace Tuna.Revit.Extension.Ribbon.Proxy
{
internal class RibbonPulldownButtonProxy : RibbonElementProxy, IRibbonItem, IRibbonItemsCollector
{
- private readonly List _items = new List();
+ private readonly List _items = new();
public RibbonItemType Type => RibbonItemType.PulldownButton;
@@ -24,7 +24,7 @@ internal class RibbonPulldownButtonProxy : RibbonElementProxy, I
_items.Add(ribbonButtonProxy);
}
-
+ public string Text { get; set; }
public IEnumerable GetItems() => _items;
}
diff --git a/src/Ribbon/RibbonExtension.cs b/src/Ribbon/RibbonExtension.cs
index f4825fe..6d31cfe 100644
--- a/src/Ribbon/RibbonExtension.cs
+++ b/src/Ribbon/RibbonExtension.cs
@@ -74,7 +74,7 @@ public static IRibbonPanel AddSplitButton(this IRibbonPanel ribbonPanel)
}
///
- ///
+ /// 添加分割线
///
///
///
@@ -85,7 +85,7 @@ public static IRibbonPanel AddSeparator(this IRibbonPanel ribbonPanel)
}
///
- ///
+ /// 添加滑动式抽屉
///
///
///
diff --git a/src/Ribbon/RibbonOptions.cs b/src/Ribbon/RibbonOptions.cs
new file mode 100644
index 0000000..abc2f30
--- /dev/null
+++ b/src/Ribbon/RibbonOptions.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+
+namespace Tuna.Revit.Extension;
+
+internal class RibbonOptions
+{
+ public ImageSource ToolTipImage { get; set; }
+
+ public string LongDescription { get; set; }
+
+ public string ToolTip { get; set; }
+}
diff --git a/src/TestCommand.cs b/src/TestCommand.cs
index 3bbeb86..c051152 100644
--- a/src/TestCommand.cs
+++ b/src/TestCommand.cs
@@ -20,16 +20,67 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
UIDocument uiDocument = commandData.Application.ActiveUIDocument;
Document document = uiDocument.Document;
+ var cs = new List
+ {
+ BuiltInCategory.OST_PipeCurves,
+ BuiltInCategory.OST_PipeFitting,
+ BuiltInCategory.OST_PipeAccessory,
+ BuiltInCategory.OST_FlexPipeCurves,
+ BuiltInCategory.OST_Sprinklers,
+ //Equipements
+ BuiltInCategory.OST_SpecialityEquipment,
+ BuiltInCategory.OST_NurseCallDevices,
+ BuiltInCategory.OST_TelephoneDevices,
+ BuiltInCategory.OST_FireAlarmDevices,
+ BuiltInCategory.OST_GenericModel,
+ //MEP NetWork
+ BuiltInCategory.OST_FabricationPipework,
+ BuiltInCategory.OST_FabricationDuctwork,
+ BuiltInCategory.OST_FabricationHangers,
- //uiDocument.SelectElement(e => e.Category?.Id == BuiltInCategories.Door);
- //uiDocument.SelectElements(e => e.Category?.Id == BuiltInCategories.Door);
+ //CVC
+ BuiltInCategory.OST_DuctTerminal,
+ BuiltInCategory.OST_MechanicalEquipment,
+ BuiltInCategory.OST_DuctCurves,
+ BuiltInCategory.OST_DuctAccessory,
+ BuiltInCategory.OST_DuctFitting,
+ BuiltInCategory.OST_FlexDuctCurves,
- //uiDocument.SelectObject(Autodesk.Revit.UI.Selection.ObjectType.Edge, e => e.Category?.Id == BuiltInCategories.Door, "选择门边线");
-
- //uiDocument.SelectPoint();
+ //Electricite
+ BuiltInCategory.OST_Conduit,
+ BuiltInCategory.OST_CableTray,
+ BuiltInCategory.OST_ConduitFitting,
+ BuiltInCategory.OST_CableTrayFitting,
+ BuiltInCategory.OST_ElectricalEquipment,
+ BuiltInCategory.OST_Casework,
+ BuiltInCategory.OST_ElectricalFixtures,
+ //GC
+ #region GC
+ BuiltInCategory.OST_Stairs,
+
+ BuiltInCategory.OST_StructuralFoundation,
+ BuiltInCategory.OST_Ceilings,
+ BuiltInCategory.OST_Gutter,
+ BuiltInCategory.OST_StairsRailing,
+ BuiltInCategory.OST_Walls,
+ BuiltInCategory.OST_StructuralFraming,
+ BuiltInCategory.OST_CurtainWallPanels,
+ BuiltInCategory.OST_CurtainWallMullions,
+ BuiltInCategory.OST_Doors,
+ BuiltInCategory.OST_Columns,
+ BuiltInCategory.OST_StructuralColumns,
+ BuiltInCategory.OST_Floors,
+ BuiltInCategory.OST_Roofs,
+ #endregion
+ };
+ Stopwatch Stopwatch = new Stopwatch();
+ Stopwatch.Start();
+ document.GetElements(BuiltInCategory.OST_Windows,cs.ToArray());
+ Stopwatch.Stop();
+ System.Windows.MessageBox.Show(Stopwatch.Elapsed.ToString());
return Result.Succeeded;
}
}
From 6655c604bedf551995ea537f1b8615b69b19d3b6 Mon Sep 17 00:00:00 2001
From: Shiwu <49446319+shichuyibushishiwu@users.noreply.github.com>
Date: Mon, 27 Nov 2023 11:48:47 +0800
Subject: [PATCH 6/6] release v.12
---
src/TestCommand.cs | 61 +--------------------------------
src/Tuna.Revit.Extension.csproj | 2 +-
2 files changed, 2 insertions(+), 61 deletions(-)
diff --git a/src/TestCommand.cs b/src/TestCommand.cs
index c051152..46a1a5b 100644
--- a/src/TestCommand.cs
+++ b/src/TestCommand.cs
@@ -20,67 +20,8 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
UIDocument uiDocument = commandData.Application.ActiveUIDocument;
Document document = uiDocument.Document;
- var cs = new List
- {
- BuiltInCategory.OST_PipeCurves,
- BuiltInCategory.OST_PipeFitting,
- BuiltInCategory.OST_PipeAccessory,
- BuiltInCategory.OST_FlexPipeCurves,
- BuiltInCategory.OST_Sprinklers,
- //Equipements
- BuiltInCategory.OST_SpecialityEquipment,
- BuiltInCategory.OST_NurseCallDevices,
- BuiltInCategory.OST_TelephoneDevices,
- BuiltInCategory.OST_FireAlarmDevices,
- BuiltInCategory.OST_GenericModel,
- //MEP NetWork
- BuiltInCategory.OST_FabricationPipework,
- BuiltInCategory.OST_FabricationDuctwork,
- BuiltInCategory.OST_FabricationHangers,
-
- //CVC
- BuiltInCategory.OST_DuctTerminal,
- BuiltInCategory.OST_MechanicalEquipment,
- BuiltInCategory.OST_DuctCurves,
- BuiltInCategory.OST_DuctAccessory,
- BuiltInCategory.OST_DuctFitting,
- BuiltInCategory.OST_FlexDuctCurves,
-
- //Electricite
- BuiltInCategory.OST_Conduit,
- BuiltInCategory.OST_CableTray,
- BuiltInCategory.OST_ConduitFitting,
- BuiltInCategory.OST_CableTrayFitting,
- BuiltInCategory.OST_ElectricalEquipment,
- BuiltInCategory.OST_Casework,
- BuiltInCategory.OST_ElectricalFixtures,
-
- //GC
- #region GC
- BuiltInCategory.OST_Stairs,
-
- BuiltInCategory.OST_StructuralFoundation,
- BuiltInCategory.OST_Ceilings,
- BuiltInCategory.OST_Gutter,
- BuiltInCategory.OST_StairsRailing,
- BuiltInCategory.OST_Walls,
- BuiltInCategory.OST_StructuralFraming,
- BuiltInCategory.OST_CurtainWallPanels,
- BuiltInCategory.OST_CurtainWallMullions,
- BuiltInCategory.OST_Doors,
- BuiltInCategory.OST_Columns,
- BuiltInCategory.OST_StructuralColumns,
- BuiltInCategory.OST_Floors,
- BuiltInCategory.OST_Roofs,
- #endregion
- };
-
- Stopwatch Stopwatch = new Stopwatch();
- Stopwatch.Start();
- document.GetElements(BuiltInCategory.OST_Windows,cs.ToArray());
- Stopwatch.Stop();
- System.Windows.MessageBox.Show(Stopwatch.Elapsed.ToString());
+
return Result.Succeeded;
}
}
diff --git a/src/Tuna.Revit.Extension.csproj b/src/Tuna.Revit.Extension.csproj
index 4bf5419..0fea6a9 100644
--- a/src/Tuna.Revit.Extension.csproj
+++ b/src/Tuna.Revit.Extension.csproj
@@ -23,7 +23,7 @@
Tuna
Shiwu
Tuna.png
- 11
+ 12
README.md
This is an extension package for revit api.
https://github.com/shichuyibushishiwu/Tuna.Revit.Extensions/wiki