Beispiel #1
0
        /// <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);
                }
            });
        }
Beispiel #2
0
        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);
        }
        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);
            }
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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);
        }
        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);
            }
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
        /// <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.");
            }
        }
        //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);
            }
        }
        /// <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)
        {
            TryLoadCommonAssembly();

            // Register execution override
            RevitCommandId commandId = RevitCommandId.LookupCommandId("ID_EXPORT_IFC");

            try
            {
                m_ifcCommandBinding = application.CreateAddInCommandBinding(commandId);
            }
            catch
            {
                return(Result.Failed);
            }

            m_ifcCommandBinding.Executed += OnIFCExport;
            return(Result.Succeeded);
        }
Beispiel #11
0
        //The following Method will bind the Revit Command to the indicated Method. In this case it is the DisableCommand Method
        private Result AddCommandBindings(UIControlledApplication uiApp, string name)
        {
            //Get the RevitCommandId from the Name of the Command passed on Start Up
            RevitCommandId rCommandId = RevitCommandId.LookupCommandId(name);

            //Make sure the Command can have a binding, and that another application hasn't already bound to it.
            //Command can only have One binding for all add-ins
            if (rCommandId.CanHaveBinding && !rCommandId.HasBinding)
            {
                //Set the Method that the bound command will execute when a user "presses" the button on the Ribbon
                uiApp.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler <ExecutedEventArgs>(this.DisableCommand);
            }
            else
            {
                //Tell the User that the Command cannot be bound
                TaskDialog.Show(name + " Binding", "The " + name + " Command can not have Binding or is already Bound");
            }

            return(Result.Succeeded);
        }
Beispiel #12
0
        /// <summary>
        /// Creates an idling task that will bind our own Reload Latest command to existing one.
        /// </summary>
        public static void CreateReloadLatestOverride()
        {
            AppCommand.EnqueueTask(app =>
            {
                try
                {
                    var commandId = RevitCommandId.LookupCommandId("ID_WORKSETS_RELOAD_LATEST");
                    if (commandId == null || !commandId.CanHaveBinding)
                    {
                        return;
                    }

                    var binding       = app.CreateAddInCommandBinding(commandId);
                    binding.Executed += OnReloadLatest;
                }
                catch (Exception e)
                {
                    Log.AppendLog(LogMessageType.EXCEPTION, e.Message);
                }
            });
        }
        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);
            }
        }
        public Result OnStartup(UIControlledApplication application)
        {
            try
            {
                if (false == TryResolveDynamoCore())
                {
                    return(Result.Failed);
                }

                UIControlledApplication = application;
                ControlledApplication   = application.ControlledApplication;

                SubscribeAssemblyEvents();
                SubscribeApplicationEvents();

                TransactionManager.SetupManager(new AutomaticTransactionStrategy());
                ElementBinder.IsEnabled = true;

                var dynamoCmdId = RevitCommandId.LookupCommandId("ID_VISUAL_PROGRAMMING_DYNAMO");
                dynamoCommand                 = application.CreateAddInCommandBinding(dynamoCmdId);
                dynamoCommand.CanExecute     += canExecute;
                dynamoCommand.BeforeExecuted += beforeExecuted;
                dynamoCommand.Executed       += executed;
                DynamoButtonEnabled           = true; //initialize

                RegisterAdditionalUpdaters(application);

                RevitServicesUpdater.Initialize(DynamoRevitApp.Updaters);
                SubscribeDocumentChangedEvent();

                loadDependentComponents();

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(Result.Failed);
            }
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        public void LaunchCommand(string text)
        {
            var commandName = string.Empty;

            switch (text)
            {
            case "Links Manager":
                commandName =
                    "CustomCtrl_%CustomCtrl_%   HOK   %Mission Control%LinksManager_Command";
                break;

            case "Groups Manager":
                commandName =
                    "CustomCtrl_%CustomCtrl_%   HOK   %Mission Control%GroupManager_Command";
                break;

            case "Styles Manager":
                commandName =
                    "CustomCtrl_%CustomCtrl_%   HOK   %Mission Control%StylesManager_Command";
                break;
            }

            if (string.IsNullOrEmpty(commandName))
            {
                return;
            }

            var addinId = RevitCommandId.LookupCommandId(commandName);

            if (addinId == null)
            {
                return;
            }

            AppCommand.EnqueueTask(app =>
            {
                app.PostCommand(addinId);
            });
        }
Beispiel #16
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;

            // External tool commands defined by add-ins are
            // identified by the string listed in the
            // journal file when the command is launched
            // manually.

            string name_addin_button_cmd
                = "CustomCtrl_%CustomCtrl_%"
                  + "Add-Ins%Post Add-in Command%Dummy2"; // --> id 6417

            RevitCommandId id_addin_button_cmd
                = RevitCommandId.LookupCommandId(
                      name_addin_button_cmd);

            uiapp.PostCommand(id_addin_button_cmd);

            return(Result.Succeeded);
        }
        public Result OnStartup(UIControlledApplication application)
        {
            uiControlledApplication = application;
            var revitVersion = application.ControlledApplication.VersionNumber;

            var revitFolder =
                new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            var debugPath      = revitFolder.Parent.FullName;
            var dynamoProducts = FindDynamoRevitInstallations(debugPath, revitVersion);

            Products         = new List <DynamoProduct>();
            PlaylistProducts = new List <DynamoProduct>();
            foreach (var p in dynamoProducts)
            {
                var path = VersionLoader.GetDynamoRevitPath(p, revitVersion);
                if (!File.Exists(path))
                {
                    continue;
                }

                Products.Add(p);

                if (p.VersionInfo.Major >= MinDynamoMajorVersionForPlaylist &&
                    p.VersionInfo.Minor >= MinDynamoMinorVersionForPlaylist)
                {
                    PlaylistProducts.Add(p);
                }
            }

            if (Products.Count == 0)
            {
                return(Result.Failed);
            }

            Result preliminaryLoadResult = Result.Succeeded;

            // If there are multiple versions installed, then do the command
            // binding to prompt for version selector task dialog for user to
            // select specific Dynamo version.
            if (Products.Count > 1)
            {
                var dynamoCmdId = RevitCommandId.LookupCommandId("ID_VISUAL_PROGRAMMING_DYNAMO");
                dynamoCommand                 = application.CreateAddInCommandBinding(dynamoCmdId);
                dynamoCommand.CanExecute     += canExecute;
                dynamoCommand.BeforeExecuted += beforeExecuted;
                dynamoCommand.Executed       += executed;

                if (PlaylistProducts.Count >= 1)
                {
                    var dynamoPlayerCmdId = RevitCommandId.LookupCommandId("ID_PLAYLIST_DYNAMO");
                    if (dynamoPlayerCmdId != null)
                    {
                        dynamoPlayerCommand                 = application.CreateAddInCommandBinding(dynamoPlayerCmdId);
                        dynamoPlayerCommand.CanExecute     += canExecute;
                        dynamoPlayerCommand.BeforeExecuted += beforeExecuted;
                        dynamoPlayerCommand.Executed       += executedPlaylist;
                    }
                }
            }
            else //If only one product is installed load the Revit App directly
            {
                preliminaryLoadResult = loadProduct(Products.First(), revitVersion);
            }

            return(preliminaryLoadResult);
        }
        /// <summary>
        /// Launches specific version of Dynamo command
        /// </summary>
        /// <param name="product">DynamoProduct to launch</param>
        /// <param name="e">Command executed event argument</param>
        /// <param name="playlist">Launch the Playlist app or just Dynamo</param>
        /// <returns>true for success</returns>
        private bool LaunchDynamoCommand(DynamoProduct product, ExecutedEventArgs e, bool playlist = false)
        {
            if (uiControlledApplication == null)
            {
                throw new InvalidOperationException();
            }

            var revitVersion = uiControlledApplication.ControlledApplication.VersionNumber;
            var path         = GetDynamoRevitPath(product, revitVersion);
            var data         = new VersionSelectorData()
            {
                RevitVersion = revitVersion, SelectedVersion = product.VersionInfo
            };

            data.WriteToRegistry();

            //Initialize application
            var ass      = Assembly.LoadFrom(path);
            var revitApp = ass.CreateInstance("Dynamo.Applications.DynamoRevitApp");

            if (null == revitApp)
            {
                return(false);
            }

            //Remove the command binding, because now DynamoRevitApp will
            //do the command binding for DynamoRevit command.
            RemoveCommandBinding();

            var type   = revitApp.GetType();
            var result = type.GetMethod("OnStartup").Invoke(revitApp, new object[] { uiControlledApplication });

            if ((Result)result != Result.Succeeded)
            {
                return(false);
            }

            UIApplication uiApp = new UIApplication(e.ActiveDocument.Application);

            if (!playlist)
            {
                //Invoke command
                string message = string.Empty;
                result = type.GetMethod("ExecuteDynamoCommand").Invoke(revitApp, new object[] { e.GetJournalData(), uiApp });
                if ((Result)result != Result.Succeeded)
                {
                    return(false);
                }
            }
            else
            {
                //Dependent components have done a re-binding of Playlist command in order to be executed in their context.
                //In order to lunch the Playlist we just need to post the command to the Revit application.
                var dynamoPlayerCmdId = RevitCommandId.LookupCommandId("ID_PLAYLIST_DYNAMO");
                if (dynamoPlayerCmdId != null)
                {
                    uiApp.PostCommand(dynamoPlayerCmdId);
                }
            }

            uiControlledApplication = null; //release application, no more needed.
            return(true);
        }
