public void CreateUI()
        {
            RibbonControl rc         = Autodesk.Windows.ComponentManager.Ribbon;
            RibbonTab     primaryTab = rc.FindTab(Jpp.Ironstone.Core.Constants.IRONSTONE_TAB_ID);

            RibbonPanel       Panel  = new RibbonPanel();
            RibbonPanelSource source = new RibbonPanelSource();

            source.Title = Properties.Resources.ExtensionApplication_UI_PanelTitle;

            RibbonRowPanel column1 = new RibbonRowPanel();

            column1.IsTopJustified = true;
            column1.Items.Add(UIHelper.CreateWindowToggle(Properties.Resources.ExtensionApplication_UI_SoilMenuButton, Properties.Resources.Earth_Small, RibbonItemSize.Standard, new SoilPropertiesView(), "4c7eae1d-ce9f-4a7a-a397-584aced7983c"));
            column1.Items.Add(new RibbonRowBreak());

            RibbonSplitButton rsb = new RibbonSplitButton();

            rsb.ShowText = true;
            rsb.Items.Add(UIHelper.CreateButton("Add Tree", Properties.Resources.Tree_Small, RibbonItemSize.Standard, "S_TreeRings_New"));
            rsb.Items.Add(UIHelper.CreateButton("Copy Tree", Properties.Resources.Tree_Small, RibbonItemSize.Standard, "S_TreeRings_Copy"));
            rsb.Items.Add(UIHelper.CreateButton("Add Hedge Row", Properties.Resources.Tree_Small, RibbonItemSize.Standard, "S_Hedgerow_New"));
            column1.Items.Add(rsb);

            //Build the UI hierarchy
            source.Items.Add(column1);

            Panel.Source = source;

            primaryTab.Panels.Add(Panel);
        }
        private static void AddPanels(RibbonTab ribTab)
        {
            try
            {
                var confCuiXel = ModPlusAPI.RegistryData.Adaptation.GetCuiAsXElement("AutoCAD");

                // Проходим по группам
                if (confCuiXel != null)
                {
                    foreach (var group in confCuiXel.Elements("Group"))
                    {
                        if (group.Attribute("GroupName") == null)
                        {
                            continue;
                        }

                        // create the panel source
                        var ribSourcePanel = new RibbonPanelSource
                        {
                            Title = Language.TryGetCuiLocalGroupName(group.Attribute("GroupName")?.Value)
                        };

                        // now the panel
                        var ribPanel = new RibbonPanel
                        {
                            Source = ribSourcePanel
                        };
                        ribTab.Panels.Add(ribPanel);
                        var ribRowPanel = new RibbonRowPanel();

                        // Вводим спец.счетчик, который потребуется для разбивки по строкам
                        var nr           = 0;
                        var hasFunctions = false;

                        // Если последняя функция в группе была 32х32
                        var lastWasBig = false;

                        // Проходим по функциям группы
                        foreach (var func in group.Elements("Function"))
                        {
                            var fNameAttr = func.Attribute("Name")?.Value;
                            if (string.IsNullOrEmpty(fNameAttr))
                            {
                                continue;
                            }
                            if (LoadPluginsHelper.LoadedFunctions.Any(x => x.Name.Equals(fNameAttr)))
                            {
                                var loadedFunction = LoadPluginsHelper.LoadedFunctions.FirstOrDefault(x => x.Name.Equals(fNameAttr));
                                if (loadedFunction == null)
                                {
                                    continue;
                                }
                                hasFunctions = true;
                                if (nr == 0)
                                {
                                    ribRowPanel = new RibbonRowPanel();
                                }

                                // В зависимости от размера
                                var btnSizeAttr = func.Attribute("WH")?.Value;
                                if (string.IsNullOrEmpty(btnSizeAttr))
                                {
                                    continue;
                                }
                                #region 16
                                if (btnSizeAttr.Equals("16"))
                                {
                                    lastWasBig = false;

                                    // Если функция имеет "подфункции", то делаем SplitButton
                                    if (func.Elements("SubFunction").Any())
                                    {
                                        // Создаем SplitButton
                                        var risSplitBtn = new RibbonSplitButton
                                        {
                                            Text            = "RibbonSplitButton",
                                            Orientation     = Orientation.Horizontal,
                                            Size            = RibbonItemSize.Standard,
                                            ShowImage       = true,
                                            ShowText        = false,
                                            ListButtonStyle = Autodesk.Private.Windows.RibbonListButtonStyle.SplitButton,
                                            ResizeStyle     = RibbonItemResizeStyles.NoResize,
                                            ListStyle       = RibbonSplitButtonListStyle.List
                                        };

                                        // Добавляем в него первую функцию, которую делаем основной
                                        var ribBtn = RibbonHelpers.AddButton(
                                            loadedFunction.Name,
                                            Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                            GetSmallIcon(loadedFunction),
                                            GetBigIcon(loadedFunction),
                                            Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                            Orientation.Horizontal,
                                            Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                            loadedFunction.ToolTipHelpImage);

                                        risSplitBtn.Items.Add(ribBtn);
                                        risSplitBtn.Current = ribBtn;

                                        // Затем добавляем подфункции
                                        foreach (var subFunc in func.Elements("SubFunction"))
                                        {
                                            if (LoadPluginsHelper.LoadedFunctions.Any(x => x.Name.Equals(subFunc.Attribute("Name")?.Value)))
                                            {
                                                var loadedSubFunction = LoadPluginsHelper.LoadedFunctions
                                                                        .FirstOrDefault(x => x.Name.Equals(subFunc.Attribute("Name")?.Value));
                                                if (loadedSubFunction == null)
                                                {
                                                    continue;
                                                }
                                                risSplitBtn.Items.Add(RibbonHelpers.AddButton(
                                                                          loadedSubFunction.Name,
                                                                          Language.GetFunctionLocalName(loadedSubFunction.Name, loadedSubFunction.LName),
                                                                          GetSmallIcon(loadedSubFunction),
                                                                          GetBigIcon(loadedSubFunction),
                                                                          Language.GetFunctionShortDescription(loadedSubFunction.Name, loadedSubFunction.Description),
                                                                          Orientation.Horizontal,
                                                                          Language.GetFunctionFullDescription(loadedSubFunction.Name, loadedSubFunction.FullDescription),
                                                                          loadedSubFunction.ToolTipHelpImage));
                                            }
                                        }

                                        ribRowPanel.Items.Add(risSplitBtn);
                                    }

                                    // Если в конфигурации меню не прописано наличие подфункций, то проверяем, что они могут быть в самой функции
                                    else if (loadedFunction.SubPluginsNames.Any())
                                    {
                                        // Создаем SplitButton
                                        var risSplitBtn = new RibbonSplitButton
                                        {
                                            Text            = "RibbonSplitButton",
                                            Orientation     = Orientation.Horizontal,
                                            Size            = RibbonItemSize.Standard,
                                            ShowImage       = true,
                                            ShowText        = false,
                                            ListButtonStyle = Autodesk.Private.Windows.RibbonListButtonStyle.SplitButton,
                                            ResizeStyle     = RibbonItemResizeStyles.NoResize,
                                            ListStyle       = RibbonSplitButtonListStyle.List
                                        };

                                        // Добавляем в него первую функцию, которую делаем основной
                                        var ribBtn = RibbonHelpers.AddButton(
                                            loadedFunction.Name,
                                            Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                            GetSmallIcon(loadedFunction),
                                            GetBigIcon(loadedFunction),
                                            Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                            Orientation.Horizontal,
                                            Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                            loadedFunction.ToolTipHelpImage);
                                        risSplitBtn.Items.Add(ribBtn);
                                        risSplitBtn.Current = ribBtn;

                                        // Затем добавляем подфункции
                                        for (int i = 0; i < loadedFunction.SubPluginsNames.Count; i++)
                                        {
                                            risSplitBtn.Items.Add(RibbonHelpers.AddButton(
                                                                      loadedFunction.SubPluginsNames[i],
                                                                      Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.SubPluginsLNames[i], i + 1),
                                                                      GetSmallIconForSubFunction(loadedFunction, i),
                                                                      GetBigIconForSubFunction(loadedFunction, i),
                                                                      Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.SubDescriptions[i], i + 1),
                                                                      Orientation.Horizontal,
                                                                      Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.SubFullDescriptions[i], i + 1),
                                                                      loadedFunction.SubHelpImages[i]));
                                        }

                                        ribRowPanel.Items.Add(risSplitBtn);
                                    }

                                    // Иначе просто добавляем маленькую кнопку
                                    else
                                    {
                                        ribRowPanel.Items.Add(RibbonHelpers.AddSmallButton(
                                                                  loadedFunction.Name,
                                                                  Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                                                  GetSmallIcon(loadedFunction),
                                                                  Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                                                  Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                                                  loadedFunction.ToolTipHelpImage));
                                    }

                                    nr++;
                                    if (nr == 3 | nr == 6)
                                    {
                                        ribRowPanel.Items.Add(new RibbonRowBreak());
                                    }
                                    if (nr == 9)
                                    {
                                        ribSourcePanel.Items.Add(ribRowPanel);
                                        nr = 0;
                                    }
                                }
                                #endregion

                                // Если кнопка большая, то добавляем ее в отдельную Row Panel
                                #region 32
                                if (btnSizeAttr.Equals("32"))
                                {
                                    lastWasBig = true;
                                    if (ribRowPanel.Items.Count > 0)
                                    {
                                        ribSourcePanel.Items.Add(ribRowPanel);
                                        nr = 0;
                                    }

                                    ribRowPanel = new RibbonRowPanel();

                                    // Если функция имеет "подфункции", то делаем SplitButton
                                    if (func.Elements("SubFunction").Any())
                                    {
                                        // Создаем SplitButton
                                        var risSplitBtn = new RibbonSplitButton
                                        {
                                            Text            = "RibbonSplitButton",
                                            Orientation     = Orientation.Vertical,
                                            Size            = RibbonItemSize.Large,
                                            ShowImage       = true,
                                            ShowText        = true,
                                            ListButtonStyle = Autodesk.Private.Windows.RibbonListButtonStyle.SplitButton,
                                            ResizeStyle     = RibbonItemResizeStyles.NoResize,
                                            ListStyle       = RibbonSplitButtonListStyle.List
                                        };

                                        // Добавляем в него первую функцию, которую делаем основной
                                        var ribBtn = RibbonHelpers.AddBigButton(
                                            loadedFunction.Name,
                                            Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                            GetBigIcon(loadedFunction),
                                            Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                            Orientation.Horizontal,
                                            Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                            loadedFunction.ToolTipHelpImage);
                                        risSplitBtn.Items.Add(ribBtn);
                                        risSplitBtn.Current = ribBtn;

                                        // Затем добавляем подфункции
                                        foreach (var subFunc in func.Elements("SubFunction"))
                                        {
                                            if (LoadPluginsHelper.LoadedFunctions.Any(x => x.Name.Equals(subFunc.Attribute("Name")?.Value)))
                                            {
                                                var loadedSubFunction = LoadPluginsHelper.LoadedFunctions.FirstOrDefault(x => x.Name.Equals(subFunc.Attribute("Name")?.Value));
                                                if (loadedSubFunction == null)
                                                {
                                                    continue;
                                                }
                                                risSplitBtn.Items.Add(RibbonHelpers.AddBigButton(
                                                                          loadedSubFunction.Name,
                                                                          Language.GetFunctionLocalName(loadedSubFunction.Name, loadedSubFunction.LName),
                                                                          GetBigIcon(loadedSubFunction),
                                                                          Language.GetFunctionShortDescription(loadedSubFunction.Name, loadedSubFunction.Description),
                                                                          Orientation.Horizontal,
                                                                          Language.GetFunctionFullDescription(loadedSubFunction.Name, loadedSubFunction.FullDescription),
                                                                          loadedSubFunction.ToolTipHelpImage));
                                            }
                                        }

                                        ribRowPanel.Items.Add(risSplitBtn);
                                    }

                                    // Если в конфигурации меню не прописано наличие подфункций, то проверяем, что они могут быть в самой функции
                                    else if (loadedFunction.SubPluginsNames.Any())
                                    {
                                        // Создаем SplitButton
                                        var risSplitBtn = new RibbonSplitButton
                                        {
                                            Text            = "RibbonSplitButton",
                                            Orientation     = Orientation.Vertical,
                                            Size            = RibbonItemSize.Large,
                                            ShowImage       = true,
                                            ShowText        = true,
                                            ListButtonStyle = Autodesk.Private.Windows.RibbonListButtonStyle.SplitButton,
                                            ResizeStyle     = RibbonItemResizeStyles.NoResize,
                                            ListStyle       = RibbonSplitButtonListStyle.List
                                        };

                                        // Добавляем в него первую функцию, которую делаем основной
                                        var ribBtn = RibbonHelpers.AddBigButton(
                                            loadedFunction.Name,
                                            Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                            GetBigIcon(loadedFunction),
                                            Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                            Orientation.Horizontal,
                                            Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                            loadedFunction.ToolTipHelpImage);
                                        risSplitBtn.Items.Add(ribBtn);
                                        risSplitBtn.Current = ribBtn;

                                        // Затем добавляем подфункции
                                        for (int i = 0; i < loadedFunction.SubPluginsNames.Count; i++)
                                        {
                                            risSplitBtn.Items.Add(RibbonHelpers.AddBigButton(
                                                                      loadedFunction.SubPluginsNames[i],
                                                                      Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.SubPluginsLNames[i], i + 1),
                                                                      GetBigIconForSubFunction(loadedFunction, i),
                                                                      Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.SubDescriptions[i], i + 1),
                                                                      Orientation.Horizontal,
                                                                      Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.SubFullDescriptions[i], i + 1),
                                                                      loadedFunction.SubHelpImages[i]));
                                        }

                                        ribRowPanel.Items.Add(risSplitBtn);
                                    }

                                    // Иначе просто добавляем большую кнопку
                                    else
                                    {
                                        RibbonButton ribbonButton = RibbonHelpers.AddBigButton(
                                            loadedFunction.Name,
                                            Language.GetFunctionLocalName(loadedFunction.Name, loadedFunction.LName),
                                            GetBigIcon(loadedFunction),
                                            Language.GetFunctionShortDescription(loadedFunction.Name, loadedFunction.Description),
                                            Orientation.Vertical,
                                            Language.GetFunctionFullDescription(loadedFunction.Name, loadedFunction.FullDescription),
                                            loadedFunction.ToolTipHelpImage);
                                        ribRowPanel.Items.Add(ribbonButton);
                                    }

                                    ribSourcePanel.Items.Add(ribRowPanel);
                                }
                                #endregion
                            }
                        }// foreach functions

                        if (ribRowPanel.Items.Any() & !lastWasBig)
                        {
                            ribSourcePanel.Items.Add(ribRowPanel);
                        }

                        // Если в группе нет функций(например отключены), то не добавляем эту группу
                        if (!hasFunctions)
                        {
                            ribTab.Panels.Remove(ribPanel);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
        }