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 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 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); } }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.curCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); ModifyScene(uiapp, "Create Design Options", CreateDesignOptions); }
public void Execute(UIApplication uiapp) { this.uiapp = uiapp; this.curCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DesignOptions); ModifyScene(uiapp, "Page Alignment Tool", PageAlignmentTool); }
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; }
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); }
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); }
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); }
//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"); } }
static void CloseDocByCommand(UIApplication uiapp) { RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId( PostableCommand.Close); uiapp.PostCommand(closeDoc); }
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++; }
/// <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); } }
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> /// 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)); }
private void LoadFamily() { try { RevitCommandId loadFamilyCommand = RevitCommandId.LookupPostableCommandId(PostableCommand.LoadShapes); if (uidoc.Application.CanPostCommand(loadFamilyCommand)) { uidoc.Application.PostCommand(loadFamilyCommand); } } catch { } }
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 static void PostCmd_copy(UIApplication uiapp) { //用以监控新生成的tempFi uiapp.Application.DocumentChanged += new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged); Selection sel = uiapp.ActiveUIDocument.Selection; sel.SetElementIds(new List <ElementId> { tempFi1.Id }); var commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Copy); if (uiapp.CanPostCommand(commandId)) { uiapp.PostCommand(commandId); } }
public void setSelection(ElementId elemId, UIDocument uiDoc) { ExCommand.FormToShow.EnableControls(); if (uiDoc.Document.GetElement(elemId) == null) { TaskDialog.Show("Внимание", "Не удалось найти элемент в модели"); return; } using (var tr = new Transaction(uiDoc.Document)) { tr.Start("FocusOnClash"); uiDoc.Selection.SetElementIds(new List <ElementId>() { elemId }); uiDoc.Application.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.SelectionBox)); tr.Commit(); } }
/// <summary> /// 提示编辑修订版本号,并重新保存 /// </summary> /// <param name="application"></param> private void PromptToEditRevisionsAndResave(UIApplication application) { // Setup external event to be notified when activity is done externalEvent = ExternalEvent.Create(new PostCommandRevisionMonitorEventHandler(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; //在执行RevitCommandId之前,执行externalEvent,也就是 CleanupAfterRevisionEdit 方法,这个方法注销了注册的事件,并 repost了 Save 命令 //这里为什么要使用外部事件?先执行屏蔽“未保存文件”对话框,然后外部事件排队,执行修订命令的对话框,执行结束后revit空闲,这里才执行 CleanupAfterRevisionEdit 方法,注销事件(以防止影响到其他命令),在调用保存方法。 // Post the revision editing command application.PostCommand(id); }
public static void ProjectBrowserOnOff(UIApplication uiApp, NewForm ui, Document doc) { Util.LogThreadInfo("Project Browser On Off"); // rename all the sheets, but first open a transaction using (Transaction t = new Transaction(doc, "Project Browser On Off")) { Util.LogThreadInfo("Project Browser On Off Transaction"); // start a transaction within the valid Revit API context t.Start("Project Browser On Off"); // our command is a postable command RevitCommandId id_built_in = RevitCommandId.LookupPostableCommandId(PostableCommand.ProjectBrowser); uiApp.PostCommand(id_built_in); t.Commit(); t.Dispose(); } }
public static void SetThinLines( UIApplication app, bool makeThin) { bool isAlreadyThin = IsThinLines(); if (makeThin != isAlreadyThin) { // Switch TL state by invoking // PostableCommand.ThinLines RevitCommandId commandId = RevitCommandId.LookupPostableCommandId( PostableCommand.ThinLines); if (app.CanPostCommand(commandId)) { app.PostCommand(commandId); } } }
public void TwinMotionExportFbx(Document doc) { //Document doc = this.ActiveUIDocument.Document; Application app = doc.Application; UIApplication uiapp = new UIApplication(app); try { RevitCommandId id = RevitCommandId .LookupPostableCommandId( PostableCommand.PlaceAComponent); string name = "CustomCtrl_%CustomCtrl_%" + "Twinmotion 2020%Twinmotion Direct Link%" + "ExportButton"; RevitCommandId id_addin = RevitCommandId .LookupCommandId(name); if (id_addin != null) { uiapp.DialogBoxShowing += new EventHandler <DialogBoxShowingEventArgs>( OnDialogBoxShowing); RunCommands(uiapp, id_addin); } } catch { TaskDialog.Show("Test", "error"); } finally { uiapp.DialogBoxShowing -= new EventHandler <DialogBoxShowingEventArgs>( OnDialogBoxShowing); } }
static void ShowShortcutHelp() { using ( var taskDialog = new TaskDialog(MethodBase.GetCurrentMethod().DeclaringType.FullName) { Title = "New Shortcut", MainIcon = TaskDialogIcons.IconInformation, TitleAutoPrefix = true, AllowCancellation = true, MainInstruction = $"Keyboard shortcut '{ShortcutAssigned}' is now assigned to Rhino", MainContent = $"You can use {ShortcutAssigned} 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)); } } }
void needsCollaboration(Object sender) { if (current != null) { Autodesk.Revit.ApplicationServices.Application app = sender as Autodesk.Revit.ApplicationServices.Application; UIApplication uiapp = new UIApplication(app); var filter = Builders <BsonDocument> .Filter.Eq("_id", current["_id"]); var update = Builders <BsonDocument> .Update.Set("is_running", true); collection.UpdateOne(filter, update); uiapp.OpenAndActivateDocument(_test_project_filepath); RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId(PostableCommand.Close); uiapp.PostCommand(closeDoc); } else { closeRevit(); } }