Beispiel #19
0
        }                                                          // declare assembly version property

        public Result OnStartup(UIControlledApplication application)
        {
            AssemblyPath    = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //get ribbon assembly directory.
            AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            #region Import CAD message
            UIControlledApplication uicontrolapp    = application;
            RevitCommandId          importCommandId = RevitCommandId.LookupCommandId("ID_FILE_IMPORT");
            try
            {
                AddInCommandBinding importBinding = uicontrolapp.CreateAddInCommandBinding(importCommandId);
                importBinding.BeforeExecuted += new EventHandler <Autodesk.Revit.UI.Events.BeforeExecutedEventArgs>(ImportReplacement);
            }
            catch (Exception)
            {
                throw;
            }
            #endregion

            #region InPlace component message
            RevitCommandId inplaceCommandId = RevitCommandId.LookupCommandId("ID_INPLACE_COMPONENT");
            try
            {
                AddInCommandBinding inplaceBinding = uicontrolapp.CreateAddInCommandBinding(inplaceCommandId);
                inplaceBinding.BeforeExecuted += new EventHandler <Autodesk.Revit.UI.Events.BeforeExecutedEventArgs>(InplaceReplacement);
            }
            catch (Exception)
            {
                throw;
            }
            #endregion

            #region Create Ribbon tab
            application.CreateRibbonTab(ArpTabName);
            #endregion

            #region Create Panels
            //create ribbon panels
            RibbonPanel helpPanel            = application.CreateRibbonPanel(ArpTabName, "ARP Toolkit v" + AssemblyVersion);
            RibbonPanel modellingPanel       = application.CreateRibbonPanel(ArpTabName, "Modelling");
            RibbonPanel drawingsPanel        = application.CreateRibbonPanel(ArpTabName, "Drawings");
            RibbonPanel printPanel           = application.CreateRibbonPanel(ArpTabName, "Print & Export");
            RibbonPanel modelManagementPanel = application.CreateRibbonPanel(ArpTabName, "Model Management");
            #endregion

            #region Create Buttons
            // PANEL HELP
            #region Help
            PushButtonData helpButtonData = new PushButtonData(
                "cmdHelp",
                "Help",
                Path.Combine(AssemblyPath, "ArpRibbon.dll"),
                "Data.CmdAbout");

            PushButton helpButton = helpPanel.AddItem(helpButtonData) as PushButton;

            helpButton.ToolTip = "ARP Tools info and User Guide.";

            BitmapImage helpLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/Help_32.ico"));
            helpButton.LargeImage = helpLargeImage;
            #endregion

            // PANEL MODELLING
            #region Flip button
            PushButtonData flipButtonData = new PushButtonData(
                "cmdFlip",
                "Flip Walls" + "\n" + "or Doors",
                Path.Combine(AssemblyPath, "Flip.dll"),
                "Entry.CmdMain");

            PushButton flipButton = modellingPanel.AddItem(flipButtonData) as PushButton;

            flipButton.ToolTip = "Flip a selection of Walls by centerline regardless of the Location Line." + "\n"
                                 + "Flip a selection of doors controlling whether you want to flip the hand or the facing.";

            BitmapImage flipLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/Flip_32.ico"));
            flipButton.LargeImage = flipLargeImage;
            #endregion

            // PANEL DRAWINGS
            #region Room Centroid and Tag Button
            PushButtonData roomCentroidButtonData = new PushButtonData(
                "cmdRoomCentroid",
                "Room Centroid," + "\n" + "Tag to Room",
                Path.Combine(AssemblyPath, "RoomCentroidAndTags.dll"),
                "Entry.CmdMain");

            PushButton roomCentroidButton = drawingsPanel.AddItem(roomCentroidButtonData) as PushButton;

            roomCentroidButton.ToolTip = "Moves room insertion point to room centroid." + "\n"
                                         + "Move room tags to room insertion point. " +
                                         "It works with both tags tagging rooms in the current model or in a linked model " +
                                         "(but linked models and current model coordinates must match).";

            BitmapImage roomCentroidLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/RoomCentroidAndTags_32.ico"));
            roomCentroidButton.LargeImage = roomCentroidLargeImage;
            #endregion

            #region Remove Empty Elevation Tags
            PushButtonData elevationTagsButtonData = new PushButtonData(
                "cmdElevationTags",
                "Remove Empty" + "\n" + "Elevation Tags",
                Path.Combine(AssemblyPath, "RemoveEmptyElevationTags.dll"),
                "Entry.CmdMain");

            PushButton elevationTagsButton = drawingsPanel.AddItem(elevationTagsButtonData) as PushButton;

            elevationTagsButton.ToolTip = "Generally if all elevations hosted in an elevation tag are deleted from the model, " + "\n"
                                          + "the empty elevation tag still remains in its location. This application will delete " + "\n"
                                          + "all empty elevation tags from the model.";

            BitmapImage elevationTagsLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/RemoveEmptyElevationTags_32.ico"));
            elevationTagsButton.LargeImage = elevationTagsLargeImage;
            #endregion

            #region Assign View Template
            PushButtonData AssignTemplateButtonData = new PushButtonData(
                "cmdAssignTemplate",
                "Assign" + "\n" + "View Templates",
                Path.Combine(AssemblyPath, "AssignViewTemplates.dll"),
                "Entry.CmdMain");

            PushButton AssignTemplateButton = drawingsPanel.AddItem(AssignTemplateButtonData) as PushButton;

            AssignTemplateButton.ToolTip = "Use this tool to assign View Templates to Views accross the project." + "\n" +
                                           "Just drag a View into a View Template to assign it.";

            BitmapImage AssignTemplateLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/AssignViewTemplates_32.ico"));
            AssignTemplateButton.LargeImage = AssignTemplateLargeImage;
            #endregion

            #region Transfer View Filters
            PushButtonData transFiltersButtonData = new PushButtonData(
                "cmdTransferViewFilters",
                "Transfer" + "\n" + "View Filters",
                Path.Combine(AssemblyPath, "TransferViewFilters.dll"),
                "Entry.CmdMain");

            PushButton transFiltersButton = drawingsPanel.AddItem(transFiltersButtonData) as PushButton;

            transFiltersButton.ToolTip = "Transfer multiple View Filters from one template to another." + "\n"
                                         + "Or override their graphic settings if the selected filters are already applied in the target Template.";

            BitmapImage transFiltersLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/TransferViewFilters_32.ico"));
            transFiltersButton.LargeImage = transFiltersLargeImage;
            #endregion

            #region Reassign Detail Number
            PushButtonData ReassignDetNumButtonData = new PushButtonData(
                "cmdReassignDetNum",
                "Reassign" + "\n" + "Detail Number",
                Path.Combine(AssemblyPath, "ReassignDetailNumbers.dll"),
                "Entry.CmdMain");

            PushButton ReassignDetNumButton = drawingsPanel.AddItem(ReassignDetNumButtonData) as PushButton;

            ReassignDetNumButton.ToolTip = "Run this tool in a sheet view and click on sheet viewports" + "\n"
                                           + "one by one to change the detail number sequentially.";

            BitmapImage ReassignDetNumLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/ReassignDetailNumber_32.ico"));
            ReassignDetNumButton.LargeImage = ReassignDetNumLargeImage;
            #endregion

            #region Sheet Duplicator
            PushButtonData sheetDuplicatorButtonData = new PushButtonData(
                "cmdSheetDuplicator",
                "Sheet" + "\n" + "Duplicator",
                Path.Combine(AssemblyPath, "SheetDuplicator.dll"),
                "Entry.CmdMain");

            PushButton sheetDuplicatorButton = drawingsPanel.AddItem(sheetDuplicatorButtonData) as PushButton;

            sheetDuplicatorButton.ToolTip = "Select a sheet and duplicate it multiple times." + "\n"
                                            + "Default duplicate option is 'with Detailing'. For dependent views, you can choose 'Duplicate as a Dependent'." + "\n"
                                            + "Legend Views and Schedules are not duplicated, just placed again in the sheet.";

            BitmapImage sheetDuplicatorLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/SheetDuplicator_32.ico"));
            sheetDuplicatorButton.LargeImage = sheetDuplicatorLargeImage;
            #endregion

            // PANEL PRINT & EXPORT
            #region Create Print Set
            PushButtonData printSetButtonData = new PushButtonData(
                "cmdPrintSet",
                "Create" + "\n" + "Print Set",
                Path.Combine(AssemblyPath, "CreatePrintSet.dll"),
                "Entry.CmdMain");

            PushButton printSetButton = printPanel.AddItem(printSetButtonData) as PushButton;

            printSetButton.ToolTip = "Creates a Sheet Set from selected sheets." + "\n"
                                     + "Once created, it will appear in the Print menu > Print Range > Selected views/sheets.";

            BitmapImage printSetLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/CreatePrintSet_32.ico"));
            printSetButton.LargeImage = printSetLargeImage;
            #endregion

            #region Schedule to Excel
            PushButtonData scheduleToExcelData = new PushButtonData(
                "cmdScheduleToExcel",
                "Schedule" + "\n" + "to Excel",
                Path.Combine(AssemblyPath, "ScheduleToExcel.dll"),
                "Entry.CmdMain");

            PushButton scheduleToExcelButton = printPanel.AddItem(scheduleToExcelData) as PushButton;

            scheduleToExcelButton.ToolTip = "Select schedules in the Project Browser and then click this button. They will open in Excel." + "\n"
                                            + "It can also open your active view in Excel (if this is a schedule).";

            BitmapImage scheduleToExcelLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/ScheduleToExcel_32.ico"));
            scheduleToExcelButton.LargeImage = scheduleToExcelLargeImage;
            #endregion

            // uncomment the if block below if you want to restrict button load to specific users
            //load the following buttons ONLY for entitled users
            //if (Data.Helpers.IsExtendedToolsEntitled())
            //{
            // PANEL MODEL MANAGEMENT
            #region Delete Unused Filters Button
            // create data needed for the button
            PushButtonData deleteFiltersButtonData = new PushButtonData(
                "cmdDeleteFilters",                                        // unique name/id for the new button
                "Purge" + "\n" + "Filters",                                // text that will be displayed under the button
                Path.Combine(AssemblyPath, "DeleteUnusedFilters.dll"),     // dll location that will run where the button is pushed
                "DeleteUnusedFilters.CmdMain");                            // namespace and method that will be called

            // data is added to the button and then to the panel
            PushButton deleteFiltersButton = modelManagementPanel.AddItem(deleteFiltersButtonData) as PushButton;

            // tooltip message that will be displayed when the users hover over the button
            deleteFiltersButton.ToolTip = "Removed unused view filters from the project.";

            // bitmap image for the button
            BitmapImage deleteFiltersLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/DeleteUnusedFilters_32.ico"));
            deleteFiltersButton.LargeImage = deleteFiltersLargeImage;
            #endregion

            #region Delete Unused Text Note Button
            PushButtonData deleteTextButtonData = new PushButtonData(
                "cmdPurgeText",
                "Purge" + "\n" + "Text",
                Path.Combine(AssemblyPath, "DeleteUnusedTextNoteTypes.dll"),
                "DeleteUnusedTextNoteTypes.CmdMain");

            PushButton deleteTextButton = modelManagementPanel.AddItem(deleteTextButtonData) as PushButton;

            deleteTextButton.ToolTip = "Removes unused Text Note Types from the project.";

            BitmapImage deleteTextLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/DeleteUnusedTextNoteTypesIcon_32.ico"));
            deleteTextButton.LargeImage = deleteTextLargeImage;
            #endregion

            #region Purge Dimension Styles Button
            PushButtonData purgeDimStylesButtonData = new PushButtonData(
                "cmdPurgeDimStyles",
                "Purge" + "\n" + "Dim Styles",
                Path.Combine(AssemblyPath, "PurgeDimStyles.dll"),
                "Entry.CmdMain");

            PushButton purgeDimStylesButton = modelManagementPanel.AddItem(purgeDimStylesButtonData) as PushButton;

            purgeDimStylesButton.ToolTip = "Removes unused Dimension Styles from the project.";

            BitmapImage purgeDimStylesLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/PurgeDimStyles_32.ico"));
            purgeDimStylesButton.LargeImage = purgeDimStylesLargeImage;
            #endregion

            #region Purge Nested Families Button
            PushButtonData purgeNestedFamButtonData = new PushButtonData(
                "cmdPurgeNestedFam",
                "Purge" + "\n" + "Nested Families",
                Path.Combine(AssemblyPath, "PurgeNestedFamilies.dll"),
                "Entry.CmdMain");

            PushButton purgeNestedFamButton = modelManagementPanel.AddItem(purgeNestedFamButtonData) as PushButton;

            purgeNestedFamButton.ToolTip = "Purge families nested into your project loadable families." + "\n"
                                           + "It purges up to one level of nesting, and only model categories (not annotation categories).";

            BitmapImage purgeNestedFamLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/PurgeNestedFamilies_32.ico"));
            purgeNestedFamButton.LargeImage = purgeNestedFamLargeImage;
            #endregion

            #region Parameter Mapper Button
            PushButtonData paramMapperButtonData = new PushButtonData(
                "cmdParamMapper",
                "Parameter" + "\n" + "Mapper",
                Path.Combine(AssemblyPath, "ParameterMapper.dll"),
                "Entry.CmdMain");

            PushButton paramMapperButton = modelManagementPanel.AddItem(paramMapperButtonData) as PushButton;

            paramMapperButton.ToolTip = "Copy values from one parameter to another by selecting Category and Source Parameter." + "\n"
                                        + "Grouped elements are excluded from edition.";

            BitmapImage paramMapperLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/ParameterMapper_32.ico"));
            paramMapperButton.LargeImage = paramMapperLargeImage;
            #endregion

            #region Parameter Loader Button
            PushButtonData ParameterLoaderButtonData = new PushButtonData(
                "cmdParameterLoader",
                "Parameter" + "\n" + "Loader",
                Path.Combine(AssemblyPath, "ParameterLoader.dll"),
                "Entry.CmdMain");

            PushButton ParameterLoaderButton = modelManagementPanel.AddItem(ParameterLoaderButtonData) as PushButton;

            ParameterLoaderButton.ToolTip = "Load Shared Parameters in batch." + "\n"
                                            + "It can be used in both Project and Family environment.";

            BitmapImage ParameterLoaderLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/ParameterLoader_32.ico"));
            ParameterLoaderButton.LargeImage = ParameterLoaderLargeImage;
            #endregion

            #region Transfer Worksets Button
            PushButtonData transferWorksetsButtonData = new PushButtonData(
                "cmdTransferWorksets",
                "Transfer" + "\n" + "Worksets",
                Path.Combine(AssemblyPath, "TransferWorksets.dll"),
                "Entry.CmdMain");

            PushButton transferWorksetsButton = modelManagementPanel.AddItem(transferWorksetsButtonData) as PushButton;

            transferWorksetsButton.ToolTip = "Transfer selected worksets from another project. Only the workset is transferred, not the geometry inside." + "\n"
                                             + "The source project must be open in the same Revit session.";

            BitmapImage transferWorksetsLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/TransferWorksets_32.ico"));
            transferWorksetsButton.LargeImage = transferWorksetsLargeImage;
            #endregion

            #region Transfer View Template
            PushButtonData transTemplateButtonData = new PushButtonData(
                "cmdTransferTemplate",
                "Transfer" + "\n" + "View Templates",
                Path.Combine(AssemblyPath, "TransferViewTemplate.dll"),
                "Entry.CmdMain");

            PushButton transTemplateButton = modelManagementPanel.AddItem(transTemplateButtonData) as PushButton;

            transTemplateButton.ToolTip = "Transfer selected View Templates from another project." + "\n"
                                          + "The source porject must be either opened in the same Revit session" +
                                          " or linked (and loaded) in the current project.";

            BitmapImage transferTemplateLargeImage = new BitmapImage(new Uri("pack://application:,,,/ArpRibbon;component/Icons/TransferViewTemplates_32.ico"));
            transTemplateButton.LargeImage = transferTemplateLargeImage;
            #endregion
            //}
            #endregion

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            ICollection <ElementId> viewIdCollection = new List <ElementId>();

            #region
            void SetCollectionToRemove()
            {
                try
                {
                    #region
                    // To add all views to collection
                    FilteredElementCollector viewCollector = new FilteredElementCollector(doc);
                    viewCollector.OfClass(typeof(Autodesk.Revit.DB.View));

                    string activeViewName = uidoc.ActiveView.Name;

                    foreach (Autodesk.Revit.DB.View v in viewCollector)
                    {
                        if (v.ViewType.ToString() != "ProjectBrowser" && v.ViewType.ToString() != "SystemBrowser" && v.Name != activeViewName)
                        {
                            viewIdCollection.Add(v.Id);
                        }
                    }
                    #endregion

                    #region
                    // To add all project parameters to collection
                    BindingMap bindingMap = doc.ParameterBindings;

                    FilteredElementCollector parameterElementCollector = new FilteredElementCollector(doc);
                    parameterElementCollector.OfClass(typeof(ParameterElement));

                    foreach (ParameterElement parameterElement in parameterElementCollector)
                    {
                        if (bindingMap.Contains(parameterElement.GetDefinition()))
                        {
                            viewIdCollection.Add(parameterElement.Id);
                        }
                    }
                    #endregion

                    PurgeUnused();
                    TaskDialog.Show("Revit Handy Tools - Model Transmit", "The project will be prepared for model transmit");
                }
                catch (Exception e)
                {
                    TaskDialog.Show("Error", e.ToString());
                }
            }

            #endregion

            void PurgeUnused()
            {
                // To purge a project
                RevitCommandId commandId = RevitCommandId.LookupCommandId("ID_PURGE_UNUSED");

                uiapp.PostCommand(commandId);
            }

            CustomForms.WarningForm warningTransmit = new CustomForms.WarningForm();
            warningTransmit.WarningLabel = String.Format("{0}{1}", "This will remove critical settings of the project.\n",
                                                         "Please make sure you run this extension in a coordiantion model.");
            warningTransmit.ShowDialog();

            if (warningTransmit.DialogResult == DialogResult.Yes)
            {
                SetCollectionToRemove();
            }
            else
            {
                return(Result.Succeeded);
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Cleaning up a project for model transmit");

                doc.Delete(viewIdCollection);

                tx.Commit();
            }

            return(Result.Succeeded);
        }
