Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 66666

Re: Select point from form

$
0
0

Please try this

 

In the Form:

    public partial class CreateTextNoteForm : Form
    {
        ExternalEvent m_ex = null;
        public CreateTextNoteForm(UIApplication app, ExternalEvent exEvent)
        {
            InitializeComponent();
            m_ex = exEvent;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_ex.Raise();
        }
    }

The External command shall be:

        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        {
            _cachedCmdData = cmdData;

            try
            {
                //TODO: add your code below.

                TextInsertHandler handler = new TextInsertHandler();

                ExternalEvent exEvent = ExternalEvent.Create(handler);

                CreateTextNoteForm displayForm = new CreateTextNoteForm(cmdData.Application, exEvent);

                displayForm.Show();

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                return Result.Failed;
            }
        }

        public class TextInsertHandler : IExternalEventHandler
        {
            public String GetName()
            {
                return "R2014 External Event Sample";
            }
            public void Execute(UIApplication uiapp)
            {
                try
                {
                    using (Transaction trans = new Transaction(uiapp.ActiveUIDocument.Document, "Create Text Note"))
                    {
                        trans.Start();

                        CreateNote("test");

                        trans.Commit();
                    }
                }
                catch (Exception ex) { }

                return;
            }

        }  // class

        public static void CreateNote(String note)
        {
            try
            {
                Autodesk.Revit.DB.View curView = _cachedCmdData.Application.ActiveUIDocument.ActiveView;
                XYZ selectedPoint = _cachedCmdData.Application.ActiveUIDocument.Selection.PickPoint("Pick Note Location");
                ElementId defaultTypeId = _cachedCmdData.Application.ActiveUIDocument.Document.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);

                TextNote _TextNote = TextNote.Create(
                    _cachedCmdData.Application.ActiveUIDocument.Document,
                    curView.Id,
                    selectedPoint,
                    note,
                    defaultTypeId
                    );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }

If this is the solution you seek please mark this reply as an answer


Viewing all articles
Browse latest Browse all 66666

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>