示例#1
0
        //private void btnCancel_Click(object sender, EventArgs e)
        //{

        //    //this.Close();
        //}

        #region convertTextNotesToUpperByView
        private void convertTextNotesToUpperByView()
        {
            // Iterate through the document and find all the TextNote elements
            FilteredElementCollector collector = new FilteredElementCollector(document, document.ActiveView.Id);

            collector.OfClass(typeof(TextNote));
            if (collector.GetElementCount() == 0)
            {
                return;
            }

            // Record all TextNotes that are not yet formatted to be 'AllCaps'
            ElementSet textNotesToUpdate = new Autodesk.Revit.DB.ElementSet();

            foreach (Element element in collector)
            {
                TextNote textNote = (TextNote)element;

                // Extract the FormattedText from the TextNote
                FormattedText formattedText = textNote.GetFormattedText();

                if (formattedText.GetAllCapsStatus() != FormatStatus.All)
                {
                    textNotesToUpdate.Insert(textNote);
                }
            }

            // Check whether we found any TextNotes that need to be formatted
            if (textNotesToUpdate.IsEmpty)
            {
                //Do something if there are no notes to format
                TaskDialog.Show("Nothing to do!", "There are no Text Notes to change to uppercase!");
            }

            // Apply the 'AllCaps' formatting to the TextNotes that still need it.
            using (frmConvertTextNotes frm = new frmConvertTextNotes(document))
            {
                foreach (TextNote textNote in textNotesToUpdate)
                {
                    Autodesk.Revit.DB.FormattedText formattedText = textNote.GetFormattedText();
                    formattedText.SetAllCapsStatus(true);
                    textNote.SetFormattedText(formattedText);
                }
            }
        }
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                //Create a transaction
                Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
                documentTransaction.Start();

                System.Windows.Forms.DialogResult result;


                // create a form to display the information of view filters
                using (frmConvertTextNotes frm = new frmConvertTextNotes(commandData))
                {
                    result = frm.ShowDialog();
                }
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    documentTransaction.Commit();
                    return(Autodesk.Revit.UI.Result.Succeeded);
                }
                else
                {
                    documentTransaction.RollBack();
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }



                //return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception ex)
            {
                // If there is something wrong, give error information and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }