/// <summary>
        /// The implementation of the command.
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            UIDocument  uiDoc       = commandData.Application.ActiveUIDocument;
            Document    doc         = uiDoc.Document;
            View        activeView  = commandData.View;
            GroupHelper groupHelper = new GroupHelper();
            Group       selectedModelGroup;

            if (!groupHelper.getSelectedModelGroup(uiDoc, out selectedModelGroup, out message))
            {
                return(Result.Cancelled);
            }

            groupHelper.HideAllAttachedDetailGroups(selectedModelGroup, doc, activeView);
            return(Result.Succeeded);
        }
        public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements)
        {
            // Check to see if any document path is provided in journal data
            // if yes, open the document.
            if (data.JournalData.TryGetValue("Open", out var filename))
            {
                if (!GH.Guest.OpenDocument(filename))
                {
                    return(Result.Failed);
                }
            }

            GH.Guest.ShowEditorAsync();

            return(Result.Succeeded);
        }
        /// <summary>
        /// The implementation of the command.
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Document doc        = commandData.Application.ActiveUIDocument.Document;
            View     activeView = commandData.View;

            if (activeView is ViewSchedule)
            {
                ScheduleHTMLExporter exporter = new ScheduleHTMLExporter(activeView as ViewSchedule);
                Autodesk.Revit.ApplicationServices.Application revitApplication = commandData.Application.Application;
                bool bInteractive = revitApplication.IsJournalPlaying() ? false : true;
                return(exporter.ExportToHTML(bInteractive, ref message) ? Result.Succeeded : Result.Cancelled);
            }

            message = "Unable to proceed: Active view must be a schedule.";
            return(Result.Cancelled);
        }
Exemple #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 Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                CreationMgr mgr = new CreationMgr(commandData.Application.ActiveUIDocument);
                mgr.Execute();
            }
            catch (Exception e)
            {
                message += e.StackTrace;
                return(Autodesk.Revit.UI.Result.Cancelled);
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemple #5
0
        /// <summary>
        /// Overload this method to implement the external command within 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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ElementSet selections = new ElementSet();

            foreach (ElementId elementId in commandData.Application.ActiveUIDocument.Selection.GetElementIds())
            {
                selections.Insert(commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
            }
            ElementSet dimsToDelete = new Autodesk.Revit.DB.ElementSet();

            //warning if nothing selected
            if (0 == selections.Size)
            {
                message = "Please select dimensions";
                return(Autodesk.Revit.UI.Result.Failed);
            }

            //find all unpinned dimensions in the current selection
            foreach (Element e in selections)
            {
                Dimension dimesionTemp = e as Dimension;
                if (null != dimesionTemp && !dimesionTemp.Pinned)
                {
                    dimsToDelete.Insert(dimesionTemp);
                }
            }

            //warning if could not find any unpinned dimension
            if (0 == dimsToDelete.Size)
            {
                message = "There are no unpinned dimensions currently selected";
                return(Autodesk.Revit.UI.Result.Failed);
            }

            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");

            transaction.Start();
            //delete all the unpinned dimensions
            foreach (Element e in dimsToDelete)
            {
                commandData.Application.ActiveUIDocument.Document.Delete(e.Id);
            }

            transaction.Commit();
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemple #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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
                                                        , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;

            // get one sheet view to place panel schedule.
            ViewSheet sheet = doc.ActiveView as ViewSheet;

            if (null == sheet)
            {
                message = "please go to a sheet view.";
                return(Result.Failed);
            }

            // get all PanelScheduleView instances in the Revit document.
            FilteredElementCollector fec = new FilteredElementCollector(doc);
            ElementClassFilter       PanelScheduleViewsAreWanted = new ElementClassFilter(typeof(PanelScheduleView));

            fec.WherePasses(PanelScheduleViewsAreWanted);
            List <Element> psViews = fec.ToElements() as List <Element>;

            Transaction placePanelScheduleOnSheet = new Transaction(doc, "placePanelScheduleOnSheet");

            placePanelScheduleOnSheet.Start();

            XYZ nextOrigin = new XYZ(0.0, 0.0, 0.0);

            foreach (Element element in psViews)
            {
                PanelScheduleView psView = element as PanelScheduleView;
                if (psView.IsPanelScheduleTemplate())
                {
                    // ignore the PanelScheduleView instance which is a template.
                    continue;
                }

                PanelScheduleSheetInstance onSheet = PanelScheduleSheetInstance.Create(doc, psView.Id, sheet);
                onSheet.Origin = nextOrigin;
                BoundingBoxXYZ bbox  = onSheet.get_BoundingBox(doc.ActiveView);
                double         width = bbox.Max.X - bbox.Min.X;
                nextOrigin = new XYZ(onSheet.Origin.X + width, onSheet.Origin.Y, onSheet.Origin.Z);
            }

            placePanelScheduleOnSheet.Commit();

            return(Result.Succeeded);
        }
Exemple #7
0
        public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements)
        {
            var doc = data.Application.ActiveUIDocument.Document;

            if (!doc.IsFamilyDocument && !DB.DirectShape.IsSupportedDocument(doc))
            {
                message = "Active document dont't support DirectShape functionality.";
                return(Result.Failed);
            }

            using
            (
                var openFileDialog = new OpenFileDialog()
            {
                Filter = "Rhino 3D models (*.3dm)|*.3dm",
                FilterIndex = 1,
                RestoreDirectory = true
            }
            )
            {
                switch (openFileDialog.ShowDialog(Revit.MainWindowHandle))
                {
                case DialogResult.OK:
                    if (doc.IsFamilyDocument)
                    {
                        return(Import3DMFileToFamily
                               (
                                   doc,
                                   openFileDialog.FileName
                               ));
                    }
                    else
                    {
                        return(Import3DMFileToProject
                               (
                                   doc,
                                   openFileDialog.FileName,
                                   CommandGrasshopperBake.ActiveBuiltInCategory
                               ));
                    }

                case DialogResult.Cancel: return(Result.Cancelled);
                }
            }

            return(Result.Failed);
        }
