how to get the pushbutton which i click

how to get the pushbutton which i click

Anonymous
Not applicable
1,683 Views
2 Replies
Message 1 of 3

how to get the pushbutton which i click

Anonymous
Not applicable
//创建Panle
private void CreateRibbonPanel(UIControlledApplication application) 
{
    string tabName = "测绘院工具集";
    string panelName = "测绘院";
    string panelHelperName = "帮助信息";

    application.CreateRibbonTab(tabName);

    #region 孔洞插件

    RibbonPanel panelHole = application.CreateRibbonPanel(tabName, panelName);
    panelHole.Title = "孔洞插件";

    //自动开洞
    PushButtonData btnData1 = new PushButtonData(Properties.Resources.AutoHoleButtonName, Properties.Resources.AutoHoleButtonTitle, AddInPath, "NBGisRevit.NBGisOpeningInWallCommand");
    PushButton button1 = panelHole.AddItem(btnData1) as PushButton;
    button1.ToolTip = "自动开洞";
    button1.LongDescription = "自动开洞";
    button1.LargeImage = CommFunction.GetEmbeddedImage("NBGisRevit.Resources.Icons.qzdkd.png", ImageType.Png);
    
    #endregion
}

[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class NBGisOpeningMonitorCommand : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        try
        {
            //How to get the PushButton i clicked here?

            return Result.Succeeded;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return Result.Failed;
        }            
    }
}

 About is the code , i want to get the button i clicked in the Excute Function,because i want to change the text of the button,so how can i do this?

0 Likes
Accepted solutions (1)
1,684 Views
2 Replies
Replies (2)
Message 2 of 3

ollikat
Collaborator
Collaborator
Accepted solution

Hi

 

I think that's not directly possible...at least I couldn't figure out any way. But you could store those button objects somewhere in your application object. Furthermore you could then access / set the text for these buttons via properties/functions of the application class. You just need to figure out some convenient way how to get the instance of the application class within your command class.

0 Likes
Message 3 of 3

Revitalizer
Advisor
Advisor

Hi,

 

In the TBC blog, you can find this posting:

http://thebuildingcoder.typepad.com/blog/2011/02/pimp-my-autocad-or-revit-ribbon.html

 

if you scroll downwards, there is this:

Also, an event listener can be achieved for both CAD systems:

ComponentManager.UIElementActivated

  += new EventHandler<Autodesk.Windows

    .UIElementActivatedEventArgs>(

      ComponentManager_UIElementActivated );

 

void ComponentManager_UIElementActivated(

  object sender,

  Autodesk.Windows.UIElementActivatedEventArgs e )

{

  // e.UiElement.PersistId says which item has been pressed

}

 

This way, you may be notified which button is clicked.

 

Best regards,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes