Skip to content

Commit

Permalink
Merge pull request #55 from shichuyibushishiwu/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
shichuyibushishiwu authored Jul 11, 2024
2 parents d25f09e + 4c0808f commit fb63637
Show file tree
Hide file tree
Showing 24 changed files with 393 additions and 131 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 shichuyibushishiwu
Copyright (c) 2024 ITuna

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ Welcome to the Tuna.Revit.Extensions wiki! This is an extension package for revi
* Revit 2022
* Revit 2023
* Revit 2024
* Revit 2025

# Install

```
> dotnet add package Tuna.Revit.Extension --version 2021.0.0
> dotnet add package Tuna.Revit.Extension --version 2025.0.17
```


2 changes: 1 addition & 1 deletion Tuna.Revit.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Rvt_24_Debug;Rvt_24_Release;
Rvt_25_Debug;Rvt_25_Release;
</Configurations>
<TunaVer>15</TunaVer>
<TunaVer>17</TunaVer>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>preview</LangVersion>
</PropertyGroup>
Expand Down
45 changes: 23 additions & 22 deletions sample/Tuna.Sample/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,30 @@ public Result OnShutdown(UIControlledApplication application)

public Result OnStartup(UIControlledApplication application)
{
var tab = application.AddRibbonTab("tuna")
.AddRibbonPanel("archi", panel =>
{
panel.AddPushButton<Commands.CommandA>()
.AddSeparator()
.AddPulldownButton("pdb", pbt => pbt
.AddPushButton<Commands.CommandA>()
.AddSeparator()
.AddPushButton<Commands.CommandB>()
.Configurate(d =>
{
d.LargeImage = "compass.png";
}))
.AddSplitButton("stb", slt => slt
.AddPushButton<Commands.CommandA>()
.AddSeparator()
.AddPushButton<Commands.CommandB>())
.AddComboBox("s", cb => cb.AddItem("dd").AddItem("ssad").OnSelectedChanged(e =>
{
var tab = application.AddRibbonTab("tuna");

}))
.AddSlideOut();
});
tab.AddRibbonPanel("archi", panel =>
{
panel.AddPushButton<Commands.CommandA>()
.AddSeparator()
.AddPulldownButton("pdb", pbt => pbt
.AddPushButton<Commands.CommandA>()
.AddSeparator()
.AddPushButton<Commands.CommandB>()
.Configurate(d =>
{
d.LargeImage = "compass.png";
}))
.AddSplitButton("stb", slt => slt
.AddPushButton<Commands.CommandA>()
.AddSeparator()
.AddPushButton<Commands.CommandB>())
.AddComboBox("s", cb => cb.AddItem("dd").AddItem("ssad").OnSelectedChanged(e =>
{

}))
.AddSlideOut();
});

return Result.Succeeded;
}
Expand Down
2 changes: 0 additions & 2 deletions sample/Tuna.Sample/Commands/CommandA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ internal class CommandB : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{


TaskDialog.Show("msg", "B");
return Result.Succeeded;
}
Expand Down
4 changes: 2 additions & 2 deletions sample/Tuna.Sample/Tuna.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@
<Version>2025.0.$(TunaVer)</Version>
</PropertyGroup>

<!--<Target Name="CopyAddin" BeforeTargets="PostBuildEvent" Condition="'$(Configuration.Contains(Debug))'">
<Target Name="CopyAddin" BeforeTargets="PostBuildEvent" Condition="'$(Configuration.Contains(Debug))'">
<ItemGroup>
<SourceFiles Include="$(ProjectDir)$(OutDir)\**\*.*"></SourceFiles>
</ItemGroup>
<Copy SourceFiles="$(ProjectDir)\Tuna.addin" DestinationFolder="C:\ProgramData\Autodesk\Revit\Addins\2020"></Copy>
<Copy SourceFiles="@(SourceFiles)" DestinationFiles="@(SourceFiles->'C:\ProgramData\Autodesk\Revit\Addins\2020\Tuna\%(RecursiveDir)%(Filename)%(Extension)')"></Copy>

</Target>-->
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/Extensions/ParameterFilterRuleFactoryExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class ParameterFilterRuleFactoryExtension
/// <returns></returns>
public static FilterRule CreateEqualsRule(ElementId id, string name, bool caseSensitive = false)
{
#if Rvt_23||Rvt_24
#if Rvt_23||Rvt_24||Rvt_25
return ParameterFilterRuleFactory.CreateEqualsRule(id, name);
#else
return ParameterFilterRuleFactory.CreateEqualsRule(id, name, caseSensitive);
Expand Down
26 changes: 22 additions & 4 deletions src/Ribbon/RibbonHost.cs → src/RevitApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@

namespace Tuna.Revit.Extension;

internal class RibbonHost
/// <summary>
/// 应用程序上下文
/// </summary>
public class RevitApplicationContext
{
private Assembly _assembly;
private bool _isValid;

/// <summary>
/// 默认值
/// </summary>
public static RibbonHost Default { get; } = new RibbonHost();
public static RevitApplicationContext Instance { get; } = new RevitApplicationContext();

RibbonHost() { }
RevitApplicationContext() { }

/// <summary>
/// 当前加载的插件的程序集
/// </summary>
public Assembly Assembly
{
get => _assembly;
Expand All @@ -30,16 +36,28 @@ internal set
{
_assembly = value;
_isValid = true;
InstallPath = $"{Directory.GetParent(_assembly?.Location).FullName}//Assets//Icon";
InstallPath = @$"{Directory.GetParent(_assembly?.Location).FullName}\Assets\Icon";
}
}
}

/// <summary>
/// Revit <see cref="Autodesk.Revit.UI.UIControlledApplication"/> 实例
/// </summary>
public UIControlledApplication UIControlledApplication { get; internal set; }

/// <summary>
/// Revit <see cref="Autodesk.Revit.UI.UIApplication"/> 实例
/// </summary>
public UIApplication UIApplication { get; internal set; }

/// <summary>
/// 上下文是否有效
/// </summary>
public bool IsVaild => _isValid;

/// <summary>
/// 当前加载的插件的安装位置
/// </summary>
public string InstallPath { get; set; }
}
97 changes: 97 additions & 0 deletions src/RevitApplicationEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tuna.Revit.Extension;

/// <summary>
/// Revit application events
/// </summary>
public class RevitApplicationEvent
{
private readonly UIControlledApplication _application;

/// <summary>
/// Initialize revit application event
/// </summary>
/// <param name="uIControlledApplication"></param>
public RevitApplicationEvent(UIControlledApplication uIControlledApplication)
{
_application = uIControlledApplication;
uIControlledApplication.ApplicationClosing += UIControlledApplication_ApplicationClosing;
uIControlledApplication.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized;


#if !Rvt_23_Before
uIControlledApplication.SelectionChanged += UIControlledApplication_SelectionChanged;
#endif

#if !Rvt_24_Before
uIControlledApplication.ThemeChanged += UIControlledApplication_ThemeChanged;
#endif
}

private void ControlledApplication_ApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e) { }

#if !Rvt_24_Before
private void UIControlledApplication_ThemeChanged(object sender, Autodesk.Revit.UI.Events.ThemeChangedEventArgs e)
{
OnThemeChanged(sender);
}
#endif

#if !Rvt_23_Before
private void UIControlledApplication_SelectionChanged(object sender, Autodesk.Revit.UI.Events.SelectionChangedEventArgs e)
{
OnApplicationSelectionChanged(sender, new SelectionChangedEventArgs(e));
}
#endif

private void UIControlledApplication_ApplicationClosing(object sender, Autodesk.Revit.UI.Events.ApplicationClosingEventArgs e)
{
OnApplicationClosing(sender, e);
_application.ApplicationClosing -= UIControlledApplication_ApplicationClosing;
_application.ControlledApplication.ApplicationInitialized -= ControlledApplication_ApplicationInitialized;

#if !Rvt_23_Before
_application.SelectionChanged -= UIControlledApplication_SelectionChanged;
#endif

#if !Rvt_24_Before
_application.ThemeChanged -= UIControlledApplication_ThemeChanged;
#endif
}

/// <summary>
/// 当应用初始化后触发的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e) { }

/// <summary>
/// 当应用关闭时触发的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationClosing(object sender, Autodesk.Revit.UI.Events.ApplicationClosingEventArgs e) { }

