예제 #1
0
        /// <summary>
        /// Bind to combobox's DropDownOpened Event, add new levels that created by user.
        /// </summary>
        /// <param name="evnetArgs">Autodesk.Revit.UI.Events.ComboBoxDropDownOpenedEventArgs</param>
        public void AddNewLevels(object sender, ComboBoxDropDownOpenedEventArgs args)
        {
            Autodesk.Revit.UI.ComboBox comboboxLevel = sender as Autodesk.Revit.UI.ComboBox;
            if (null == comboboxLevel)
            {
                return;
            }
            FilteredElementCollector collector = new FilteredElementCollector(uiApplication.ActiveUIDocument.Document);
            ICollection <Element>    founds    = collector.OfClass(typeof(Level)).ToElements();

            foreach (Element elem in founds)
            {
                Level level            = elem as Level;
                bool  alreadyContained = false;
                foreach (ComboBoxMember comboboxMember in comboboxLevel.GetItems())
                {
                    if (comboboxMember.Name == level.Name)
                    {
                        alreadyContained = true;
                    }
                }
                if (!alreadyContained)
                {
                    ComboBoxMemberData comboBoxMemberData = new ComboBoxMemberData(level.Name, level.Name);
                    ComboBoxMember     comboboxMember     = comboboxLevel.AddItem(comboBoxMemberData);
                    comboboxMember.Image = new BitmapImage(new Uri(Path.Combine(ButtonIconsFolder, "LevelsSelector.png"), UriKind.Absolute));
                }
            }
        }
예제 #2
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
                                                ref string message,
                                                ElementSet elements)
        {
            RibbonPanel myPanel = revit.Application.GetRibbonPanels()[0];
            //reset wall type
            RadioButtonGroup radioGroupTypeSelector =
                GetRibbonItemByName(myPanel, "WallTypeSelector") as RadioButtonGroup;

            if (null == radioGroupTypeSelector)
            {
                throw new InvalidCastException("Cannot get Wall Type selector!");
            }
            radioGroupTypeSelector.Current = radioGroupTypeSelector.GetItems()[0];

            //reset level
            Autodesk.Revit.UI.ComboBox comboboxLevel =
                GetRibbonItemByName(myPanel, "LevelsSelector") as Autodesk.Revit.UI.ComboBox;
            if (null == comboboxLevel)
            {
                throw new InvalidCastException("Cannot get Level selector!");
            }
            comboboxLevel.Current = comboboxLevel.GetItems()[0];

            //reset wall shape
            Autodesk.Revit.UI.ComboBox comboboxWallShape =
                GetRibbonItemByName(myPanel, "WallShapeComboBox") as Autodesk.Revit.UI.ComboBox;
            if (null == comboboxLevel)
            {
                throw new InvalidCastException("Cannot get wall shape combo box!");
            }
            comboboxWallShape.Current = comboboxWallShape.GetItems()[0];

            //get wall mark
            Autodesk.Revit.UI.TextBox textBox =
                GetRibbonItemByName(myPanel, "WallMark") as Autodesk.Revit.UI.TextBox;
            if (null == textBox)
            {
                throw new InvalidCastException("Cannot get Wall Mark TextBox!");
            }
            textBox.Value = "new wall";

            return(Autodesk.Revit.UI.Result.Succeeded);
        }