通过Application.GetRibbonPanels("Tab名称");得到RibbonPanel 通过IList listItem = ribbonPanel.GetItems();得到Panel中的控件


通过Application.GetRibbonPanels("Tab名称");得到RibbonPanel

通过IList<RibbonItem> listItem = ribbonPanel.GetItems();得到Panel中的控件


//得到Ribbon控件的值

[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]

public class cmdTest : IExternalCommand

{

    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)

    {

        UIApplication uiApp = commandData.Application;

        Document doc = uiApp.ActiveUIDocument.Document;

        Selection sel = uiApp.ActiveUIDocument.Selection;


        Transaction ts = new Transaction(doc, "http://revit.5d6d.com");

        ts.Start();


        RibbonPanel ribbonPanel = null;

        List<RibbonPanel> listPanel = commandData.Application.GetRibbonPanels("Tab名称");

        foreach (RibbonPanel panel in listPanel)

        {

            if (panel.Name == "RibbonPanel名称")//RibbonPanel的Name

            {

                ribbonPanel = panel;

                break;

            }

        }

        //间距

        TextBox textBox = null;

        IList<RibbonItem> listItem = ribbonPanel.GetItems();

        foreach (RibbonItem item in listItem)

        {

            if (item.Name == "txtDis")//Ribbon的Name属性

            {

                textBox = item as TextBox;

            }

        }


        TaskDialog.Show("txt", textBox.Value.ToString());


        ts.Commit();

        return Result.Succeeded;

    }

}