Beispiel #21
0
        /// <summary>
        /// Ovveride method for when user synchs to central.
        /// The goal here is to disable the DTM Tool and prevent pop-ups while synching.
        /// </summary>
        public static void OnSynchToCentral(object sender, ExecutedEventArgs args, SynchType synchType)
        {
            // (Konrad) This will disable the DTM Tool when we are synching to central.
            AppCommand.IsSynching = true;

            RevitCommandId commandId;

            switch (synchType)
            {
            case SynchType.Synch:
                commandId = RevitCommandId.LookupCommandId("ID_FILE_SAVE_TO_MASTER");
                break;

            case SynchType.SynchNow:
                commandId = RevitCommandId.LookupCommandId("ID_FILE_SAVE_TO_MASTER_SHORTCUT");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(synchType), synchType, null);
            }
            if (commandId == null || !commandId.CanHaveBinding)
            {
                return;
            }

            AppCommand.EnqueueTask(app =>
            {
                try
                {
                    app.RemoveAddInCommandBinding(commandId);

                    switch (synchType)
                    {
                    case SynchType.Synch:
                        AppCommand.IsSynchOverriden = false;
                        break;

                    case SynchType.SynchNow:
                        AppCommand.IsSynchNowOverriden = false;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(synchType), synchType, null);
                    }
                }
                catch (Exception e)
                {
                    Log.AppendLog(LogMessageType.EXCEPTION, e.Message);
                }
            });

            AppCommand.EnqueueTask(app =>
            {
                // (Konrad) We can now post the same Command we were overriding since the override is OFF.
                app.PostCommand(commandId);

                // (Konrad) Once the command executes this will turn the override back ON.
                AppCommand.IsSynching = false;

                var doc         = app.ActiveUIDocument.Document;
                var centralPath = FileInfoUtil.GetCentralFilePath(doc);
                if (string.IsNullOrEmpty(centralPath))
                {
                    return;
                }

                // (Konrad) Let's turn the synch command override back on.
                var config = MissionControlSetup.Configurations[centralPath];
                foreach (var updater in config.Updaters)
                {
                    if (!updater.IsUpdaterOn)
                    {
                        continue;
                    }

                    if (string.Equals(updater.UpdaterId.ToLower(),
                                      AppCommand.Instance.DtmUpdaterInstance.UpdaterGuid.ToString().ToLower(), StringComparison.Ordinal))
                    {
                        CreateSynchToCentralOverride();
                    }
                }
            });
        }
Beispiel #22
0
        public void Post()
        {
            RevitCommandId id = RevitCommandId.LookupCommandId("8f6f8548-6e06-45e7-9525-836047939811");

            m_uiApplication.PostCommand(id);
        }
Beispiel #23
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp      = commandData.Application;
            UIDocument    uidoc      = uiapp.ActiveUIDocument;
            Application   app        = uiapp.Application;
            Document      doc        = uidoc.Document;
            View          activeView = doc.ActiveView;

            ICollection <ElementId> selectedSheetsId = uidoc.Selection.GetElementIds();

            string  viewSetName = app.Username + " Temp";
            ViewSet myViewSet   = new ViewSet();

            FilteredElementIterator elemItr = new FilteredElementCollector(doc).OfClass(typeof(ViewSheetSet)).GetElementIterator();

            elemItr.Reset();

            Element existingViewSet = null;

            while (elemItr.MoveNext())
            {
                if (elemItr.Current.Name == viewSetName)
                {
                    existingViewSet = elemItr.Current;
                }
            }

            IEnumerable <ViewSheet> sheetItr = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).ToElements().Cast <ViewSheet>();

            foreach (ViewSheet e in sheetItr)
            {
                if (selectedSheetsId.Contains(e.Id))
                {
                    myViewSet.Insert(e);
                }
            }


            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create View Set");

                //If exists, delete existing viewset
                try
                {
                    doc.Delete(existingViewSet.Id);
                }
                catch
                {
                    //if the view set does not exists, don't crash
                }

                //Create the new viewset
                PrintManager printMan = doc.PrintManager;
                printMan.PrintRange = PrintRange.Select;
                ViewSheetSetting viewSetting = printMan.ViewSheetSetting;
                viewSetting.CurrentViewSheetSet.Views = myViewSet;
                viewSetting.SaveAs(viewSetName);

                t.Commit();
            }

            //RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.SheetIssuesOrRevisions);

            //Jrn.RibbonEvent "Execute external command:CustomCtrl_%CustomCtrl_%CADtools%Publish%Batch" & vbCr & "Publish:Arup.CADtools.Revit.Commands.RevitPublishCmd"
            //vbCr = "\r"
            string name = "CustomCtrl_%CustomCtrl_%CADtools%Publish%Batch\rPublish";

            RevitCommandId id = RevitCommandId.LookupCommandId(name);

            uidoc.Application.PostCommand(id);


            return(Result.Succeeded);
        }