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> /// 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 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 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 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 override void ShutDown(bool shutDownHost) { DisposeLogic.IsShuttingDown = true; OnShuttingDown(); base.ShutDown(shutDownHost); // unsubscribe events RevitServicesUpdater.UnRegisterAllChangeHooks(); UnsubscribeDocumentManagerEvents(); UnsubscribeRevitServicesUpdaterEvents(); UnsubscribeTransactionManagerEvents(); if (shutDownHost) { // this method cannot be called without Revit 2014 var exitCommand = RevitCommandId.LookupPostableCommandId(PostableCommand.ExitRevit); UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; IdlePromise.ExecuteOnIdleAsync( () => { if (uiapp.CanPostCommand(exitCommand)) { uiapp.PostCommand(exitCommand); } else { MessageBox.Show( "A command in progress prevented Dynamo from closing revit. Dynamo update will be cancelled."); } }); } }