Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

accessing Pushbutton of a command from inside the command

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
tephraimCHQM3
194 Views, 3 Replies

accessing Pushbutton of a command from inside the command

tephraimCHQM3
Participant
Participant

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.

0 Likes

accessing Pushbutton of a command from inside the command

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.

3 REPLIES 3
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted 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;

                            } 
                        }
                    }
                }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

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;

                            } 
                        }
                    }
                }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 4
ricaun
in reply to: tephraimCHQM3

ricaun
Advisor
Advisor

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!

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

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!

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 4 of 4

tephraimCHQM3
Participant
Participant

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.

Post to forums  

Autodesk Design & Make Report