Revit.SDK.Samples.DoorSwing.CS.DoorSwingData.UpdateDoorsInfo C# (CSharp) Method

UpdateDoorsInfo() public static method

update door instances information: Left/Right information, related rooms information.
public static UpdateDoorsInfo ( System.Windows.Forms.Document doc, bool onlyUpdateSelect, bool showUpdateResultMessage, string &message ) : Autodesk.Revit.UI.Result
doc System.Windows.Forms.Document Revit project.
onlyUpdateSelect bool /// true means only update selected doors' information otherwise false. ///
showUpdateResultMessage bool /// this parameter is used for invoking this method in Application's events (document save and document saveAs). /// update door infos in Application level events should not show unnecessary messageBox. ///
message string
return Autodesk.Revit.UI.Result
        public static Autodesk.Revit.UI.Result UpdateDoorsInfo(Document doc, bool onlyUpdateSelect, 
                                         bool showUpdateResultMessage, ref string message)
        {
            if ((!AssignedAllRooms(doc)) && showUpdateResultMessage)
             {
            DialogResult dialogResult = MessageBox.Show("One or more eligible areas of this level " +
                                        "have no assigned room(s). Doors bounding these areas " +
                                        "will be designated as external doors. Proceed anyway?",
                                        "Door Swing", MessageBoxButtons.YesNo);

            if (DialogResult.No == dialogResult)
            {
               message = "Update cancelled. Please assign rooms for all eligible areas first.";
               return Autodesk.Revit.UI.Result.Cancelled;
            }
             }

             // begin update door parameters.
             IEnumerator iter;
             int doorCount              = 0;
             bool checkSharedParameters = false;

             if (onlyUpdateSelect) // update doors in select elements
             {
            UIDocument newUIdoc = new UIDocument(doc);
            iter = newUIdoc.Selection.Elements.GetEnumerator();
             }
             else // update all doors in current Revit project.
             {
             ElementClassFilter familyInstanceFilter   = new ElementClassFilter(typeof(FamilyInstance));
             ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
             LogicalAndFilter doorInstancesFilter      = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter);
             iter                                      = new FilteredElementCollector(doc).WherePasses(doorInstancesFilter).GetElementIterator();
             }

             iter.Reset();
             while (iter.MoveNext())
             {
            // find door instance
            FamilyInstance door = iter.Current as FamilyInstance;

            if (onlyUpdateSelect)
            {
               if (null == door)
               {
                  continue;
               }

               if (null == door.Category)
               {
                  continue;
               }

               if (!door.Category.Name.Equals("Doors"))
               {
                  continue;
               }
            }

            // check if has needed parameters.
            if (!checkSharedParameters)
            {
               checkSharedParameters = true;

               if (!(door.Symbol.ParametersMap.Contains("BasalOpening") &&
                     door.ParametersMap.Contains("InstanceOpening") &&
                     door.ParametersMap.Contains("Internal Door")))
               {
                  message = "Cannot update door parameters. Please customize door opening expression first.";
                  return Autodesk.Revit.UI.Result.Failed;
               }
            }

            // get one door.
            doorCount++;

            // update one door's Opening parameter value.
            if (UpdateOpeningFeatureOfOneDoor(door) == Autodesk.Revit.UI.Result.Failed)
            {
               message = "Cannot update door parameters. Please customize door opening expression first.";
               return Autodesk.Revit.UI.Result.Failed;
            }

            // update one door's from/to room.
            UpdateFromToRoomofOneDoor(door, false);

            // update one door's internalDoor flag
            UpdateInternalDoorFlagFeatureofOneDoor(door);
             }

             if (showUpdateResultMessage)
             {

            if (onlyUpdateSelect)
            {
               System.Windows.Forms.MessageBox.Show("Updated all selected doors of " + doc.Title +
                                                    " (" + doorCount + " doors).\r\n (Selection may " +
                                                    "include miscellaneous elements.)","Door Swing");
            }
            else
            {
               System.Windows.Forms.MessageBox.Show("Updated all doors of " + doc.Title + " (" +
                                                    doorCount + " doors).", "Door Swing");
            }
             }

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

Usage Example

Exemplo n.º 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(ExternalCommandData commandData,
                                                ref string message,
                                                ElementSet elements)
        {
            Autodesk.Revit.UI.Result returnCode = Autodesk.Revit.UI.Result.Cancelled;

            Transaction tran = new Transaction(commandData.Application.ActiveUIDocument.Document, "Initialize Command");

            tran.Start();

            try
            {
                // one instance of DoorSwingData class.
                DoorSwingData databuffer = new DoorSwingData(commandData.Application);

                using (InitializeForm initForm = new InitializeForm(databuffer))
                {
                    // Show UI
                    DialogResult dialogResult = initForm.ShowDialog();

                    if (DialogResult.OK == dialogResult)
                    {
                        databuffer.DeleteTempDoorInstances();

                        // update door type's opening feature based on family's actual geometry and
                        // country's standard.
                        databuffer.UpdateDoorFamiliesOpeningFeature();

                        // update each door instance's Opening feature and internal door flag
                        returnCode = DoorSwingData.UpdateDoorsInfo(commandData.Application.ActiveUIDocument.Document, false, true, ref message);
                    }
                }
            }
            catch (Exception ex)
            {
                // if there is anything wrong, give error information and return failed.
                message    = ex.Message;
                returnCode = Autodesk.Revit.UI.Result.Failed;
            }

            if (Autodesk.Revit.UI.Result.Succeeded == returnCode)
            {
                tran.Commit();
            }
            else
            {
                tran.RollBack();
            }
            return(returnCode);
        }
All Usage Examples Of Revit.SDK.Samples.DoorSwing.CS.DoorSwingData::UpdateDoorsInfo