/// <summary>
/// 当主题改变触发的事件
/// </summary>
/// <remarks>仅适用于 Revti 2024 以上的版本</remarks>
/// <param name="sender"></param>
protected virtual void OnThemeChanged(object sender) { }

/// <summary>
/// 当应用程序的选择对象变更后触发的事件
/// </summary>
/// <remarks>仅适用于 Revti 2023 以上的版本</remarks>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnApplicationSelectionChanged(object sender, SelectionChangedEventArgs e) { }
}
8 changes: 4 additions & 4 deletions src/Ribbon/Abstraction/IRibbonComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
namespace Tuna.Revit.Extension;

/// <summary>
///
/// 下拉选项
/// </summary>
public interface IRibbonComboBox : IRibbonItem
{
/// <summary>
///
/// 添加成员
/// </summary>
/// <param name="title"></param>
/// <returns></returns>
IRibbonComboBox AddItem(string title);

/// <summary>
///
/// 添加多个成员
/// </summary>
/// <param name="titles"></param>
/// <returns></returns>
IRibbonComboBox AddItems(params string[] titles);

/// <summary>
///
/// 添加分割线
/// </summary>
/// <returns></returns>
IRibbonComboBox AddSeparator();
Expand Down
16 changes: 11 additions & 5 deletions src/Ribbon/Abstraction/IRibbonPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,38 @@ public interface IRibbonPanel : IRibbonPushButtonContainer<IRibbonPanel>
/// </summary>
/// <param name="title"></param>
/// <param name="handle"></param>
/// <returns></returns>
/// <returns>当前面板</returns>
IRibbonPanel AddPulldownButton(string title, Action<IRibbonPulldownButton> handle = null);

/// <summary>
/// 添加下拉按钮
/// </summary>
/// <param name="title"></param>
/// <param name="handle"></param>
/// <returns></returns>
/// <returns>当前面板</returns>
IRibbonPanel AddSplitButton(string title, Action<IRibbonSplitButton> handle = null);

/// <summary>
/// 添加堆叠式按钮
/// </summary>
/// <returns>当前面板</returns>
//IRibbonPanel AddStackPanel(Action<IRibbonStackedPanel> handle = null);

/// <summary>
/// 添加单选框按钮组
/// </summary>
/// <returns></returns>
/// <returns>当前面板</returns>
IRibbonPanel AddRadioButtonGroup();

/// <summary>
/// 添加文本输入框
/// </summary>
/// <returns></returns>
/// <returns>当前面板</returns>
IRibbonPanel AddTextBox();

/// <summary>
/// 添加下拉框
/// </summary>
/// <returns></returns>
/// <returns>当前面板</returns>
IRibbonPanel AddComboBox(string name, Action<IRibbonComboBox> handle = null);
}
16 changes: 15 additions & 1 deletion src/Ribbon/Abstraction/IRibbonStackedPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@

namespace Tuna.Revit.Extension;

internal interface IRibbonStackedPanel
/// <summary>
/// 堆叠式面板
/// </summary>
public interface IRibbonStackedPanel
{
/// <summary>
///
/// </summary>
/// <typeparam name="TComandA"></typeparam>
/// <typeparam name="TCommandB"></typeparam>
/// <typeparam name="TCommandC"></typeparam>
public void AddPushButton<TComandA, TCommandB, TCommandC>();

/// <summary>
///
/// </summary>
/// <typeparam name="TComandA"></typeparam>
/// <typeparam name="TCommandB"></typeparam>
public void AddPushButton<TComandA, TCommandB>();
}
9 changes: 8 additions & 1 deletion src/Ribbon/Abstraction/IRibbonTab.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -23,4 +24,10 @@ public interface IRibbonTab : IRibbonItemsCollector
/// <param name="title">面板的标题</param>
/// <param name="handle">添加面板的元素</param>
IRibbonPanel AddRibbonPanel(string title, Action<IRibbonPanel> handle);

/// <summary>
/// 获取面板
/// </summary>
/// <returns></returns>
List<RibbonPanel> GetRibbonPanels();
}
Loading

0 comments on commit fb63637

Please sign in to comment.