Skip to content

Commit

Permalink
implemented CmdItemExecuted and added reference to PresentationFramew…
Browse files Browse the repository at this point in the history
…ork assembly
  • Loading branch information
Jeremy Tammik committed Feb 20, 2015
1 parent 55dfd34 commit 198945e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
8 changes: 8 additions & 0 deletions BcSamples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1003,4 +1003,12 @@ Image:
C:\a\lib\revit\2015\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll
BuildingCoder.CmdListPipeSizes # version 2015.0.117.0

ADN Bc A-I
Item Executed and List Command Buttons
List all ribbon panel command buttons and subscribe to Autodesk.Windows.ComponentManager.ItemExecuted
LargeImage:
Image:
C:\a\lib\revit\2015\bc\BuildingCoder\BuildingCoder\bin\Debug\BuildingCoder.dll
BuildingCoder.CmdItemExecuted # version 2015.0.118.0


2 changes: 2 additions & 0 deletions BuildingCoder/BuildingCoder/BuildingCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="RevitAPI">
<HintPath>..\..\..\..\..\..\..\Program Files\Autodesk\Revit 2015\RevitAPI.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -133,6 +134,7 @@
<Compile Include="CmdIdling.cs" />
<Compile Include="CmdImportsInFamilies.cs" />
<Compile Include="CmdInstallLocation.cs" />
<Compile Include="CmdItemExecuted.cs" />
<Compile Include="CmdLandXml.cs" />
<Compile Include="CmdLibraryPaths.cs" />
<Compile Include="CmdLinkedFileElements.cs" />
Expand Down
108 changes: 108 additions & 0 deletions BuildingCoder/BuildingCoder/CmdItemExecuted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#region Header
//
// CmdItemExecuted.cs - list all ribbon panel command buttons and subscribe to Autodesk.Windows.ComponentManager.ItemExecuted
//
// Copyright (C) 2015 by Jeremy Tammik,
// Autodesk Inc. All rights reserved.
//
#endregion // Header

#region Namespaces
using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Windows;
#endregion // Namespaces

namespace BuildingCoder
{
[Transaction( TransactionMode.ReadOnly )]
class CmdItemExecuted : IExternalCommand
{
static bool _subscribed = false;

static void OnItemExecuted(
object sender,
Autodesk.Internal.Windows
.RibbonItemExecutedEventArgs e )
{
string s = ( null == sender )
? "<nul>"
: sender.ToString();

Autodesk.Windows.RibbonItem parent = e.Parent;

Debug.Print(
"OnItemExecuted: {0} '{1}' in '{2}' cookie {3}",
s, parent.AutomationName,
e.Item.AutomationName, e.Item.Cookie );
}

public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements )
{
if( _subscribed )
{
Autodesk.Windows.ComponentManager.ItemExecuted
-= OnItemExecuted;

_subscribed = false;
}
else
{
RibbonTabCollection tabs
= ComponentManager.Ribbon.Tabs;

foreach( RibbonTab tab in tabs )
{
Debug.Print( " {0} {1} '{2}'", tab,
tab.GetType().Name, tab.AutomationName );

if( tab.KeyTip == null )
{
// This tab is user defined.

foreach( var panel in tab.Panels )
{
// Cannot convert type 'Autodesk.Windows.RibbonPanel'
// to 'Autodesk.Revit.UI.RibbonPanel' via a reference
// conversion, boxing conversion, unboxing conversion,
// wrapping conversion, or null type conversion.
//
//Autodesk.Revit.UI.RibbonPanel rp
// = panel as Autodesk.Revit.UI.RibbonPanel;

Autodesk.Windows.RibbonPanel rp
= panel as Autodesk.Windows.RibbonPanel;

Debug.Print( " {0} {1}",
panel.ToString(), panel.GetType().Name );

foreach( var item in panel.Source.Items )
{
Autodesk.Windows.RibbonItem ri = item
as Autodesk.Windows.RibbonItem;

string automationName = ri.AutomationName;

Debug.Print( " {0} {1} '{2}' {3}",
item.ToString(), item.GetType().Name,
automationName, ri.Cookie );
}
}
}
}

Autodesk.Windows.ComponentManager.ItemExecuted
+= OnItemExecuted;

_subscribed = true;
}
return Result.Succeeded;
}
}
}
5 changes: 3 additions & 2 deletions BuildingCoder/BuildingCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
// 2015-02-14 2015.0.117.3 implemented PlaceFamilyInstanceOnFace
// 2015-02-19 2015.0.117.4 updated CmdInstallLocation from Revit 2010 to 2015 and replaced TransactionMode.Automatic by ReadOnly
// 2015-02-20 2015.0.117.5 updated CmdListMarks to use TransactionMode.Manual instead of Automatic
// 2015-02-20 2015.0.118.0 updated CmdListMarks to use TransactionMode.Manual instead of Automatic
//
[assembly: AssemblyVersion( "2015.0.117.5" )]
[assembly: AssemblyFileVersion( "2015.0.117.5" )]
[assembly: AssemblyVersion( "2015.0.118.0" )]
[assembly: AssemblyFileVersion( "2015.0.118.0" )]

0 comments on commit 198945e

Please sign in to comment.