Skip to content

Commit

Permalink
Merge pull request #35 from shichuyibushishiwu/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
shichuyibushishiwu authored Nov 27, 2023
2 parents f7af8cc + 6655c60 commit bf1e715
Show file tree
Hide file tree
Showing 25 changed files with 671 additions and 151 deletions.
4 changes: 3 additions & 1 deletion sample/Tuna.Sample/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public Result OnShutdown(UIControlledApplication application)

public Result OnStartup(UIControlledApplication application)
{
throw new NotImplementedException();


return Result.Succeeded;
}
}
}
6 changes: 3 additions & 3 deletions sample/Tuna.Sample/Commands/ElementFilterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);


Expand All @@ -77,7 +77,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
uIDocument.SelectElement(BuiltInCategory.OST_Walls, "选择墙体");






Expand Down
19 changes: 16 additions & 3 deletions sample/Tuna.Sample/Commands/SelectionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,40 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Tuna.Revit.Extension;


namespace Tuna.Sample.Commands
{
/// <summary>
///
/// </summary>
/// <remarks></remarks>
[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<Reference> 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;
}
Expand Down
46 changes: 36 additions & 10 deletions src/Constants/BuiltInCategories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -569,12 +565,6 @@ public class BuiltInCategories
/// </summary>
public static ElementId DuctLinings { get; set; } = new ElementId(BuiltInCategory.OST_DuctLinings);

/// <summary>
/// 部件标记
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_AssemblyTags"/></para>
/// </summary>
public static ElementId AssemblyTags { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyTags);

/// <summary>
/// 零件标记
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_PartTags"/></para>
Expand Down Expand Up @@ -1559,6 +1549,42 @@ public class BuiltInCategories
/// </summary>
public static ElementId WireTags { get; set; } = new ElementId(BuiltInCategory.OST_WireTags);

/// <summary>
/// 部件
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_Assemblies"/></para>
/// </summary>
public static ElementId Assemblies { get; set; } = new ElementId(BuiltInCategory.OST_Assemblies);

/// <summary>
/// 部件原点
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_AssemblyOrigin"/></para>
/// </summary>
public static ElementId AssemblyOrigin { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin);

/// <summary>
///
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_AssemblyOrigin_Lines"/></para>
/// </summary>
public static ElementId AssemblyOrigin_Lines { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin_Lines);

/// <summary>
///
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_AssemblyOrigin_Planes"/></para>
/// </summary>
public static ElementId AssemblyOrigin_Planes { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin_Planes);

/// <summary>
///
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_AssemblyOrigin_Points"/></para>
/// </summary>
public static ElementId AssemblyOrigin_Points { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyOrigin_Points);

/// <summary>
/// 部件标记
/// <para><see cref="Autodesk.Revit.DB.BuiltInCategory.OST_AssemblyTags"/></para>
/// </summary>
public static ElementId AssemblyTags { get; set; } = new ElementId(BuiltInCategory.OST_AssemblyTags);

/// <summary>
/// 根据视图的规程过滤出可见性相关的类别<see cref="Autodesk.Revit.DB.ElementId"/>
/// <para>Get category <see cref="Autodesk.Revit.DB.ElementId"/> by <see cref="Autodesk.Revit.DB.ViewDiscipline"/></para>
Expand Down
1 change: 1 addition & 0 deletions src/Constants/BuiltInParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class View
/// VIEW_SCALE
/// </summary>
public static ElementId Scale { get; } = new ElementId(BuiltInParameter.VIEW_SCALE);


}

Expand Down
2 changes: 1 addition & 1 deletion src/Data/SelectionFilters/SelectionFilterExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public GeometrySelectionFilter(Document document, IEnumerable<ElementId> element
public GeometrySelectionFilter(Document document, BuiltInCategory builtInCategory, IEnumerable<ElementId> elementIds = null, Func<GeometryObject, bool> filterCodition = null)
{
_document = document;
_builtInCategory = builtInCategory;
_builtInCategory = builtInCategory;
_elementIds = elementIds;
_filterCodition = filterCodition;
}
Expand Down
199 changes: 114 additions & 85 deletions src/Extensions/UIExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,124 @@
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;

/// <summary>
/// Revit ribbon ui extensions
/// </summary>
public static class UIExtension
{
static PushButtonData CreatePushButtonData<T>(string text = null) where T : class, new()
{
//按钮的类型
Type commandType = typeof(T);

//按钮的名称
string name = commandType.Name;

//实例化一个按钮的数据
return new PushButtonData($"btn_{name}", text ?? name, commandType.Assembly.Location, commandType.FullName);
}

static PushButtonData CreatePushButtonData<T>() where T : class, IRibbonButton, new()
{
//创建抽象按钮的实例
IRibbonButton button = Activator.CreateInstance<T>();

//实例化一个按钮的数据
PushButtonData pushButtonData = CreatePushButtonData<T>(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);

return pushButtonData;
}


public static ComboBox CreateComboBox(this RibbonPanel panel, string name, Action<ComboBoxData> 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<PulldownButtonData> handle = null)
{
ArgumentNullExceptionUtils.ThrowIfNull(panel);

PulldownButtonData data = new PulldownButtonData(name, text);
handle?.Invoke(data);

return panel.AddItem(data) as PulldownButton;
}

/// <summary>
/// 在面板上创建一个按钮
/// <para>Create a ribbon push button on the panel</para>
/// </summary>
/// <typeparam name="T">外部命令,必须是一个自定义类型,且继承于<see cref="Autodesk.Revit.UI.IExternalCommand"/>,且必须存在一个无参的构造函数</typeparam>
/// <param name="panel">要添加按钮的面板</param>
/// <param name="handle">对按钮的参数进行赋值</param>
/// <returns>创建的按钮</returns>
public static PushButton CreatePushButton<T>(this RibbonPanel panel, Action<PushButtonData> handle) where T : class, IExternalCommand, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(panel);
ArgumentNullExceptionUtils.ThrowIfNull(handle);

PushButtonData pushButtonData = CreatePushButtonData<T>();
handle.Invoke(pushButtonData);

return panel.AddItem(pushButtonData) as PushButton;
}

/// <summary>
/// 在面板上创建一个按钮
/// <para>Create a ribbon push button on the panel</para>
/// </summary>
/// <typeparam name="T">外部命令,必须是一个自定义类型,且继承于<see cref="Autodesk.Revit.UI.IExternalCommand"/> 和 <see cref="IRibbonButton"/>,且必须存在一个无参的构造函数</typeparam>
/// <param name="panel">要添加按钮的面板</param>
/// <returns>创建的按钮</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static PushButton CreatePushButton<T>(this RibbonPanel panel) where T : class, IExternalCommand, IRibbonButton, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(panel);
return panel.AddItem(CreatePushButtonData<T>()) as PushButton;
}

