public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiapp = commandData.Application; var app = uiapp.Application; App = app; var uidoc = uiapp.ActiveUIDocument; var doc = uidoc.Document; var sel = uidoc.Selection; var acview = doc.ActiveView; app.DocumentChanged += OnDocumentChanged; uiapp.Idling += OnIdling; floor = sel.PickObject(ObjectType.Element, doc.GetSelectionFilter(m => m is Floor)).GetElement(doc) as Floor; #if Revit2019 CommandHandlerService.invokeCommandHandler("ID_OBJECTS_PROJECT_CURVE"); #endif #if Revit2016 //调用postablecommand var commandid = RevitCommandId.LookupPostableCommandId(PostableCommand.ModelLine); uiapp.PostCommand(commandid); #endif return(Result.Succeeded); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.curCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); ModifyScene(uiapp, "Page Alignment Tool", PageAlignmentTool); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; // Built-in Revit commands are listed in the // PostableCommand enumeration RevitCommandId id_built_in = RevitCommandId.LookupPostableCommandId( PostableCommand.SheetIssuesOrRevisions); // External tool commands defined by add-ins are // identified by the client id specified in // the add-in manifest. It is also listed in the // journal file when the command is launched // manually. string name = "64b3d907-37cf-4cab-8bbc-3de9b66a3efa"; // --> id 35024 RevitCommandId id_addin_external_tool_cmd = RevitCommandId.LookupCommandId( name); uiapp.PostCommand(id_addin_external_tool_cmd); return(Result.Succeeded); }
/// <summary> /// Creates and idling task that will bind our own Synch to Central command to existing one. /// </summary> public static void CreateSynchToCentralOverride() { AppCommand.EnqueueTask(app => { try { var commandId = RevitCommandId.LookupCommandId("ID_FILE_SAVE_TO_MASTER"); var commandId2 = RevitCommandId.LookupCommandId("ID_FILE_SAVE_TO_MASTER_SHORTCUT"); if (commandId == null || commandId2 == null || !commandId2.CanHaveBinding || !commandId.CanHaveBinding) { return; } // (Konrad) We shouldn't be registering the same event handler more than once. It will throw an exception if we do. // It would also potentially cause the event to be fired multiple times. if (!AppCommand.IsSynchOverriden) { var binding = app.CreateAddInCommandBinding(commandId); binding.Executed += (sender, e) => OnSynchToCentral(sender, e, SynchType.Synch); AppCommand.IsSynchOverriden = true; } if (!AppCommand.IsSynchNowOverriden) { var binding2 = app.CreateAddInCommandBinding(commandId2); binding2.Executed += (sender, e) => OnSynchToCentral(sender, e, SynchType.SynchNow); AppCommand.IsSynchNowOverriden = true; } } catch (Exception e) { Log.AppendLog(LogMessageType.EXCEPTION, e.Message); } }); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; Document doc = uiapp.ActiveUIDocument.Document; Demo1Updater closeUpdater = new Demo1Updater(uiapp.ActiveAddInId); if (UpdaterRegistry.IsUpdaterRegistered(closeUpdater.GetUpdaterId())) { UpdaterRegistry.UnregisterUpdater(closeUpdater.GetUpdaterId()); } //注册更新 Demo1Updater demo1Updater = new Demo1Updater(uiapp.ActiveAddInId); UpdaterRegistry.RegisterUpdater(demo1Updater); ElementCategoryFilter roomFilter = new ElementCategoryFilter(BuiltInCategory.OST_Rooms); UpdaterRegistry.AddTrigger(demo1Updater.GetUpdaterId(), roomFilter, Element.GetChangeTypeElementAddition()); RevitCommandId room_CommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Room); if (uiapp.CanPostCommand(room_CommandId)) { uiapp.PostCommand(room_CommandId); } ////注销更新 //UpdaterRegistry.UnregisterUpdater(demo1Updater.GetUpdaterId()); return(Result.Succeeded); }
/// <summary> /// Implements the OnStartup event /// </summary> /// <param name="application"></param> /// <returns></returns> public Result OnStartup(UIControlledApplication application) { // Lookup the desired command by name s_commandId = RevitCommandId.LookupCommandId(s_commandToDisable); // Confirm that the command can be overridden if (!s_commandId.CanHaveBinding) { ShowDialog("Error", "The target command " + s_commandToDisable + " selected for disabling cannot be overridden"); return(Result.Failed); } // Create a binding to override the command. // Note that you could also implement .CanExecute to override the accessibiliy of the command. // Doing so would allow the command to be grayed out permanently or selectively, however, // no feedback would be available to the user about why the command is grayed out. try { AddInCommandBinding commandBinding = application.CreateAddInCommandBinding(s_commandId); commandBinding.Executed += DisableEvent; } // Most likely, this is because someone else has bound this command already. catch (Exception) { ShowDialog("Error", "This add-in is unable to disable the target command " + s_commandToDisable + "; most likely another add-in has overridden this command."); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; try { // External tool commands defined by add-ins are identified by the client id specified in // the add-in manifest. It is also listed in the journal file when the command is launched manually. string name = "BA2E663D-EFAF-4E11-B304-923314D8817D"; // --> Chiama l'Add-in PluginConfiguration RevitCommandId id_addin_external_tool_cmd = RevitCommandId.LookupCommandId( name); uiapp.PostCommand(id_addin_external_tool_cmd); return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.curCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); ModifyScene(uiapp, "Create Design Options", CreateDesignOptions); }
Result IExternalApplication.OnStartup(UIControlledApplication applicationUI) { if (StartupMode == AddinStartupMode.Cancelled) { return(Result.Cancelled); } ApplicationUI = applicationUI; EventHandler <ApplicationInitializedEventArgs> applicationInitialized = null; ApplicationUI.ControlledApplication.ApplicationInitialized += applicationInitialized = (sender, args) => { ApplicationUI.ControlledApplication.ApplicationInitialized -= applicationInitialized; Revit.ActiveUIApplication = new UIApplication(sender as Autodesk.Revit.ApplicationServices.Application); if (StartupMode < AddinStartupMode.AtStartup) { return; } if (Revit.OnStartup(Revit.ApplicationUI) == Result.Succeeded) { if (StartupMode == AddinStartupMode.Scripting) { Revit.ActiveUIApplication.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.ExitRevit)); } } }; // Add launch RhinoInside push button UI.CommandRhinoInside.CreateUI(applicationUI.CreateRibbonPanel("Rhinoceros")); return(Result.Succeeded); }
//This is the Method that creates the Selection box around the elements for the selected row private void btnSelectionBox_Click(object sender, EventArgs e) { //Check to make sure that only 1 row is selected if (dgWarnings.SelectedRows.Count == 1) { //create a RevitCommandId to utilize Revit's built in SelectionBox feature for our selected ElementIds RevitCommandId rvtId = RevitCommandId.LookupPostableCommandId(PostableCommand.SelectionBox); //Get the ElementIds associated from the DataGridView ICollection <ElementId> eId = new List <ElementId>(); //Use a try statment so an error won't crash revit try { //Get the Element Ids for the selected row int he DataGridView eId = (ICollection <ElementId>)dgWarnings.SelectedRows[0].Cells[2].Value; //Don't know why, but without creating another ICollection and setting it, the SelectionBox will not work ICollection <ElementId> iDs = eId; //Sets the current selection to the Warning Element(s) uiApp.ActiveUIDocument.Selection.SetElementIds(iDs); //Creates a selection box around all elements for that warning uiApp.PostCommand(rvtId); } //Catch any errors and display a Dialog with the informaiton catch (Exception ex) { TaskDialog.Show("Selection Box Error", ex.ToString()); } } //Tell the user they can only have one row selected else { TaskDialog.Show("Single Selection", "Select single row for Selection Box"); } }
public Result OnStartup(UIControlledApplication application) { try { application.ControlledApplication.DocumentOpened += EventDocOpen; application.ControlledApplication.DocumentClosing += EventDocClose; application.ControlledApplication.DocumentSynchronizingWithCentral += EventSwcStart; application.ControlledApplication.DocumentSynchronizedWithCentral += EventSwcStop; application.ControlledApplication.DocumentChanged += EventCommandFinished; if (_binding != null) { return(Result.Succeeded); } _commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.PurgeUnused); if (!_commandId.CanHaveBinding) { return(Result.Succeeded); } _binding = application.CreateAddInCommandBinding(_commandId); _binding.BeforeExecuted += EventCommandStart; return(Result.Succeeded); } catch (Exception e) { Log.AppendLog(LogMessageType.EXCEPTION, e.Message); return(Result.Failed); } }
static void ShowShortcutHelp(object sender, EventArgs e) { if (sender is IExternalCommand) { External.ActivationGate.Exit -= ShowShortcutHelp; using ( var taskDialog = new TaskDialog("New Shortcut") { Id = $"{MethodBase.GetCurrentMethod().DeclaringType}.{MethodBase.GetCurrentMethod().Name}", MainIcon = UIX.TaskDialogIcons.IconInformation, TitleAutoPrefix = true, AllowCancellation = true, MainInstruction = $"Keyboard shortcut 'R' is now assigned to Rhino", MainContent = $"You can use R key to restore previously visible Rhino windows over Revit window every time you need them.", FooterText = "This is a one time message", } ) { taskDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Customize keyboard shortcuts…"); if (taskDialog.Show() == TaskDialogResult.CommandLink1) { Revit.ActiveUIApplication.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.KeyboardShortcuts)); } } } }
public void Execute(UIApplication uiapp) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; try { string result = "F"; TransactionGroup tr = new TransactionGroup(doc); tr.Start("Save As"); result = Save_As(uiapp, doc); tr.Assimilate(); if (result == "S") { doc.Save(); string pa = doc.PathName; File.Copy(pa, path.Text + "\\" + name.Text + ".rvt", true); RevitCommandId saveDoc = RevitCommandId.LookupPostableCommandId(PostableCommand.Undo); uiapp.PostCommand(saveDoc); Data_File(path.Text + "\\" + name.Text + ".rvt", doc); MessageBox.Show("Save As Success!", "SUCCESS", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return; }
static void CloseDocByCommand(UIApplication uiapp) { RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId( PostableCommand.Close); uiapp.PostCommand(closeDoc); }
/// <summary> /// Loads the default Mass template automatically rather than showing UI. /// </summary> /// <param name="application">An object that is passed to the external application /// which contains the controlled application.</param> void createCommandBinding(UIControlledApplication application) { RevitCommandId wallCreate = RevitCommandId.LookupCommandId("ID_NEW_REVIT_DESIGN_MODEL"); AddInCommandBinding binding = application.CreateAddInCommandBinding(wallCreate); binding.Executed += new EventHandler <Autodesk.Revit.UI.Events.ExecutedEventArgs>(binding_Executed); binding.CanExecute += new EventHandler <Autodesk.Revit.UI.Events.CanExecuteEventArgs>(binding_CanExecute); }
/// <summary> /// Open a default 3d view /// <reference>https://forums.autodesk.com/t5/revit-api-forum/generate-3d-view-programmatically/td-p/5808509</reference> /// </summary> public void Open3DView() { RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Default3DView); if (RvtUiApp.CanPostCommand(commandId)) { RvtUiApp.PostCommand(commandId); } }
private void button1_Click(object sender, EventArgs e) { PostableCommand command = PostableCommand.AcquireCoordinates; Enum.TryParse <PostableCommand>(_list[i], out command); label1.Text = _list[i]; _cmdDataForm.Application.PostCommand(RevitCommandId.LookupPostableCommandId(command)); i++; }
public Result OnStartup(UIControlledApplication uiControlledApplication) { try { //binding commands RevitCommandId commandId = RevitCommandId.LookupCommandId("ID_MEP_DUCT_PRESSURE_LOSS_REPORT"); if (commandId != null) { AddInCommandBinding pressureLossCommand = uiControlledApplication.CreateAddInCommandBinding(commandId); if (pressureLossCommand != null) { pressureLossCommand.CanExecute += new EventHandler <Autodesk.Revit.UI.Events.CanExecuteEventArgs>(CanDuctExecute); pressureLossCommand.Executed += new EventHandler <Autodesk.Revit.UI.Events.ExecutedEventArgs>(DuctExecute); } } commandId = RevitCommandId.LookupCommandId("ID_MEP_PIPE_PRESSURE_LOSS_REPORT"); if (commandId != null) { AddInCommandBinding pressureLossCommand = uiControlledApplication.CreateAddInCommandBinding(commandId); if (pressureLossCommand != null) { pressureLossCommand.CanExecute += new EventHandler <Autodesk.Revit.UI.Events.CanExecuteEventArgs>(CanPipeExecute); pressureLossCommand.Executed += new EventHandler <Autodesk.Revit.UI.Events.ExecutedEventArgs>(PipeExecute); } } commandId = RevitCommandId.LookupCommandId("ID_MEP_SELECT_DUCT_PRESSURE_LOSS_REPORT"); if (commandId != null) { AddInCommandBinding pressureLossCommand = uiControlledApplication.CreateAddInCommandBinding(commandId); if (pressureLossCommand != null) { pressureLossCommand.CanExecute += new EventHandler <Autodesk.Revit.UI.Events.CanExecuteEventArgs>(CanDuctSelectExecute); pressureLossCommand.Executed += new EventHandler <Autodesk.Revit.UI.Events.ExecutedEventArgs>(DuctSelectExecute); } } commandId = RevitCommandId.LookupCommandId("ID_MEP_SELECT_PIPE_PRESSURE_LOSS_REPORT"); if (commandId != null) { AddInCommandBinding pressureLossCommand = uiControlledApplication.CreateAddInCommandBinding(commandId); if (pressureLossCommand != null) { pressureLossCommand.CanExecute += new EventHandler <Autodesk.Revit.UI.Events.CanExecuteEventArgs>(CanPipeSelectExecute); pressureLossCommand.Executed += new EventHandler <Autodesk.Revit.UI.Events.ExecutedEventArgs>(PipeSelectExecute); } } return(Result.Succeeded); } catch { return(Result.Failed); } }
/// <summary> /// Implementation of Startup for the external application. /// </summary> /// <param name="application">The Revit application.</param> /// <returns>The result (typically Succeeded).</returns> public Result OnStartup(UIControlledApplication application) { // Register execution override RevitCommandId commandId = RevitCommandId.LookupCommandId("ID_EXPORT_IFC"); m_ifcCommandBinding = application.CreateAddInCommandBinding(commandId); m_ifcCommandBinding.Executed += OnIFCExport; return(Result.Succeeded); }
public void PostCommandAndUpdateNewElementProperties(Document doc, PostableCommand postableCommand, string transactionName, BuiltInParameter bip, string value) { StartTrackingElements(); StartCancellingAllDialogs(); var postableCommandId = RevitCommandId.LookupPostableCommandId(postableCommand); App.PostCommand(postableCommandId); PostElementPropertyUpdateRequest(doc, transactionName, bip, value); }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uiDoc = app.ActiveUIDocument; Document doc = uiDoc.Document; Autodesk.Revit.DB.View curView = null; View3D usableView = null; //if the current view is 3d (future correction => valid for IFC import) if (doc.ActiveView.ViewType != ViewType.ThreeD) { //try to use an existing 3D view IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any(o => o.Name == "{3D}" || o.Name == "BCFortho" || o.Name == "BCFpersp")) { usableView = viewcollector3D.First(o => o.Name == "{3D}" || o.Name == "BCFortho" || o.Name == "BCFpersp"); } // No valid view to use for importing if (usableView == null) { System.Windows.MessageBox.Show("Bim snippet can't be imported since\n the project contains no valid view."); return; } // set the view to a usableView for importing the IFC snippet uiDoc.ActiveView = usableView; } // Show the import screen app.PostCommand(RevitCommandId.LookupCommandId("ID_IFC_LINK")); //Run a background worker to insert the name of the file to import BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += new DoWorkEventHandler(DoWork); bgw.RunWorkerCompleted += (_, __) => { if (curView != null) { uiDoc.ActiveView = curView; } }; bgw.RunWorkerAsync(); } catch (Exception e) { System.Windows.MessageBox.Show("A service has failed."); } }
private void LoadFamily() { try { RevitCommandId loadFamilyCommand = RevitCommandId.LookupPostableCommandId(PostableCommand.LoadShapes); if (uidoc.Application.CanPostCommand(loadFamilyCommand)) { uidoc.Application.PostCommand(loadFamilyCommand); } } catch { } }
/// <summary> /// The function that is called to finish the execution of the workflow. Cleans up subscribed events, /// and posts the save command. /// </summary> /// <param name="uiApp"></param> private void CleanupAfterRevisionEdit(UIApplication uiApp) { // Remove dialog box showing uiApp.DialogBoxShowing -= HideDocumentNotSaved; if (binding != null) { binding.BeforeExecuted -= ReactToRevisionsAndSchedulesCommand; } externalEvent = null; // Repost the save command uiApp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.Save)); }
public static void PostCmd_rotate(UIApplication uiapp) { Selection sel = uiapp.ActiveUIDocument.Selection; sel.SetElementIds(new List <ElementId> { tempFi1.Id }); var commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Rotate); if (uiapp.CanPostCommand(commandId)) { uiapp.PostCommand(commandId); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; RevitCommandId id_addin_button_cmd = RevitCommandId.LookupPostableCommandId( (PostableCommand)6417); uiapp.PostCommand(id_addin_button_cmd); return(Result.Succeeded); }
/// <summary> /// Metodo che chiude il documento attivo /// </summary> /// <remarks> /// </remarks> /// <param name="uiapp">L'oggetto Applicazione di Revit</param> private void CloseDocByCommand(UIApplication uiapp) { if (uiapp.ActiveUIDocument.Document != null) { Document doc = uiapp.ActiveUIDocument.Document; // Dà il comando di chiusura del documento aperto RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId( PostableCommand.Close); uiapp.PostCommand(closeDoc); // Assegno alla comboBox della View il valore predefinito modelessForm.AssignValueComboBoxDefault(); } }
private static void ShutdownRevitHost() { // this method cannot be called without Revit 2014 var exitCommand = RevitCommandId.LookupPostableCommandId(PostableCommand.ExitRevit); var uiApplication = DocumentManager.Instance.CurrentUIApplication; if ((uiApplication != null) && uiApplication.CanPostCommand(exitCommand)) { uiApplication.PostCommand(exitCommand); } else { MessageBox.Show( "A command in progress prevented Dynamo from " + "closing revit. Dynamo update will be cancelled."); } }
private void createNewDesignOptions() { string mesStr = "There are no existing design options, do you want to create?"; DialogResult result = MessageBox.Show(mesStr, "Create New Design Options", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.Yes) { allowToCreate = true; RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); uiapp.PostCommand(commandId); } else { allowToCreate = false; uiapp.Idling -= Application_Idling; } }
/// <summary> /// Prompts to edit the revision and resave. /// </summary> /// <param name="application"></param> private void PromptToEditRevisionsAndResave(UIApplication application) { // Setup external event to be notified when activity is done externalEvent = ExternalEvent.Create(new PostCommandRevisionMonitorEvent(this)); // Setup event to be notified when revisions command starts (this is a good place to raise this external event) RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.SheetIssuesOrRevisions); if (binding == null) { binding = application.CreateAddInCommandBinding(id); } binding.BeforeExecuted += ReactToRevisionsAndSchedulesCommand; // Post the revision editing command application.PostCommand(id); }
//public Guid UpdaterGuid { get; set; } = new Guid("90391154-67BB-452E-A1A7-A07A98B94F86"); /// <summary> /// Creates an idling task that will bind our own Reload Latest command to existing one. /// </summary> public static void CreateLinkUnloadOverride(UIApplication app) { try { var commandId = RevitCommandId.LookupCommandId("ID_UNLOAD_FOR_ALL_USERS"); if (commandId == null || !commandId.CanHaveBinding) { return; } var binding = app.CreateAddInCommandBinding(commandId); binding.Executed += OnUnloadForAllUsers; } catch (Exception e) { Log.AppendLog(LogMessageType.EXCEPTION, e.Message); } }