private void GenerateExampleNumbers()
        {
            string exampleText      = "";
            var    drawingHandler   = new Tekla.Structures.Drawing.DrawingHandler();
            var    selectedDrawings = drawingHandler.GetDrawingSelector().GetSelected();
            int    i = 0;

            while (selectedDrawings.MoveNext())
            {
                var currentDrawing = selectedDrawings.Current as Tekla.Structures.Drawing.Drawing;

                switch (this.title_comboBox.SelectedIndex)
                {
                case (0):
                    exampleText = exampleText + currentDrawing.Name + "\t   ->   \t" + currentDrawing.Name.Replace(this.find_textBox.Text, this.replace_textBox.Text) + "\n";
                    break;

                case (1):
                    exampleText = exampleText + currentDrawing.Title1 + "\t   ->   \t" + currentDrawing.Title1.Replace(this.find_textBox.Text, this.replace_textBox.Text) + "\n";
                    break;

                case (2):
                    exampleText = exampleText + currentDrawing.Title2 + "\t   ->   \t" + currentDrawing.Title2.Replace(this.find_textBox.Text, this.replace_textBox.Text) + "\n";
                    break;

                case (3):
                    exampleText = exampleText + currentDrawing.Title3 + "\t   ->   \t" + currentDrawing.Title3.Replace(this.find_textBox.Text, this.replace_textBox.Text) + "\n";
                    break;

                default:
                    try
                    {
                        string udaName = new UDAHandler().GetUDAByIndex(this.title_comboBox.SelectedIndex - 4);

                        if (udaName != "")
                        {
                            string udaValue = "";
                            if (currentDrawing.GetUserProperty(udaName, ref udaValue))
                            {
                                exampleText = exampleText + udaValue + "\t   ->   \t" + udaValue.Replace(this.find_textBox.Text, this.replace_textBox.Text) + "\n";
                            }
                        }
                    }
                    catch (Exception) { }
                    break;
                }

                if (i > 5)
                {
                    break;
                }
                i++;
            }

            this.example_label.Text = exampleText;
        }
        private void FillTitleCombobox()
        {
            this.title_comboBox.Items.Clear();
            //DO NOT CHANGE THIS CODE
            this.title_comboBox.Items.Add("NAME");
            this.title_comboBox.Items.Add("TITLE1");
            this.title_comboBox.Items.Add("TITLE2");
            this.title_comboBox.Items.Add("TITLE3");

            //This try is stupid but i dont know how to test it
            try
            {
                var udaLabels = new UDAHandler().GetAllUDALabels();
                this.title_comboBox.Items.AddRange(udaLabels.ToArray());
            }
            catch (Exception) { }
        }
        public override bool Run(List <InputDefinition> Input)
        {
            GetValuesFromDialog();
            int succesfulModified = 0;

            var selectedDrawings = new Tekla.Structures.Drawing.DrawingHandler().GetDrawingSelector().GetSelected();
            var drawingsCount    = selectedDrawings.GetSize();

            if (drawingsCount == 0)
            {
                MessageBox.Show("No drawings selected", "No drawings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            DialogResult result = MessageBox.Show(
                "Are you sure do you want to change attributes in " + selectedDrawings.GetSize() + " drawings?",
                "Are you sure ?",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2
                );

            if (result == DialogResult.Yes)
            {
                var progress = new Tekla.Structures.Model.Operations.Operation.ProgressBar();

                var stopwatch = new System.Diagnostics.Stopwatch();
                try
                {
                    progress.Display(10, "Task is in progress", "Task is in progress", "Cancel", " ");
                    stopwatch.Start();
                    int    checkedDrawings = 0;
                    double medTimeForOne   = 0;

                    while (selectedDrawings.MoveNext())
                    {
                        if (progress.Canceled())
                        {
                            break;
                        }

                        var  currentDrawing = selectedDrawings.Current as Tekla.Structures.Drawing.Drawing;
                        bool modified       = false;

                        switch (_Title)
                        {
                        case (0):
                            if (currentDrawing.Name != currentDrawing.Name.Replace(_Find, _Replace))
                            {
                                currentDrawing.Name = currentDrawing.Name.Replace(_Find, _Replace);
                                modified            = true;
                            }
                            break;

                        case (1):
                            if (currentDrawing.Title1 != currentDrawing.Title1.Replace(_Find, _Replace))
                            {
                                currentDrawing.Title1 = currentDrawing.Title1.Replace(_Find, _Replace);
                                modified = true;
                            }
                            break;

                        case (2):
                            if (currentDrawing.Title2 != currentDrawing.Title2.Replace(_Find, _Replace))
                            {
                                currentDrawing.Title2 = currentDrawing.Title2.Replace(_Find, _Replace);
                                modified = true;
                            }
                            break;

                        case (3):
                            if (currentDrawing.Title3 != currentDrawing.Title3.Replace(_Find, _Replace))
                            {
                                currentDrawing.Title3 = currentDrawing.Title3.Replace(_Find, _Replace);
                                modified = true;
                            }
                            break;

                        default:
                            try
                            {
                                var udaHandler = new UDAHandler();
                                var udaName    = udaHandler.GetUDAByIndex(_Title - 4);

                                if (udaName != "")
                                {
                                    //I dont want to change other types than string because it might be wrong
                                    string udaStringValue = "";
                                    if (currentDrawing.GetUserProperty(udaName, ref udaStringValue))
                                    {
                                        if (udaStringValue != udaStringValue.Replace(_Find, _Replace))
                                        {
                                            modified = currentDrawing.SetUserProperty(udaName, udaStringValue.Replace(_Find, _Replace));
                                        }
                                    }
                                }
                            }
                            catch (Exception) { }
                            break;
                        }

                        if (modified)
                        {
                            currentDrawing.Modify();
                            succesfulModified++;
                        }
                        checkedDrawings++;
                        medTimeForOne = stopwatch.Elapsed.TotalMinutes / checkedDrawings;
                        progress.SetProgress(checkedDrawings + "/" + drawingsCount + "\t" + Math.Round(medTimeForOne * (drawingsCount - checkedDrawings)) + " minutes left", 100 * checkedDrawings / drawingsCount);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    progress.Close();
                    stopwatch.Stop();
                    MessageBox.Show("Task has been completed.\nModified drawings: " + succesfulModified.ToString() + ".\nTime elapsed: " + Math.Round(stopwatch.Elapsed.TotalSeconds).ToString() + " seconds");
                }
            }
            return(true);
        }