/// <summary>
/// 在下拉按钮上创建一个按钮
/// <para>Create a ribbon push button on the panel</para>
/// </summary>
/// <typeparam name="T">外部命令,必须是一个自定义类型,且继承于<see cref="Autodesk.Revit.UI.IExternalCommand"/> 和 <see cref="IRibbonButton"/>,且必须存在一个无参的构造函数</typeparam>
/// <param name="pulldownButton">要添加按钮的下拉按钮</param>
/// <returns>创建的按钮</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static PushButton CreatePushButton<T>(this PulldownButton pulldownButton) where T : class, IExternalCommand, IRibbonButton, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(pulldownButton);
return pulldownButton.AddPushButton(CreatePushButtonData<T>());
}

/// <summary>
/// Revit ribbon ui extensions
/// 在下拉按钮上创建一个按钮
/// <para>Create a ribbon push button on the panel</para>
/// </summary>
public static class UIExtension
/// <typeparam name="T">外部命令,必须是一个自定义类型,且继承于<see cref="Autodesk.Revit.UI.IExternalCommand"/> 和 <see cref="IRibbonButton"/>,且必须存在一个无参的构造函数</typeparam>
/// <param name="splitButton">要添加按钮的下拉按钮</param>
/// <returns>创建的按钮</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static PushButton CreatePushButton<T>(this SplitButton splitButton) where T : class, IExternalCommand, IExternalCommandAvailability, IRibbonButton, new()
{
/// <summary>
/// Create ribbon push button
/// </summary>
/// <typeparam name="T">IExternalCommand</typeparam>
/// <param name="panel"></param>
/// <param name="action"></param>
/// <returns></returns>
public static RibbonPanel CreatePushButton<T>(this RibbonPanel panel, Action<PushButtonData> 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;
}

/// <summary>
/// Create a revit ribbon push button
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <returns></returns>
private static PushButtonData CreatePushButton<TCommand>() where TCommand : class, IExternalCommand, IRibbonButton, new()
{
IRibbonButton button = Activator.CreateInstance<TCommand>();
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;
}

/// <summary>
/// Create a revit ribbon push button
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <param name="panel"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static PushButton CreatePushButton<TCommand>(this RibbonPanel panel) where TCommand : class, IExternalCommand, IRibbonButton, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(panel);
return panel.AddItem(CreatePushButton<TCommand>()) as PushButton;
}

/// <summary>
/// Create a revit ribbon push button
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <param name="pulldownButton"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static PushButton CreatePushButton<TCommand>(this PulldownButton pulldownButton) where TCommand : class, IExternalCommand, IRibbonButton, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(pulldownButton);
return pulldownButton.AddPushButton(CreatePushButton<TCommand>());
}

/// <summary>
/// Create a revit ribbon push button
/// </summary>
/// <typeparam name="TCommand"></typeparam>
/// <param name="splitButton"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static PushButton CreatePushButton<TCommand>(this SplitButton splitButton) where TCommand : class, IExternalCommand, IExternalCommandAvailability, IRibbonButton, new()
{
ArgumentNullExceptionUtils.ThrowIfNull(splitButton);
return splitButton.AddPushButton(CreatePushButton<TCommand>());
}
ArgumentNullExceptionUtils.ThrowIfNull(splitButton);
return splitButton.AddPushButton(CreatePushButtonData<T>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Autodesk.Revit.UI;
using System.Drawing;

namespace Tuna.Revit.Extension.Interfaces;
namespace Tuna.Revit.Extension;

/// <summary>
/// Revit ribbon ui push button information
Expand Down
Loading

0 comments on commit bf1e715

Please sign in to comment.