Exemple #8
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 virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
                                                        , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction trans = new Transaction(commandData.Application.ActiveUIDocument.Document, "Revit.SDK.Samples.VisibilityControl");

            trans.Start();
            try
            {
                if (null == commandData)
                {
                    trans.RollBack();
                    throw new ArgumentNullException("commandData");
                }

                // create an instance of VisibilityCtrl
                VisibilityCtrl visiController = new VisibilityCtrl(commandData.Application.ActiveUIDocument);

                // create a user interface form
                using (VisibilityCtrlForm dlg = new VisibilityCtrlForm(visiController))
                {
                    // show dialog
                    System.Windows.Forms.DialogResult result = dlg.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        trans.Commit();
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                    else if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        // isolate the selected element(s)
                        visiController.Isolate();
                        trans.Commit();
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }

                trans.RollBack();
                return(Autodesk.Revit.UI.Result.Cancelled);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                trans.RollBack();
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Exemple #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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            // NOTES: Anything can be done in this method, such as the solid-solid cut operation.

            // Get the application and document from external command data.
            Application app       = commandData.Application.Application;
            Document    activeDoc = commandData.Application.ActiveUIDocument.Document;

            #region Demo how to use the SolidSolidCut API to make one solid cut another.

            int solidToBeCutElementId = 30481; //The cube
            int cuttingSolidElementId = 30809; //The sphere

            //Get element by ElementId
            Element solidToBeCut = activeDoc.GetElement(new ElementId(solidToBeCutElementId));
            Element cuttingSolid = activeDoc.GetElement(new ElementId(cuttingSolidElementId));

            //If the two elements do not exist, notify user to open the family file then try this command.
            if (solidToBeCut == null || cuttingSolid == null)
            {
                TaskDialog.Show("Notice", "Please open the family file SolidSolidCut.rfa, then try to run this command.");

                return(Autodesk.Revit.UI.Result.Succeeded);
            }

            //Check whether the cuttingSolid can cut the solidToBeCut
            CutFailureReason cutFailureReason = new CutFailureReason();
            if (SolidSolidCutUtils.CanElementCutElement(cuttingSolid, solidToBeCut, out cutFailureReason))
            {
                //cuttingSolid can cut solidToBeCut

                //Do the solid-solid cut operation
                //Start a transaction
                Transaction transaction = new Transaction(activeDoc);
                transaction.Start("AddCutBetweenSolids(activeDoc, solidToBeCut, cuttingSolid)");

                //Let the cuttingSolid cut the solidToBeCut
                SolidSolidCutUtils.AddCutBetweenSolids(activeDoc, solidToBeCut, cuttingSolid);

                transaction.Commit();
            }

            #endregion

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemple #10
0
        /// <summary>
        /// The implementation of the command.
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Document doc        = commandData.Application.ActiveUIDocument.Document;
            View     activeView = commandData.View;

            if (activeView is ViewSchedule)
            {
                ScheduleHTMLExporter exporter = new ScheduleHTMLExporter(activeView as ViewSchedule);
                exporter.ExportToHTML();
            }
            else
            {
                TaskDialog.Show("Unable to proceed", "Active view must be a schedule.");
                return(Result.Cancelled);
            }
            return(Result.Succeeded);
        }
