private void CollectViewTemplates()
        {
            try
            {
                List <ViewTemplateProperties> templates = new List <ViewTemplateProperties>();
                ViewTemplateProperties        vtp       = new ViewTemplateProperties();
                templates.Add(vtp);

                FilteredElementCollector collector    = new FilteredElementCollector(m_doc);
                List <ViewSection>       viewSections = collector.OfClass(typeof(ViewSection)).ToElements().Cast <ViewSection>().ToList();
                var sections = from section in viewSections where section.IsTemplate select section;
                if (sections.Count() > 0)
                {
                    List <ViewSection> sectionList = sections.OrderBy(view => view.Name).ToList();
                    foreach (ViewSection viewSection in sectionList)
                    {
                        vtp = new ViewTemplateProperties(viewSection);
                        templates.Add(vtp);
                    }
                }

                comboBoxViewTemplate.ItemsSource       = templates;
                comboBoxViewTemplate.DisplayMemberPath = "TemplateName";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect view templates.\n" + ex.Message, "Elevation Creator: Collect View Templates", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private bool SetToolSettings()
        {
            bool result = false;

            try
            {
                toolSettings.IsLinkedRoom = (bool)radioBttnRoomLink.IsChecked;
                toolSettings.IsLInkedWall = (bool)radioBttnWallLink.IsChecked;
                ViewFamilyType vft = (ViewFamilyType)comboBoxViewFamily.SelectedItem;
                if (null != vft)
                {
                    toolSettings.ViewFamilyId = vft.Id.IntegerValue;
                }
                ViewTemplateProperties vtp = (ViewTemplateProperties)comboBoxViewTemplate.SelectedItem;
                if (null != vtp)
                {
                    toolSettings.ViewTemplateId = vtp.TemplateId.IntegerValue;
                }

                toolSettings.ScaleByTemplate = (bool)radioBttnTemplate.IsChecked;

                int scaleVal = 0;
                if (!int.TryParse(textBoxScale.Text, out scaleVal))
                {
                    MessageBox.Show("Please enter a valid number for the scale value.", "Elevation Creator : Invalid Scale Value", MessageBoxButton.OK, MessageBoxImage.Information);
                    return(false);
                }
                toolSettings.CustomScale = scaleVal;

                int spaceAround = 0;
                if (!int.TryParse(textBoxSpace.Text, out spaceAround))
                {
                    MessageBox.Show("Please enter a valid number for the space around the views.", "Elevation Creator : Invalid Space Value", MessageBoxButton.OK, MessageBoxImage.Information);
                    return(false);
                }
                toolSettings.SpaceAround = spaceAround;

                toolSettings.AIsSelected = (bool)checkBoxA.IsChecked;
                toolSettings.BIsSelected = (bool)checkBoxB.IsChecked;
                toolSettings.CIsSelected = (bool)checkBoxC.IsChecked;
                toolSettings.DIsSelected = (bool)checkBoxD.IsChecked;

                toolSettings.PrefixSelected = (bool)checkBoxPrefix.IsChecked;
                toolSettings.PrefixText     = textBoxPrefix.Text;
                if (toolSettings.PrefixSelected && string.IsNullOrEmpty(toolSettings.PrefixText))
                {
                    MessageBox.Show("Please enter a vlid prefix text.", "Elevation Creator : Empty Prefix", MessageBoxButton.OK, MessageBoxImage.Information);
                    return(false);
                }

                toolSettings.IntermediateSelected = (bool)checkBoxIntermediate.IsChecked;
                toolSettings.IntermediateText     = comboBoxIntermediate.Text;

                toolSettings.ElevationSelected = (bool)checkBoxElevation.IsChecked;
                toolSettings.ABCDSelected      = (bool)checkBoxABCD.IsChecked;
                toolSettings.SuffixSelected    = (bool)checkBoxSuffix.IsChecked;
                toolSettings.SuffixText        = comboBoxSuffix.Text;

                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to save the settings.\n" + ex.Message, "Elevation Creator: SetToolSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(result);
        }
        private void GetToolSettings()
        {
            try
            {
                toolSettings = ElevationCreatorSettingStorageUtil.GetElevationCreatorSettings(m_doc);
                radioBttnRoomLink.IsChecked = toolSettings.IsLinkedRoom;
                radioBttnWallLink.IsChecked = toolSettings.IsLInkedWall;

                for (int i = 0; i < comboBoxViewFamily.Items.Count; i++)
                {
                    ViewFamilyType vft = comboBoxViewFamily.Items[i] as ViewFamilyType;
                    if (vft.Id.IntegerValue == toolSettings.ViewFamilyId)
                    {
                        comboBoxViewFamily.SelectedIndex = i; break;
                    }
                }

                for (int i = 0; i < comboBoxViewTemplate.Items.Count; i++)
                {
                    ViewTemplateProperties vtp = comboBoxViewTemplate.Items[i] as ViewTemplateProperties;
                    if (vtp.TemplateId.IntegerValue == toolSettings.ViewTemplateId)
                    {
                        comboBoxViewTemplate.SelectedIndex = i; break;
                    }
                }

                radioBttnTemplate.IsChecked    = toolSettings.ScaleByTemplate;
                textBoxScale.Text              = toolSettings.CustomScale.ToString();
                textBoxSpace.Text              = toolSettings.SpaceAround.ToString();
                checkBoxA.IsChecked            = toolSettings.AIsSelected;
                checkBoxB.IsChecked            = toolSettings.BIsSelected;
                checkBoxC.IsChecked            = toolSettings.CIsSelected;
                checkBoxD.IsChecked            = toolSettings.DIsSelected;
                checkBoxPrefix.IsChecked       = toolSettings.PrefixSelected;
                textBoxPrefix.Text             = toolSettings.PrefixText;
                checkBoxIntermediate.IsChecked = toolSettings.IntermediateSelected;

                for (int i = 0; i < comboBoxIntermediate.Items.Count; i++)
                {
                    string itemText = comboBoxIntermediate.Items[i].ToString();
                    if (itemText == toolSettings.IntermediateText)
                    {
                        comboBoxIntermediate.SelectedIndex = i;
                    }
                }

                checkBoxElevation.IsChecked = toolSettings.ElevationSelected;
                checkBoxABCD.IsChecked      = toolSettings.ABCDSelected;
                checkBoxSuffix.IsChecked    = toolSettings.SuffixSelected;

                for (int i = 0; i < comboBoxSuffix.Items.Count; i++)
                {
                    string itemText = comboBoxSuffix.Items[i].ToString();
                    if (itemText == toolSettings.SuffixText)
                    {
                        comboBoxSuffix.SelectedIndex = i;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get Elevation Creator settings.\n" + ex.Message, "Elevation Creator: GetToolSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }