示例#1
0
 /// <summary>
 /// Displays the dialog to the user and returns if the user accepted the dialog/clicked OK. If the user cancels, <c>false</c> is
 /// returned. When the return value is <c>true</c>, the configuration is returned via the <paramref name="settings"/> parameter.
 /// <para>All saving/loading is handled by this method.</para>
 /// </summary>
 ///
 /// <param name="document"> The current Revit document. </param>
 /// <param name="settings"> [out] User configured settings. This will be <c>null</c> if the user canceled. </param>
 public static bool TryGetSettings(RevitDB.Document document, out Settings settings)
 {
     settings         = null;
     using var dialog = new ConfigurationForm(document);
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         settings = dialog.LastSavedSettings;
         return(true);
     }
     return(false);
 }
示例#2
0
        /// <inheritdoc/>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var document = commandData.Application.ActiveUIDocument.Document;

            if (!ConfigurationForm.TryGetSettings(document, out var settings))
            {
                return(Result.Cancelled);
            }

            try
            {
                return(settings.Direction switch
                {
                    Direction.Export => ExportData(document, settings),
                    Direction.Import => ImportData(document, settings),
                    _ => Result.Succeeded,
                });
            }