Exemple #11
0
 ElementSet(string label, ICollection <Autodesk.Revit.DB.ElementId> val, Document doc)
     : base(label)
 {
     MVal = new Autodesk.Revit.DB.ElementSet();
     foreach (var elemId in val)
     {
         if (Autodesk.Revit.DB.ElementId.InvalidElementId == elemId)
         {
             continue;
         }
         var elem = doc.GetElement(elemId);
         if (null != elem)
         {
             MVal.Insert(elem);
         }
     }
 }
Exemple #12
0
        // TBD: as of 04/10/07 - only works on App startup, not dynamically from another command (jma)

        /*public void
         * AddMenu()
         * {
         *  MenuItem rootMenu = m_revitApp.CreateTopMenu("RevitLookup Test Menu Item");
         *
         *  bool success = rootMenu.AddToExternalTools();
         *  if (success) {
         *      MenuItem subItem = rootMenu.Append(MenuItem.MenuType.BasicMenu, "Pick me to call back into RevitLookup", "RevitLookup.dll", "CmdSampleMenuItemCallback");
         *      System.Windows.Forms.MessageBox.Show("Successfully added new menu to the External Tools menu.  Pick the item to demonstrate callback.");
         *  }
         *  else
         *      System.Windows.Forms.MessageBox.Show("Could not add new menu!");
         * }
         *
         * public void
         * AddToolbar()
         * {
         *  Toolbar toolBar = m_revitApp.CreateToolbar();
         *  toolBar.Name = "Jimbo";
         *
         *  if (toolBar != null) {
         *      ToolbarItem tbItem = toolBar.AddItem("RevitLookup.dll", "CmdSampleMenuItemCallback");
         *      System.Windows.Forms.MessageBox.Show("Successfully added new toolbar.  Pick the item to demonstrate callback.");
         *  }
         *  else
         *      System.Windows.Forms.MessageBox.Show("Could not add new toolbar!");
         * }*/

        public void SelectElement()
        {
            Autodesk.Revit.UI.Selection.Selection selSet = m_revitApp.ActiveUIDocument.Selection;

            try
            {
                Autodesk.Revit.DB.Element    elem    = m_revitApp.ActiveUIDocument.Document.GetElement(selSet.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element).ElementId);
                Autodesk.Revit.DB.ElementSet elemSet = m_revitApp.Application.Create.NewElementSet();
                elemSet.Insert(elem);
                Snoop.Forms.Objects form = new Snoop.Forms.Objects(elemSet);
                form.ShowDialog();
            }
            catch (System.Exception)
            {
                System.Windows.Forms.MessageBox.Show("Didn't pick one!");
            }
        }
