示例#1
0
 /// <summary>
 /// Implement this method as an external command for Revit.
 /// </summary>
 /// <param name="commandData">An object that is passed to the external application
 /// which contains data related to the command,
 /// such as the application object and active view.</param>
 /// <param name="message">A message that can be set by the external application
 /// which will be displayed if a failure or cancellation is returned by
 /// the external command.</param>
 /// <param name="elements">A set of elements to which the external application
 /// can add elements that are to be highlighted in case of failure or cancellation.</param>
 /// <returns>Return the status of the external command.
 /// A result of Succeeded means that the API external method functioned as expected.
 /// Cancelled can be used to signify that the user cancelled the external operation
 /// at some point. Failure should be returned if the application is unable to proceed with
 /// the operation.</returns>
 public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                         ref string message,
                                         ElementSet elements)
 {
     try
     {
         Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
         documentTransaction.Start();
         using (SpotDimensionInfoDlg infoForm = new SpotDimensionInfoDlg(commandData))
         {
             //Highlight the selected spotdimension
             if (infoForm.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
                 infoForm.SelectedSpotDimension != null)
             {
                 elements.Insert(infoForm.SelectedSpotDimension);
                 message = "High light the selected SpotDimension";
                 return(Autodesk.Revit.UI.Result.Failed);
             }
         }
         documentTransaction.Commit();
         return(Autodesk.Revit.UI.Result.Succeeded);
     }
     catch (Exception ex)
     {
         // If there are something wrong, give error information and return failed
         message = ex.Message;
         return(Autodesk.Revit.UI.Result.Failed);
     }
 }
示例#2
0
        int m_numberOfLayers;   // number of Structure Layers

        #endregion


        #region Interface implementation
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            try
            {
                // function initialization and find out a slab's Level, Type name, and set the Span Direction properties.
                bool isInitialization = this.Initialize(revit);
                if (false == isInitialization)
                {
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // show a displayForm to display the properties of the slab
                SlabPropertiesForm slabForm = new SlabPropertiesForm(this);
                if (DialogResult.OK != slabForm.ShowDialog())
                {
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }
            }
            catch (Exception displayProblem)
            {
                TaskDialog.Show("Revit", displayProblem.ToString());
                return(Autodesk.Revit.UI.Result.Failed);
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#3
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData cmdData, ref string msg, ElementSet elems)
        {
            Autodesk.Revit.UI.Result result;

            try
            {
                Snoop.CollectorExts.CollectorExt.m_app       = cmdData.Application; // TBD: see note in CollectorExt.cs
                Snoop.CollectorExts.CollectorExt.m_activeDoc = cmdData.Application.ActiveUIDocument.Document;

                // iterate over the collection and put them in an ArrayList so we can pass on
                // to our Form
                Autodesk.Revit.DB.Document doc = cmdData.Application.ActiveUIDocument.Document;
                if (doc.ActiveView == null)
                {
                    TaskDialog.Show("RevitLookup", "The document must have an active view!");
                    return(Result.Cancelled);
                }

                Snoop.Forms.Objects form = new Snoop.Forms.Objects(doc.ActiveView);
                form.ShowDialog();

                result = Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (System.Exception e)
            {
                msg    = e.Message;
                result = Autodesk.Revit.UI.Result.Failed;
            }

            return(result);
        }
示例#4
0
      /// <summary>
      /// Implement this method as an external command for Revit.
      /// </summary>
      /// <param name="commandData">An object that is passed to the external application 
      /// which contains data related to the command, 
      /// such as the application object and active view.</param>
      /// <param name="message">A message that can be set by the external application 
      /// which will be displayed if a failure or cancellation is returned by 
      /// the external command.</param>
      /// <param name="elements">A set of elements to which the external application 
      /// can add elements that are to be highlighted in case of failure or cancellation.</param>
      /// <returns>Return the status of the external command. 
      /// A result of Succeeded means that the API external method functioned as expected. 
      /// Cancelled can be used to signify that the user cancelled the external operation 
      /// at some point. Failure should be returned if the application is unable to proceed with 
      /// the operation.</returns>
      public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
      {
         m_application = commandData.Application;
         m_document = m_application.ActiveUIDocument;

         try
         {
            // Select elements. Click "Finish" or "Cancel" buttons on the dialog bar to complete the selection operation.
            List<ElementId> elemDeleteList = new List<ElementId>();
            IList<Reference> eRefList = m_document.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, "Please pick some element to delete. ESC for Cancel.");
            foreach (Reference eRef in eRefList)
            {
               if (eRef != null && eRef.ElementId != ElementId.InvalidElementId)
               {
                  elemDeleteList.Add(eRef.ElementId);
               }
            }

            // Delete elements
            m_document.Document.Delete(elemDeleteList);
            return Result.Succeeded;
         }
         catch (Exceptions.OperationCanceledException)
         {
            // Selection Cancelled.
            return Result.Cancelled;
         }
         catch (Exception ex)
         {
            // If any error, give error information and return failed
            message = ex.Message;
            return Result.Failed;
         }
      }
示例#5
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                m_application = commandData.Application;
                m_document    = m_application.ActiveUIDocument;

                // Pick a point on wall face.
                Reference pickedRefer = PickPointOnWallFace();
                if (pickedRefer != null)
                {
                    Transaction trans = new Transaction(m_document.Document, "PlaceAtPointOnWallFace");
                    trans.Start();
                    // Place the 36" x 48" window at the reference.
                    PlaceWindowAtReference(pickedRefer);
                    trans.Commit();
                }
                else
                {
                    return(Result.Cancelled);
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return(Result.Failed);
            }
        }
