예제 #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 virtual Result Execute(ExternalCommandData commandData
                                      , ref string message, ElementSet elements)
        {
            try
            {
                Document document             = commandData.Application.ActiveUIDocument.Document;
                Autodesk.Revit.DB.Units units = document.GetUnits();

                // show UI
                using (UnitsForm displayForm = new UnitsForm(units))
                {
                    DialogResult result = displayForm.ShowDialog();
                    if (DialogResult.OK == result)
                    {
                        using (Autodesk.Revit.DB.Transaction tran = new Autodesk.Revit.DB.Transaction(document, "SetUnits"))
                        {
                            tran.Start();
                            document.SetUnits(units);
                            tran.Commit();
                        }
                    }
                    else
                    {
                        return(Autodesk.Revit.UI.Result.Cancelled);
                    }
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of ProjectUnitData
 /// </summary>
 /// <param name="units">an object of Autodesk.Revit.DB.Units</param>
 public ProjectUnitData(Autodesk.Revit.DB.Units units)
 {
     m_unitType_formatOptions.Clear();
     m_units = units;
     foreach (Autodesk.Revit.DB.UnitType unittype in Enum.GetValues(typeof(
                                                                        Autodesk.Revit.DB.UnitType)))
     {
         try
         {
             Autodesk.Revit.DB.FormatOptions formatOptions = m_units.GetFormatOptions(unittype);
             m_unitType_formatOptions.Add(unittype, formatOptions);
             m_unitType_label.Add(unittype, Autodesk.Revit.DB.LabelUtils.GetLabelFor(unittype));
         }
         catch
         {
             continue;
         }
     }
     m_decimalSymbol       = units.DecimalSymbol;
     m_digitGroupingSymbol = units.DigitGroupingSymbol;
     m_digitGroupingAmount = units.DigitGroupingAmount;
     foreach (Autodesk.Revit.DB.DisplayUnitType displayunittype in Enum.GetValues(typeof(
                                                                                      Autodesk.Revit.DB.DisplayUnitType)))
     {
         try
         {
             m_displayUnitType_label.Add(displayunittype, Autodesk.Revit.DB.LabelUtils.GetLabelFor(displayunittype));
         }
         catch
         {
             continue;
         }
     }
     foreach (Autodesk.Revit.DB.UnitSymbolType unitsymboltype in Enum.GetValues(typeof(
                                                                                    Autodesk.Revit.DB.UnitSymbolType)))
     {
         try
         {
             m_unitSymbolType_label.Add(unitsymboltype, Autodesk.Revit.DB.LabelUtils.GetLabelFor(unitsymboltype));
         }
         catch
         {
             if (unitsymboltype == Autodesk.Revit.DB.UnitSymbolType.UST_NONE)
             {
                 m_unitSymbolType_label.Add(unitsymboltype, "(NONE)");
             }
             continue;
         }
     }
 }