Exemple #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, Autodesk.Revit.DB.ElementSet elements)
        {
            Transaction newTran = null;

            try
            {
                if (null == commandData)
                {
                    throw new ArgumentNullException("commandData");
                }

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

                newTran = new Transaction(doc);
                newTran.Start("AllViews_Sample");

                AllViewsForm dlg = new AllViewsForm(view);

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    view.GenerateSheets(doc);
                }
                newTran.Commit();

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                // message = e.Message;
                if (e.Message == "viewId cannot be added to the ViewSheet." + Environment.NewLine + "Parameter name: viewId")
                {
                    TaskDialog.Show("Error", "Cannot reuse the same view");
                }
                else
                {
                    message = e.Message;
                }
                if ((newTran != null) && newTran.HasStarted() && !newTran.HasEnded())
                {
                    newTran.RollBack();
                }
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
 public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
 {
     try
     {
         m_doc = commandData.Application.ActiveUIDocument.Document;
         if (IsValidView())
         {
             AppCommand.thisApp.ShowWalker(commandData.Application);
         }
         return Result.Succeeded;
     }
     catch (Exception ex)
     {
         message = ex.Message;
         return Result.Failed;
     }
 }
Exemple #15
0
        public override Result Execute(ExternalCommandData data, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if
            (
                (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) &&
                (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
            )
            {
                return(ShowLoadError(data));
            }

            if (Addin.CurrentStatus == Addin.Status.Ready)
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    return(Rhinoceros.RunCommandAbout());
                }

                if
                (
                    Rhinoceros.MainWindow.Visible ||
                    Rhinoceros.MainWindow.ActivePopup?.IsInvalid == false
                )
                {
                    Rhinoceros.MainWindow.BringToFront();
                    return(Result.Succeeded);
                }

                return(Result.Succeeded);
            }

            if (AddinOptions.Current.CompactTab)
            {
                data.Application.CreateRibbonTab(Addin.AddinName);
                data.Application.ActivateRibbonTab(Addin.AddinName);
            }

            var result = Start(new RibbonHandler(data.Application));

            if (result == Result.Failed)
            {
                ShowLoadError(data);
            }

            return(result);
        }
