Hello everyone,
I want to disable the button of an external command when the user clicks it.
After the command finished running, I want to enable back the push button.
The reason behind this is that I don't want to have several instances of the command running, only one at a time.
One way I though to to make this happen is by changing the PushButton.Enabled property of the relevant push button. To do that I need access to the commands corresponding push button.
Any Idea of how can I do that?
I will note that my externalApplication and externalCommand reside in 2 different projects, so they can't easily access each other.
Solved! Go to Solution.
Hello everyone,
I want to disable the button of an external command when the user clicks it.
After the command finished running, I want to enable back the push button.
The reason behind this is that I don't want to have several instances of the command running, only one at a time.
One way I though to to make this happen is by changing the PushButton.Enabled property of the relevant push button. To do that I need access to the commands corresponding push button.
Any Idea of how can I do that?
I will note that my externalApplication and externalCommand reside in 2 different projects, so they can't easily access each other.
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
Hi @tephraimCHQM3 ,
Are you looking for this one?
Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon;
foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs)
{
if (tab.Title.Contains("Add-Ins"))
{
foreach (Autodesk.Windows.RibbonPanel panel in tab.Panels)
{
if (panel.Source.Id == "EXTERNAL_TOOLS_PANEL")
{
panel.IsEnabled = false;
//Do your Work Here
//After completing your work
panel.IsEnabled = true;
}
}
}
}
Hi @tephraimCHQM3 ,
Are you looking for this one?
Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon;
foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs)
{
if (tab.Title.Contains("Add-Ins"))
{
foreach (Autodesk.Windows.RibbonPanel panel in tab.Panels)
{
if (panel.Source.Id == "EXTERNAL_TOOLS_PANEL")
{
panel.IsEnabled = false;
//Do your Work Here
//After completing your work
panel.IsEnabled = true;
}
}
}
}
Hello!
Probably the easiest way is using the IExternalCommandAvailability with a static variable to enable/disable your button.
The Availability of the button could be applied when um create the PushButtonData on the AvailabilityClassName property, like the ClassName property.
Here is a simple implementation of the IExternalCommandAvailability with the static Enabled
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RevitAddin
{
public class AvailableOnProjectButtonEnabled : IExternalCommandAvailability
{
public static bool Enabled { get; set; } = true;
public bool IsCommandAvailable(UIApplication uiapp, CategorySet categorySet)
{
if (uiapp.ActiveUIDocument == null) return false;
if (uiapp.ActiveUIDocument.Document == null) return false;
if (uiapp.ActiveUIDocument.Document.IsFamilyDocument) return false;
return Enabled;
}
}
}
See yaa!
Hello!
Probably the easiest way is using the IExternalCommandAvailability with a static variable to enable/disable your button.
The Availability of the button could be applied when um create the PushButtonData on the AvailabilityClassName property, like the ClassName property.
Here is a simple implementation of the IExternalCommandAvailability with the static Enabled
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RevitAddin
{
public class AvailableOnProjectButtonEnabled : IExternalCommandAvailability
{
public static bool Enabled { get; set; } = true;
public bool IsCommandAvailable(UIApplication uiapp, CategorySet categorySet)
{
if (uiapp.ActiveUIDocument == null) return false;
if (uiapp.ActiveUIDocument.Document == null) return false;
if (uiapp.ActiveUIDocument.Document.IsFamilyDocument) return false;
return Enabled;
}
}
}
See yaa!
Thanks @ricaun and @naveen.kumar.t for the answers.
Even though @ricaun answer is indeed a possible solution, the one provided by @naveen.kumar.t is more fitted to my needs.
Here is my final implementation:
public static void SetToolEnabledValue(string ribbonItemText, bool value)
{
RibbonTab ribbonTab = ComponentManager.Ribbon.Tabs
.FirstOrDefault(tab => tab.AutomationName == "TAB_NAME");
if (ribbonTab != default(RibbonTab))
{
foreach (Autodesk.Windows.RibbonPanel panel in ribbonTab.Panels)
{
foreach (Autodesk.Windows.RibbonItem ribbonItem in panel.Source.Items)
{
if (ribbonItem.AutomationName == ribbonItemText)
{
ribbonItem.IsEnabled = value;
return;
}
}
}
}
}
Thanks @ricaun and @naveen.kumar.t for the answers.
Even though @ricaun answer is indeed a possible solution, the one provided by @naveen.kumar.t is more fitted to my needs.
Here is my final implementation:
public static void SetToolEnabledValue(string ribbonItemText, bool value)
{
RibbonTab ribbonTab = ComponentManager.Ribbon.Tabs
.FirstOrDefault(tab => tab.AutomationName == "TAB_NAME");
if (ribbonTab != default(RibbonTab))
{
foreach (Autodesk.Windows.RibbonPanel panel in ribbonTab.Panels)
{
foreach (Autodesk.Windows.RibbonItem ribbonItem in panel.Source.Items)
{
if (ribbonItem.AutomationName == ribbonItemText)
{
ribbonItem.IsEnabled = value;
return;
}
}
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.