添加项目文件。
This commit is contained in:
53
DotNet.Revit.ShortKey/CmdShortKey.cs
Normal file
53
DotNet.Revit.ShortKey/CmdShortKey.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Windows;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DotNet.Revit.ShortKey
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态设置命令控件的快捷键
|
||||
/// </summary>
|
||||
/// <seealso cref="Autodesk.Revit.UI.IExternalCommand" />
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class CmdShortKey : IExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
|
||||
{
|
||||
// 基于Revit的命令控件动态设置快捷键测试....
|
||||
|
||||
var panel = commandData.Application.CreateRibbonPanel("ShortKeyTest");
|
||||
var data = new PushButtonData("ID_BIMAPI", "ShortKey", typeof(CmdTest).Assembly.Location, typeof(CmdTest).FullName);
|
||||
var btn = panel.AddItem(data) as Autodesk.Revit.UI.RibbonButton;
|
||||
|
||||
btn.SetShortCut("BIMAPI");
|
||||
|
||||
|
||||
// 修改 门 按钮的快捷键
|
||||
|
||||
var item = Autodesk.Windows.ComponentManager.Ribbon.FindItem("ID_OBJECTS_DOOR", false);
|
||||
if (item == null)
|
||||
return Result.Succeeded;
|
||||
|
||||
item.SetShortCut("DOOR");
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
public class CmdTest : IExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Shortcut is valid!!");
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
79
DotNet.Revit.ShortKey/DotNet.Revit.ShortKey.csproj
Normal file
79
DotNet.Revit.ShortKey/DotNet.Revit.ShortKey.csproj
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BB36AF9B-E8EC-42BA-AEA8-21C7B6C94058}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DotNet.Revit.ShortKey</RootNamespace>
|
||||
<AssemblyName>DotNet.Revit.ShortKey</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AdWindows">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\AdWindows.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="RevitAPI">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\RevitAPI.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="RevitAPIUI">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\RevitAPIUI.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="UIFramework">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\UIFramework.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UIFrameworkServices">
|
||||
<HintPath>..\..\..\..\CYBIM\CYCommons\References\Revit\16\UIFrameworkServices.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CmdShortKey.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ShortKeyHelper.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
36
DotNet.Revit.ShortKey/Properties/AssemblyInfo.cs
Normal file
36
DotNet.Revit.ShortKey/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DotNet.Revit.ShortKey")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DotNet.Revit.ShortKey")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d36eef7d-e6e8-454d-8bcd-b33459a6c9cd")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
74
DotNet.Revit.ShortKey/ShortKeyHelper.cs
Normal file
74
DotNet.Revit.ShortKey/ShortKeyHelper.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UIFramework;
|
||||
using UIFrameworkServices;
|
||||
|
||||
namespace DotNet.Revit.ShortKey
|
||||
{
|
||||
public static class ShortKeyHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 基于Revit封装的RibbonButton设置其快捷键.
|
||||
/// </summary>
|
||||
/// <param name="btn">RibbonButton.</param>
|
||||
/// <param name="key">快捷键字符串.</param>
|
||||
/// <returns></returns>
|
||||
public static bool SetShortCut(this Autodesk.Revit.UI.RibbonButton btn, string key)
|
||||
{
|
||||
if (btn == null)
|
||||
return false;
|
||||
|
||||
var item = btn.GetType().InvokeMember("getRibbonItem",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
|
||||
Type.DefaultBinder, btn, null);
|
||||
|
||||
if (item == null)
|
||||
return false;
|
||||
|
||||
return (item as Autodesk.Windows.RibbonItem).SetShortCut(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 基于通用库封装的RibbonCommandItem设置其快捷键.
|
||||
/// </summary>
|
||||
/// <param name="commandItem">RibbonCommandItem.</param>
|
||||
/// <param name="key">快捷键字符串.</param>
|
||||
/// <returns></returns>
|
||||
public static bool SetShortCut(this Autodesk.Windows.RibbonItem commandItem, string key)
|
||||
{
|
||||
if (commandItem == null || string.IsNullOrEmpty(key))
|
||||
return false;
|
||||
|
||||
var parentTab = default(Autodesk.Windows.RibbonTab);
|
||||
var parentPanel = default(Autodesk.Windows.RibbonPanel);
|
||||
|
||||
Autodesk.Windows.ComponentManager.Ribbon.FindItem(commandItem.Id, false, out parentPanel, out parentTab, true);
|
||||
|
||||
if (parentTab == null || parentPanel == null)
|
||||
return false;
|
||||
|
||||
var path = string.Format("{0}>{1}", parentTab.Id, parentPanel.Source.Id);
|
||||
var cmdId = ControlHelper.GetCommandId(commandItem);
|
||||
|
||||
if (string.IsNullOrEmpty(cmdId))
|
||||
{
|
||||
cmdId = Guid.NewGuid().ToString();
|
||||
ControlHelper.SetCommandId(commandItem, cmdId);
|
||||
}
|
||||
|
||||
var shortcutItem = new ShortcutItem(commandItem.Text, cmdId, key, path);
|
||||
shortcutItem.ShortcutType = StType.RevitAPI;
|
||||
KeyboardShortcutService.applyShortcutChanges(new Dictionary<string, ShortcutItem>()
|
||||
{
|
||||
{
|
||||
cmdId,shortcutItem
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user