/// <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 { // create a form to display the information of view filters using (ViewFiltersForm infoForm = new ViewFiltersForm(commandData)) { infoForm.ShowDialog(); } return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception ex) { // If there is something wrong, give error information and return failed message = ex.Message; return(Autodesk.Revit.UI.Result.Failed); } }
/// <summary> /// Check if input name is valid for new filter, the name should be unique /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okButton_Click(object sender, EventArgs e) { // Check name is not empty String newName = newFilterNameTextBox.Text.Trim(); if (String.IsNullOrEmpty(newName)) { ViewFiltersForm.MyMessageBox("Filter name is empty!"); newFilterNameTextBox.Focus(); return; } // // Check if filter name contains invalid characters // These character are different from Path.GetInvalidFileNameChars() char[] invalidFileChars = { '\\', ':', '{', '}', '[', ']', '|', ';', '<', '>', '?', '\'', '~' }; foreach (char invalidChr in invalidFileChars) { if (newName.Contains(invalidChr)) { ViewFiltersForm.MyMessageBox("Filter name contains invalid character: " + invalidChr); return; } } // // Check if name is used // check if name is already used by other filters bool inUsed = m_inUseFilterNames.Contains(newName, StringComparer.OrdinalIgnoreCase); if (inUsed) { ViewFiltersForm.MyMessageBox("The name you supplied is already in use. Enter a unique name please."); newFilterNameTextBox.Focus(); return; } m_filterName = newName; this.Close(); this.DialogResult = DialogResult.OK; }