示例#6
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                SelectionManager manager = new SelectionManager(commandData);
                // Create a form to select objects.
                DialogResult result = System.Windows.Forms.DialogResult.None;
                while (result == DialogResult.None || result == DialogResult.Retry)
                {
                    // Picking Objects.
                    if (result == DialogResult.Retry)
                    {
                        manager.SelectObjects();
                    }
                    // Show the dialog.
                    using (SelectionForm selectionForm = new SelectionForm(manager))
                    {
                        result = selectionForm.ShowDialog();
                    }
                }

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
示例#7
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message,
                                                ElementSet elements)
        {
            // Quit if active document is null
            if (null == commandData.Application.ActiveUIDocument.Document)
            {
                message = "Active document is null.";
                return(Autodesk.Revit.UI.Result.Failed);
            }

            try
            {
                FamilyInstanceCreator creator = new FamilyInstanceCreator(commandData.Application);

                // an option dialog for user choosing based type of creating
                BasedTypeForm baseTypeform = new BasedTypeForm();
                if (DialogResult.OK == baseTypeform.ShowDialog())
                {
                    PlaceFamilyInstanceForm placeForm = new PlaceFamilyInstanceForm(creator
                                                                                    , baseTypeform.BaseType);
                    placeForm.ShowDialog();
                }

                // if everything goes well, return succeeded.
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
示例#8
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="revit">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData revit,
                                                ref string message,
                                                ElementSet elements)
        {
            try
            {
                m_application = revit.Application.Application;
                m_document    = revit.Application.ActiveUIDocument.Document;

                // it can support in truss family document only
                if (!m_document.IsFamilyDocument ||
                    m_document.OwnerFamily.FamilyCategory.Id.IntegerValue != (int)BuiltInCategory.OST_Truss)
                {
                    message = "Cannot execute truss creation in non-truss family document";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                m_appCreator    = m_application.Create;
                m_familyCreator = m_document.FamilyCreate;

                Transaction newTran = new Transaction(m_document);
                newTran.Start("NewTrussCurve");

                // Start the truss creation
                MakeNewTruss();

                newTran.Commit();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#9
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication application = commandData.Application;
            m_docment = application.ActiveUIDocument.Document;
            try
            {
                // user should select one slab firstly.
                if (application.ActiveUIDocument.Selection.Elements.Size == 0)
                {
                    TaskDialog.Show("Revit", "Please select one slab firstly.", TaskDialogCommonButtons.Ok);
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }

                // get the selected slab and show its span direction
                ElementSet         elementSet = application.ActiveUIDocument.Selection.Elements;
                ElementSetIterator elemIter   = elementSet.ForwardIterator();
                elemIter.Reset();
                while (elemIter.MoveNext())
                {
                    Floor floor = elemIter.Current as Floor;
                    if (floor != null)
                    {
                        GetSpanDirectionAndSymobls(floor);
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                return(Autodesk.Revit.UI.Result.Failed);
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#10
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction tranSample = null;

            try
            {
                tranSample = new Transaction(commandData.Application.ActiveUIDocument.Document, "Sample Start");
                tranSample.Start();
                // create a form to display the information of Revit rooms and xls based rooms
                using (RoomScheduleForm infoForm = new RoomScheduleForm(commandData))
                {
                    infoForm.ShowDialog();
                }
                tranSample.Commit();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception ex)
            {
                if (null != tranSample)
                {
                    tranSample.RollBack();
                }
                // if there are something wrong, give error information and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
示例#11
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message,
                                                ElementSet elements)
        {
            try
            {
                Transaction tran = new Transaction(commandData.Application.ActiveUIDocument.Document, "Rooms");
                tran.Start();
                // create a new instance of class data
                RoomsData data = new RoomsData(commandData);

                // create a form to display the information of rooms
                using (roomsInformationForm infoForm = new roomsInformationForm(data))
                {
                    infoForm.ShowDialog();
                }
                tran.Commit();
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception ex)
            {
                // If there are something wrong, give error information and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
示例#12
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if (null == commandData)
            {
                throw new ArgumentNullException("commandData");
            }

            Document doc  = commandData.Application.ActiveUIDocument.Document;
            ViewsMgr view = new ViewsMgr(doc);

            AllViewsForm dlg = new AllViewsForm(view);

            try
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    return(view.GenerateSheet(doc));
                }
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#13
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message,
                                                ElementSet elements)
        {
            try
            {
                Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
                documentTransaction.Start();
                // Get the application of revit
                Autodesk.Revit.UI.UIApplication revit = commandData.Application;

                // New a real operation class.
                ModelLines deal = new ModelLines(revit);

                // The main deal operation
                deal.Run();
                documentTransaction.Commit();

                // if everything goes well, return succeeded.
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
示例#14
0
        Stream(ArrayList data, Autodesk.Revit.UI.ExternalCommandData extCmd)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(Autodesk.Revit.UI.ExternalCommandData)));

            data.Add(new Snoop.Data.Object("Application", extCmd.Application));
            data.Add(new Snoop.Data.Enumerable("Data", extCmd.JournalData));
            data.Add(new Snoop.Data.Object("View", extCmd.View));
        }
示例#15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pathRein">selected path reinforcement element.</param>
 /// <param name="commandData">External command data</param>
 public Profile(Autodesk.Revit.DB.Structure.PathReinforcement pathRein, ExternalCommandData commandData)
 {
     m_pathRein    = pathRein;
     m_commandData = commandData;
     Tessellate();
     ComputeBound();
     ComputePathTo2D();
 }
示例#16
0
        /// <summary>
        /// 翻模执行
        /// </summary>
        /// <param name="inputCommandData"></param>
        public void Excute(Autodesk.Revit.UI.ExternalCommandData inputCommandData)
        {
            Document useDoc = inputCommandData.Application.ActiveUIDocument.Document;

            WorkHanlder(inputCommandData, useDoc);

            return;
        }
示例#17
0
        public Result Execute(Autodesk.Revit.UI.ExternalCommandData cmdData, ref string msg, ElementSet elems)
        {
            TaskDialog helloDlg = new TaskDialog("Autodesk Revit");

            helloDlg.MainContent = "Hello World from " + System.Reflection.Assembly.GetExecutingAssembly().Location;
            helloDlg.Show();
            return(Result.Cancelled);
        }
示例#18
0
        public Autodesk.Revit.UI.Result Execute(
            Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elementSet)
        {
            UIApplication uiApp = new UIApplication(commandData.Application.Application);

            bool error = false;

            try
            {
                // if the browser window/process is already open, activate it instead of opening a new process
                if (MessageHandler.library_pid != 0)
                {
                    // the following line could be enough, but rather activate the window thru the process
                    //SetForegroundWindow(MessageHandler.browser_hwnd);

                    // try to activate the existing instance
                    Process[] processes = Process.GetProcesses();

                    foreach (Process p in processes)
                    {
                        if (p.Id == MessageHandler.library_pid)
                        {
                            IntPtr windowHandle = p.MainWindowHandle;
                            SetForegroundWindow(windowHandle);
                            return(Result.Succeeded);
                        }
                    }
                }

                // execute the library window process
                Process process = new Process();
                process.StartInfo.FileName  = AssemblyDirectory + "\\Part_Library_App.exe ";
                process.StartInfo.Arguments = App.messagehandler.Handle.ToString(); // pass the MessageHandler's window handle the the process as a command line argument
                process.Start();

                MessageHandler.library_pid = process.Id; // grab the PID so we can kill the process if required;

                ExternalEventPL.RunExternal();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                // if revit threw an exception, try to catch it
                TaskDialog.Show("Error", e.Message);
                error = true;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                // if revit threw an exception, display error and return failed
                if (error)
                {
                    TaskDialog.Show("Error", "Part Library failed.");
                }
            }
        }
示例#19
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user canceled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction newTran = null;

            try
            {
                UIDocument uiDoc = commandData.Application.ActiveUIDocument;
                if (null == uiDoc)
                {
                    message = "this command needs to be run in an active document.";
                    return(Result.Failed);
                }
                Document doc = uiDoc.Document;

                ICollection <ElementId> selectedId = uiDoc.Selection.GetElementIds();
                if (1 != selectedId.Count)
                {
                    message = "Please select a multistory stairs before running this command.";
                    return(Result.Failed);
                }
                MultistoryStairs mStairs = doc.GetElement(selectedId.ElementAt(0)) as MultistoryStairs;
                if (null == mStairs)
                {
                    message = "Please select a multistory stairs before running this command.";
                    return(Result.Failed);
                }

                View currentView = doc.ActiveView;
                if (null == currentView || currentView.ViewType != ViewType.Elevation || !currentView.CanBePrinted)
                {
                    message = "The current view should be an elevation view to allow user to select levels.";
                    return(Result.Failed);
                }

                // allow the user to select the stairs to add stairs.
                LevelSelectionFilter    selectionFilter  = new LevelSelectionFilter(mStairs, OperationAction.Add);
                IList <Reference>       userSelectedRefs = uiDoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, selectionFilter);
                IEnumerable <ElementId> userSelectedIds  = from refer in userSelectedRefs select refer.ElementId;

                // start the transaction and add the stairs into the multistory stairs.
                newTran = new Transaction(doc, "Add Stairs to Multistory Stairs");
                newTran.Start();
                mStairs.AddStairsByLevelIds(new HashSet <ElementId>(userSelectedIds));
                newTran.Commit();

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
                {
                    newTran.RollBack();
                }
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
示例#20
0
        ///<summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(
            Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;

            ElementSet collection = new ElementSet();

            foreach (ElementId elementId in revit.ActiveUIDocument.Selection.GetElementIds())
            {
                collection.Insert(revit.ActiveUIDocument.Document.GetElement(elementId));
            }
            // check user selection
            if (collection.Size < 1)
            {
                message = "Please select object(s) before delete.";
                return(Autodesk.Revit.UI.Result.Cancelled);
            }

            bool error = true;

            try
            {
                error = true;

                // delete selection
                IEnumerator e         = collection.GetEnumerator();
                bool        MoreValue = e.MoveNext();
                while (MoreValue)
                {
                    Element component = e.Current as Element;
                    revit.ActiveUIDocument.Document.Delete(component.Id);
                    MoreValue = e.MoveNext();
                }

                error = false;
            }
            catch
            {
                // if revit threw an exception, try to catch it
                foreach (Element c in collection)
                {
                    elements.Insert(c);
                }
                message = "object(s) can't be deleted.";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                // if revit threw an exception, display error and return failed
                if (error)
                {
                    TaskDialog.Show("Error", "Delete failed.");
                }
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#21
0
        public Result Execute(Autodesk.Revit.UI.ExternalCommandData cmdData, ref string msg, ElementSet elems)
        {
            TaskDialog helloDlg = new TaskDialog("Autodesk Revit");

            helloDlg.MainContent = "Hello World.";
            helloDlg.Show();

            return(Result.Cancelled);
        }
示例#22
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false); // why did someone else send us the message?
                return;
            }

            // see if it is a type we are responsible for
            Autodesk.Revit.ApplicationServices.Application app = e.ObjToSnoop as Autodesk.Revit.ApplicationServices.Application;
            if (app != null)
            {
                Stream(snoopCollector.Data(), app);
                return;
            }

            // no more app options?
            //Autodesk.Revit.Options.Application appOptions = e.ObjToSnoop as Autodesk.Revit.Options.Application;
            //if (appOptions != null) {
            //    Stream(snoopCollector.Data(), appOptions);
            //    return;
            //}

            ControlledApplication contrApp = e.ObjToSnoop as Autodesk.Revit.ApplicationServices.ControlledApplication;

            if (contrApp != null)
            {
                Stream(snoopCollector.Data(), contrApp);
                return;
            }

            Autodesk.Revit.UI.ExternalCommandData extCmd = e.ObjToSnoop as Autodesk.Revit.UI.ExternalCommandData;
            if (extCmd != null)
            {
                Stream(snoopCollector.Data(), extCmd);
                return;
            }

            RibbonItem ribbonItem = e.ObjToSnoop as RibbonItem;

            if (ribbonItem != null)
            {
                Stream(snoopCollector.Data(), ribbonItem);
                return;
            }

            RibbonPanel ribbonPanel = e.ObjToSnoop as RibbonPanel;

            if (ribbonPanel != null)
            {
                Stream(snoopCollector.Data(), ribbonPanel);
                return;
            }
        }
示例#23
0
        public Journaling(RevitUI.ExternalCommandData commandData)
        {
            m_commandData = commandData;
            m_canReadData = (0 < commandData.JournalData.Count) ? true : false;

            m_levelList    = new List <RevitDB.Level>();
            m_wallTypeList = new List <RevitDB.WallType>();
            InitializeListData();
        }
示例#24
0
        private UI.Result Run(UI.ExternalCommandData commandData,
                              ref string message, DB.ElementSet elements)
        {
            IDictionary <string, string> logs = commandData.JournalData;

            logs.Clear();
            logs.Add("Kkozlov", "Hello, world!");
            UI.TaskDialog.Show("RevitApi", "Hello, world!");
            return(UI.Result.Succeeded);
        }
示例#25
0
文件: Profile.cs 项目: AMEE/revit
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="elem">Selected element</param>
        /// <param name="commandData">ExternalCommandData</param>
        public Profile(Autodesk.Revit.DB.Element elem, ExternalCommandData commandData)
        {
            m_dataProfile = elem;
            m_commandData = commandData;
            m_appCreator = m_commandData.Application.Application.Create;
            m_docCreator = m_commandData.Application.ActiveUIDocument.Document.Create;

            List<List<Edge>> faces = GetFaces(m_dataProfile);
            m_face = GetNeedFace(faces);
        }
示例#26
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                m_application = commandData.Application;
                m_document    = m_application.ActiveUIDocument;
                if (m_document.Document.IsFamilyDocument)
                {
                    m_CreationBase = m_document.Document.FamilyCreate;
                }
                else
                {
                    m_CreationBase = m_document.Document.Create;
                }

                //Pick a face from UI, create a new sketch plane via the face and set it to the current view.
                Reference      faceRef         = m_document.Selection.PickObject(ObjectType.Face, new PlanarFaceFilter(m_document.Document), "Please pick a planar face to set the work plane. ESC for cancel.");
                GeometryObject geoObject       = m_document.Document.GetElement(faceRef).GetGeometryObjectFromReference(faceRef);
                PlanarFace     planarFace      = geoObject as PlanarFace;
                SketchPlane    faceSketchPlane = CreateSketchPlane(planarFace.FaceNormal, planarFace.Origin);
                if (faceSketchPlane != null)
                {
                    Transaction changeSketchPlane = new Transaction(m_document.Document, "Change Sketch Plane.");
                    changeSketchPlane.Start();
                    m_document.Document.ActiveView.SketchPlane = faceSketchPlane;
                    m_document.Document.ActiveView.ShowActiveWorkPlane();
                    changeSketchPlane.Commit();
                }

                // Pick point from current work plane with snaps.
                ObjectSnapTypes snapType = ObjectSnapTypes.Centers | ObjectSnapTypes.Endpoints | ObjectSnapTypes.Intersections
                                           | ObjectSnapTypes.Midpoints | ObjectSnapTypes.Nearest | ObjectSnapTypes.WorkPlaneGrid;
                XYZ point = m_document.Selection.PickPoint(snapType, "Please pick a point to place component.");

                // Create a model curve by a circle with picked point as center.
                Transaction createModelCurve = new Transaction(m_document.Document, "Create a circle.");
                createModelCurve.Start();
                Curve circle = Arc.Create(point, 5, 0, Math.PI * 2, faceSketchPlane.GetPlane().XVec, faceSketchPlane.GetPlane().YVec);
                m_CreationBase.NewModelCurve(circle, faceSketchPlane);
                createModelCurve.Commit();

                return(Result.Succeeded);
            }
            catch (Exceptions.OperationCanceledException)
            {
                // Selection Cancelled. For picking face and picking point.
                return(Result.Cancelled);
            }
            catch (System.Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return(Result.Failed);
            }
        }
示例#27
0
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData cmdData, ref string msg, ElementSet elems)
        {
            Autodesk.Revit.UI.Result result;

            try
            {
                Snoop.CollectorExts.CollectorExt.m_app = cmdData.Application;
                UIDocument revitDoc = cmdData.Application.ActiveUIDocument;
                Document   dbdoc    = revitDoc.Document;
                Snoop.CollectorExts.CollectorExt.m_activeDoc = dbdoc; // TBD: see note in CollectorExt.cs
                Autodesk.Revit.DB.View view = dbdoc.ActiveView;

                //ElementSet ss = cmdData.Application.ActiveUIDocument.Selection.Elements; // 2015, jeremy: 'Autodesk.Revit.UI.Selection.Selection.Elements' is obsolete: 'This property is deprecated in Revit 2015. Use GetElementIds() and SetElementIds instead.'
                //if (ss.Size == 0)
                //{
                //  FilteredElementCollector collector = new FilteredElementCollector( revitDoc.Document, view.Id );
                //  collector.WhereElementIsNotElementType();
                //  FilteredElementIterator i = collector.GetElementIterator();
                //  i.Reset();
                //  ElementSet ss1 = cmdData.Application.Application.Create.NewElementSet();
                //  while( i.MoveNext() )
                //  {
                //    Element e = i.Current as Element;
                //    ss1.Insert( e );
                //  }
                //  ss = ss1;
                //}

                ICollection <ElementId> ids = cmdData.Application.ActiveUIDocument.Selection.GetElementIds(); // 2016, jeremy
                if (0 == ids.Count)
                {
                    FilteredElementCollector collector
                        = new FilteredElementCollector(revitDoc.Document, view.Id)
                          .WhereElementIsNotElementType();
                    ids = collector.ToElementIds();
                }

                //ICollection<Element> elements
                //  = new List<Element>( ids.Select<ElementId,Element>(
                //    id => dbdoc.GetElement( id ) ) );

                Snoop.Forms.Objects form = new Snoop.Forms.Objects(dbdoc, ids);
                ActiveDoc.UIApp = cmdData.Application;
                form.ShowDialog();

                result = Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (System.Exception e)
            {
                msg    = e.Message;
                result = Autodesk.Revit.UI.Result.Failed;
            }

            return(result);
        }
示例#28
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
                                                ref string message,
                                                ElementSet elements)
        {
            // Get the application of revit
            Autodesk.Revit.UI.UIApplication revit = commandData.Application;
            m_document = revit.ActiveUIDocument.Document;

            try
            {
                ElementSet elementSet = new ElementSet();
                foreach (ElementId elementId in revit.ActiveUIDocument.Selection.GetElementIds())
                {
                    elementSet.Insert(revit.ActiveUIDocument.Document.GetElement(elementId));
                }
                if (elementSet.IsEmpty)
                {
                    TaskDialog.Show("Select", "Please select one floor or slab at least.");
                    return(Autodesk.Revit.UI.Result.Cancelled);
                }
                using (m_displayForm = new DeckPropertyForm())
                {
                    List <Floor> floorList = new List <Floor>();
                    foreach (ElementId elementId in revit.ActiveUIDocument.Selection.GetElementIds())
                    {
                        Element element = revit.ActiveUIDocument.Document.GetElement(elementId);
                        Floor   floor   = element as Floor;
                        if (floor != null)
                        {
                            floorList.Add(floor);
                        }
                    }

                    if (floorList.Count <= 0)
                    {
                        TaskDialog.Show("Select", "Please select one floor or slab at least.");
                        return(Autodesk.Revit.UI.Result.Cancelled);
                    }

                    foreach (Floor floor in floorList)
                    {
                        DumpSlab(floor);
                    }
                    m_displayForm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                // If any error, store error information in message and return failed
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            // If everything goes well, return succeeded.
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        public Autodesk.Revit.UI.Result Execute(
            Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message,
            Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.UI.TaskDialog.Show(
                "My Dialog Title",
                "Hello World!");

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#30
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="elem">Selected element</param>
        /// <param name="commandData">ExternalCommandData</param>
        public Profile(Autodesk.Revit.DB.Element elem, ExternalCommandData commandData)
        {
            m_dataProfile = elem;
            m_commandData = commandData;
            m_appCreator  = m_commandData.Application.Application.Create;
            m_docCreator  = m_commandData.Application.ActiveUIDocument.Document.Create;

            List <List <Edge> > faces = GetFaces(m_dataProfile);

            m_face = GetNeedFace(faces);
        }
示例#31
0
        /// <summary>
        /// Executes the extension.
        /// </summary>
        /// <param name="commandData">The command data.</param>
        /// <param name="message">The message.</param>
        /// <param name="elements">The elements.</param>
        /// <returns>Returns execution result.</returns>
        public Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            if (currentDomain != null)
            {
                currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);
            }

            return(Proxy.Execute(commandData, ref message, elements));
        }
示例#32
0
文件: Profile.cs 项目: AMEE/revit
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="commandData">object which contains reference to Revit Application</param>
 protected Profile(ExternalCommandData commandData)
 {
     m_commandData = commandData;
     m_appCreator = m_commandData.Application.Application.Create;
     m_docCreator = m_commandData.Application.ActiveUIDocument.Document.Create;
 }
示例#33
0
文件: Profile.cs 项目: AMEE/revit
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pathRein">selected path reinforcement element.</param>
 /// <param name="commandData">External command data</param>
 public Profile(Autodesk.Revit.DB.Structure.PathReinforcement pathRein, ExternalCommandData commandData)
 {
     m_pathRein = pathRein;
     m_commandData = commandData;
     Tessellate();
     ComputeBound();
     ComputePathTo2D();
 }