Ejemplo n.º 1
0
        public ExternalEventHelper(UIControlledApplication uiControlApp)
        {
            this.externalEventHandlerCommon = new ExternalEventHandlerCommon();
            this.externalEvent = Autodesk.Revit.UI.ExternalEvent.Create(this.externalEventHandlerCommon);

            this.externalEventHandlerCommon.Started += externalEventCommon_Started;
            this.externalEventHandlerCommon.End     += externalEventCommon_End;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="exEvent"></param>
 /// <param name="handler"></param>
 public Interface(UIApplication uiapp, Autodesk.Revit.UI.ExternalEvent exEvent, RequestHandler handler)
 {
     this.uiapp = uiapp;
     this.uidoc = uiapp.ActiveUIDocument;
     this.doc = uidoc.Document;
     this.exEvent = exEvent;
     this.handler = handler;
     this.famParam = new SortedList<string, FamilyParameter>();
     InitializeComponent();
     this.SetStyle(
         ControlStyles.AllPaintingInWmPaint |
         ControlStyles.UserPaint |
         ControlStyles.DoubleBuffer, true);
     this.StartPosition = FormStartPosition.Manual;
     this.Location = new System.Drawing.Point(Screen.PrimaryScreen.WorkingArea.Width - 400, Convert.ToInt32(Screen.PrimaryScreen.WorkingArea.Height * 0.5 - this.Height * 0.5));
     CollectData();
 }
 public RevitCommand(IHubProxy myHub)
 {
     externalEvent = ExternalEvent.Create(this);
     this.myHub    = myHub;
 }
Ejemplo n.º 4
0
        public bool ConnectToOpenCOVER(string host, int port, Autodesk.Revit.DB.Document doc)
        {
            document = doc;
             handler = new externalMessageHandler();
             messageEvent = Autodesk.Revit.UI.ExternalEvent.Create(handler);
             messageQueue = new Queue<COVERMessage>();

             System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Revit");

             if (0 < processes.Length)
             {
             ApplicationWindow = processes[0].MainWindowHandle;
             }
             try
             {
             if (toCOVER != null)
             {
                 messageThread.Abort(); // stop reading from the old toCOVER connection
                 toCOVER.Close();
                 toCOVER = null;
                 setConnected(false);
             }

             toCOVER = new TcpClient(host, port);
             if (toCOVER.Connected)
             {
                 // Sends data immediately upon calling NetworkStream.Write.
                 toCOVER.NoDelay = true;
                 LingerOption lingerOption = new LingerOption(false, 0);
                 toCOVER.LingerState = lingerOption;

                 NetworkStream s = toCOVER.GetStream();
                 Byte[] data = new Byte[256];
                 data[0] = 1;
                 try
                 {
                     //toCOVER.ReceiveTimeout = 1000;
                     s.Write(data, 0, 1);
                     //toCOVER.ReceiveTimeout = 10000;
                 }
                 catch (System.IO.IOException)
                 {
                     // probably socket closed
                     setConnected(false);
                     return false;
                 }

                 int numRead = 0;
                 try
                 {
                     //toCOVER.ReceiveTimeout = 1000;
                     numRead = s.Read(data, 0, 1);
                     //toCOVER.ReceiveTimeout = 10000;
                 }
                 catch (System.IO.IOException)
                 {
                     // probably socket closed
                     setConnected(false);
                     return false;
                 }

                 List<View3D> views = new List<View3D>(
             new FilteredElementCollector(doc)
               .OfClass(typeof(View3D))
               .Cast<View3D>()
               .Where<View3D>(v =>
             v.CanBePrinted && !v.IsTemplate));
                 int n = views.Count;

                 if (0 == n)
                 {
                     setConnected(false);
                     return false;
                 }
                 MessageBuffer mb = new MessageBuffer();
                 mb.add(n);
                 foreach (View3D v in views)
                 {
                     mb.add(v.Name);
                 }
                 sendMessage(mb.buf, MessageTypes.Views);

                 if (numRead == 1)
                 {
                     setConnected(true);
                     messageThread = new Thread(new ThreadStart(this.handleMessages));

                     // Start the thread
                     messageThread.Start();

                 }

                 return true;
             }
             System.Windows.Forms.MessageBox.Show("Could not connect to OpenCOVER on localhost, port 31821");
             }
             catch
             {

             setConnected(false);
             System.Windows.Forms.MessageBox.Show("Connection error while trying to connect to OpenCOVER on localhost, port 31821");
             }
             return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Form closed event handler
        /// </summary>
        /// <param name="e"></param>
        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            // we own both the event and the handler
            // we should dispose it before we are closed
            exEvent.Dispose();
            exEvent = null;
            handler = null;

            // do not forget to call the base class
            base.OnFormClosed(e);
        }
Ejemplo n.º 6
0
        public MEPUtilsChooser(Autodesk.Revit.UI.ExternalEvent exEvent,
                               ExternalEventHandler handler,
                               ModelessForms.Application thisApp)
        {
            InitializeComponent();

            m_ExEvent = exEvent;
            m_Handler = handler;
            ThisApp   = thisApp;

            //From here: http://stackoverflow.com/questions/34426888/dynamic-button-creation-placing-them-in-a-predefined-order-using-c-sharp
            //Edit the number of methods in rowCount here
            int columnCount = 1;
            int rowCount    = 3;

            tableLayoutPanel1.ColumnCount = columnCount;
            tableLayoutPanel1.RowCount    = rowCount;

            tableLayoutPanel1.ColumnStyles.Clear();
            tableLayoutPanel1.RowStyles.Clear();

            for (int i = 0; i < columnCount; i++)
            {
                tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / columnCount));
            }
            for (int i = 0; i < rowCount; i++)
            {
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / rowCount));
            }

            //Place methods to execute in this dict
            methodDict = new Dictionary <int, Func <UIApplication, Result> >
            {
                { 0, InsulationHandler.CreateAllInsulation },
                { 1, InsulationHandler.DeleteAllPipeInsulation },
                { 2, new InsulationHandler().ExecuteInsulationSettings },
                { 3, PipeCreator.CreatePipeFromConnector },
                { 4, FlangeCreator.CreateFlangeForElements },
                { 5, TotalLineLength.TotalLineLengths },
                { 6, MEPUtils.CreateInstrumentation.StartCreatingInstrumentation.StartCreating },
                { 7, MEPUtils.SupportTools.SupportToolsMain.CallForm },
                { 8, MEPUtils.MoveToDistance.MoveToDistance.Move },
                { 9, new MEPUtils.CountWelds.CountWelds().CountWeldsMethod },
                { 10, new MEPUtils.NumberStuff.NumberStuff().NumberStuffMethod }
            };

            //Place names for methods in this dict
            nameDict = new Dictionary <int, string>
            {
                { 0, "Create all insulation" },
                { 1, "Delete all insulation" },
                { 2, "Insulation settings" },
                { 3, "Create pipe from connector" },
                { 4, "Create flanges" },
                { 5, "Total length of lines" },
                { 6, "Create Instrument!" },
                { 7, "Support Tools" },
                { 8, "Move e to distance" },
                { 9, "(ctrl) Count welds" },
                { 10, "(ctrl) (Re-)Number" }
            };

            for (int i = 0; i < nameDict.Count; i++)
            {
                var b = new Button
                {
                    Text = nameDict[i],
                    Name = string.Format("b_{0}", i)
                };
                b.Click       += B_Click;
                b.Dock         = DockStyle.Fill;
                b.AutoSizeMode = 0;
                tableLayoutPanel1.Controls.Add(b);
            }
        }
Ejemplo n.º 7
0
Archivo: COVER.cs Proyecto: nixz/covise
        public bool ConnectToOpenCOVER(string host, int port, Autodesk.Revit.DB.Document doc)
        {
            document = doc;
             handler = new externalMessageHandler();
             messageEvent = Autodesk.Revit.UI.ExternalEvent.Create(handler);
             messageQueue = new Queue<COVERMessage>();

             System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Revit");
             callCounter = 0;

             if (0 < processes.Length)
             {
             ApplicationWindow = processes[0].MainWindowHandle;
             }
             try
             {
             if (toCOVER != null)
             {
                 messageThread.Abort(); // stop reading from the old toCOVER connection
                 toCOVER.Close();
                 toCOVER = null;
             }

             toCOVER = new TcpClient(host, port);
             if (toCOVER.Connected)
             {
                 // Sends data immediately upon calling NetworkStream.Write.
                 toCOVER.NoDelay = true;
                 LingerOption lingerOption = new LingerOption(false, 0);
                 toCOVER.LingerState = lingerOption;

                 NetworkStream s = toCOVER.GetStream();
                 Byte[] data = new Byte[256];
                 data[0] = 1;
                 try
                 {
                     //toCOVER.ReceiveTimeout = 1000;
                     s.Write(data, 0, 1);
                     //toCOVER.ReceiveTimeout = 10000;
                 }
                 catch (System.IO.IOException e)
                 {
                     // probably socket closed
                     return false;
                 }

                 int numRead = 0;
                 try
                 {
                     //toCOVER.ReceiveTimeout = 1000;
                     numRead = s.Read(data, 0, 1);
                     //toCOVER.ReceiveTimeout = 10000;
                 }
                 catch (System.IO.IOException e)
                 {
                     // probably socket closed
                     return false;
                 }
                 if (numRead == 1)
                 {

                     messageThread = new Thread(new ThreadStart(this.handleMessages));

                     // Start the thread
                     messageThread.Start();
                 }

                 return true;
             }
             System.Windows.Forms.MessageBox.Show("Could not connect to OpenCOVER on localhost, port 31821");
             }
             catch
             {
             System.Windows.Forms.MessageBox.Show("Connection error while trying to connect to OpenCOVER on localhost, port 31821");
             }
             return false;
        }