Exemple #16
0
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            m_app = commandData.Application;
            m_doc = m_app.ActiveUIDocument.Document;

            if (AddSharedParameters() == false)
            {
                MessageBox.Show("LEED Parameters cannot be found.\n" + LEEDParameters.LEED_AreaWithViews.ToString() + "\n" + LEEDParameters.LEED_NonRegularyOccupied.ToString(), "LEED View Analysis - Shared Parameters", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (IsViewForAnalysis(m_doc.ActiveView))
            {
                //two modes: fast run for simple geometry, slow run for complex geometry
                UIDocument        uidoc            = m_app.ActiveUIDocument;
                IList <Reference> selectedElements = uidoc.Selection.PickObjects(ObjectType.Element, new RoomElementFilter(), "Select rooms to calculate the area with views. Click Finish on the options bar when you're done selecting rooms.");
                if (selectedElements.Count > 0)
                {
                    List <Room> selectedRooms = new List <Room>();
                    //ray tracing is only available in 3d views
                    foreach (Reference reference in selectedElements)
                    {
                        Room room = m_doc.GetElement(reference.ElementId) as Room;
                        if (null != room)
                        {
                            selectedRooms.Add(room);
                        }
                    }

                    if (selectedRooms.Count > 0)
                    {
                        MainWindow mainWindow = new MainWindow(m_app, selectedRooms);
                        if (mainWindow.ShowDialog() == true)
                        {
                            MessageBox.Show("View analysis has been successfully run.", "LEED EQc 8.2", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("A floor plan should be an active view for the view anlaysis.\n", "View Analysis - Active View", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(Result.Succeeded);
        }
Exemple #17
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_project = commandData.Application.ActiveUIDocument;

                // Get the selected element and store it to data member.
                if (!GetSelectedElement())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a BoundingBoxXYZ instance which used in NewViewSection() method
                if (!GenerateBoundingBoxXYZ())
                {
                    message = m_errorInformation;
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Create a section view.
                Transaction transaction = new Transaction(m_project.Document, "CreateSectionView");
                transaction.Start();
                ViewSection section = m_project.Document.Create.NewViewSection(m_box);
                if (null == section)
                {
                    message = "Can't create the ViewSection.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                // Modify some parameters to make it look better.
                section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2);
                transaction.Commit();

                // If everything goes right, give successful information and return succeeded.
                MessageBox.Show("Create view section succeeded.", "Revit");
                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Exemple #18
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);
                }
            }
        }
Exemple #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 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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            Floor selectFloor = GetSelectFloor(commandData);

            if (null == selectFloor)
            {
                message = "Make sure selected only one floor (Slab) in Revit.";
                return(Autodesk.Revit.UI.Result.Failed);
            }

            SlabShapeEditingForm slabShapeEditingForm =
                new SlabShapeEditingForm(selectFloor, commandData);

            slabShapeEditingForm.ShowDialog();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements)
        {
            // check to see if any document path is provided in journal data
            // if yes, open the document
            string filename = null;

            if (data.JournalData.TryGetValue("Open", out filename) && File.Exists(filename))
            {
                GH.Guest.ShowAndOpenDocumentAsync(filename);
            }
            // otherwise, just open the GH window
            else
            {
                GH.Guest.ShowAsync();
            }
            // whatever happens say success so Revit does not prompt errors
            return(Result.Succeeded);
        }
        public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements)
        {
            GH_Document.EnableSolutions = !GH_Document.EnableSolutions;

            if (GH_Document.EnableSolutions)
            {
                if (Instances.ActiveCanvas?.Document is GH_Document definition)
                {
                    definition.NewSolution(false);
                }
            }
            else
            {
                Revit.RefreshActiveView();
            }

            return(Result.Succeeded);
        }
Exemple #22
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            // Filter all printable views in current document and print them,
            // the print will raise events registered in controlled application.
            // After run this external command please refer to log files under folder of this assembly.
            Document document = commandData.Application.ActiveUIDocument.Document;

            try
            {
                List <Autodesk.Revit.DB.Element> viewElems = new List <Autodesk.Revit.DB.Element>();
                FilteredElementCollector         collector = new FilteredElementCollector(document);
                viewElems.AddRange(collector.OfClass(typeof(View)).ToElements());
                //
                // Filter all printable views
                ViewSet printableViews = new ViewSet();
                foreach (View view in viewElems)
                {
                    // skip view templates because they're invalid for print
                    if (!view.IsTemplate && view.CanBePrinted)
                    {
                        printableViews.Insert(view);
                    }
                }
                //
                // Print to file to folder of assembly
                String       assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                PrintManager pm           = document.PrintManager;
                pm.PrintToFile     = true;
                pm.PrintToFileName = assemblyPath + "\\PrintOut.prn";
                pm.Apply();
                //
                // Print views now to raise events:
                document.Print(printableViews);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            //
            // return succeed by default
            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemple #23
0
        /// <summary>
        /// The implementation of the automatic stairs creation command.
        /// </summary>
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            UIDocument activeDocument = commandData.Application.ActiveUIDocument;
            Document   document       = activeDocument.Document;

            // Create an automation utility with a hardcoded stairs configuration number
            StairsAutomationUtility utility = StairsAutomationUtility.Create(document, stairsConfigs[stairsIndex]);

            // Generate the stairs
            utility.GenerateStairs();

            stairsIndex++;
            if (stairsIndex > 4)
            {
                stairsIndex = 0;
            }

            return(Result.Succeeded);
        }
Exemple #24
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            // Create an object that is responsible for collecting users inputs and getting analysis data of current model.
            EnergyAnalysisModel analysisModel = new EnergyAnalysisModel(commandData.Application.ActiveUIDocument.Document);

            // Create the UI for users inputs options and view analysis models.
            using (OptionsAndAnalysisForm form = new OptionsAndAnalysisForm(analysisModel))
            {
                // make analysis data ready
                analysisModel.Initialize();
                // show dialog to browser analysis model
                if (DialogResult.OK != form.ShowDialog())
                {
                    return(Result.Cancelled);
                }
            }
            return(Result.Succeeded);
        }
Exemple #25
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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                // create a SlaveSymbolGeometry object
                SlaveSymbolGeometry slaveSymGeo = new SlaveSymbolGeometry(commandData.Application.ActiveUIDocument.Document);
                // execute method to get and show geometry of all instances
                slaveSymGeo.GetInstanceGeometry();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message  = e.Message;
                message += e.StackTrace;
                return(Result.Failed);
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_app = commandData.Application;
                m_doc = m_app.ActiveUIDocument.Document;

                ManagerWindow   managerWindow = new ManagerWindow(m_app, ModelManagerMode.ProjectReplication);
                Nullable <bool> dlgResult     = managerWindow.ShowDialog();


                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to initialize Project Replication.\n" + ex.Message, "Project Replication", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(Result.Cancelled);
            }
        }
Exemple #27
0
        // necessary method that Revit needs to call
        Result IExternalCommand.Execute(
            ExternalCommandData excmd,
            ref string mainmessage,
            Autodesk.Revit.DB.ElementSet elemset)
        {
            // if any of the private fields are incorrect - let Revit re-correct them
            // tried doing this before initializing the fields
//            if(
//            (!_mainMessage.Equals(mainmessage)) ||
//            (!_externalCMD.Equals(excmd)) ||
//            (!_elementSet.Equals(elemset)))
//            {
            _mainMessage = mainmessage;
            _externalCMD = excmd;
            _elementSet  = elemset;
//            }

            return(Execute());
        }
Exemple #28
0
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            UIDocument doc = commandData.Application.ActiveUIDocument;

            using (Transaction trans = new Transaction(doc.Document))
            {
                trans.Start("Select model curves in revit document");

                IList <Reference> refList = doc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element,
                                                                      "Please pick some model curves in revit document"
                                                                      );

                DividedPath dpath = DividedPath.Create(doc.Document, refList);

                trans.Commit();
            }


            return(Result.Succeeded);
        }
Exemple #29
0
        /// <summary>
        /// Checks at API address
        /// </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(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            //loads from settings.txt
            settings.LoadSettings();
            PricingHttpRest.InitializeClient(settings.APILocation, "");

            try
            {
                string result = PricingHttpRest.Get();

                System.Windows.Forms.MessageBox.Show("Status code: " + PricingHttpRest.receivedCode + " Reason: " + result + " Received content: " + PricingHttpRest.receivedContent);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error accessing API");
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Exemple #30
0
        // Internal method that allows this class to use this private fields it contains
        // without having to set them necessarily.
        protected Result Execute(
            ExternalCommandData excmd,
            string mainmessage,
            Autodesk.Revit.DB.ElementSet elemset)
        {
            try
            {
                // defined in derived classes
                return(Work());
            }

            catch
            {
                logger.Debug("Command failed because of an exception");
                TaskDialog.Show("Command Failed",
                                "There was an error behind the scenes that caused the command to fail horribly and die.");
            }

            return(Result.Failed);
        }
Exemple #31
0
        /// <summary>
        /// Overload this method to implement the external command within 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(ExternalCommandData commandData, 
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            ElementSet selections = commandData.Application.ActiveUIDocument.Selection.Elements;
            ElementSet dimsToDelete = new Autodesk.Revit.DB.ElementSet();

            //warning if nothing selected
            if (0 == selections.Size)
            {
                message = "Please select dimensions";
                return Autodesk.Revit.UI.Result.Failed;
            }

            //find all unpinned dimensions in the current selection
            foreach (Element e in selections)
            {
               Dimension dimesionTemp = e as Dimension;
               if (null != dimesionTemp && !dimesionTemp.Pinned)
               {
                  dimsToDelete.Insert(dimesionTemp);
               }
            }

            //warning if could not find any unpinned dimension
            if (0 == dimsToDelete.Size)
            {
               message = "There are no unpinned dimensions currently selected";
               return Autodesk.Revit.UI.Result.Failed;
            }

            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");

            transaction.Start();
            //delete all the unpinned dimensions
            commandData.Application.ActiveUIDocument.Document.Delete(dimsToDelete);
            transaction.Commit();
            return Autodesk.Revit.UI.Result.Succeeded;
        }
Exemple #32
0
 public StructSample(Autodesk.Revit.UI.UIApplication app, ElementSet ss)
 {
     m_app = app;
      m_ss = ss;
 }