Beispiel #1
0
        private void UserInterfaceEvents_OnResetRibbonInterface(NameValueMap context)
        {
            //TODO: Fix this
            try
            {
                //get the ribbon associated with part document
                Inventor.Ribbons ribbons        = userInterfaceManager.Ribbons;
                Inventor.Ribbon  assemblyRibbon = ribbons["Assembly"];

                //get the tabls associated with part ribbon
                RibbonTabs ribbonTabs        = assemblyRibbon.RibbonTabs;
                RibbonTab  assemblyRibbonTab = ribbonTabs["id_Assembly"];

                //create a new panel with the tab
                RibbonPanels ribbonPanels = assemblyRibbonTab.RibbonPanels;
                assemblyRibbonPanel = ribbonPanels.Add(ribbonPanelDisplayName,
                                                       ribbonPanelInternalName,
                                                       "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}",
                                                       "",
                                                       false);

                CommandControls assemblyRibbonPanelCtrls = assemblyRibbonPanel.CommandControls;
                CommandControl  copyUtilCmdBtnCmdCtrl    = assemblyRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false);
            }

            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Beispiel #2
0
 public static RibbonPanel GetOrCreate(this RibbonPanels panels, string PanelDisplayName, string PanelInternalName, string ClientId)
 {
     if (panels[PanelInternalName] != null)
     {
         return(panels[PanelInternalName]);
     }
     else
     {
         return(panels.Add(PanelDisplayName, PanelInternalName, ClientId));
     }
 }
Beispiel #3
0
        /// <summary>
        /// This method gets called to add a new panel to the ribbon to be the container for
        /// the rectangle buttons
        /// </summary>
        private void CreateRectangleRibbonPanel()
        {
            //create a reference to the ribbon
            Ribbon partRibbon     = StandardAddInServer.InventorApplication.UserInterfaceManager.Ribbons["Part"];
            Ribbon drawingRibbon  = StandardAddInServer.InventorApplication.UserInterfaceManager.Ribbons["Drawing"];
            Ribbon assemblyRibbon = StandardAddInServer.InventorApplication.UserInterfaceManager.Ribbons["Assembly"];

            //create a reference to the tab you want to add a control to
            RibbonTab partSketchTab     = partRibbon.RibbonTabs["id_TabSketch"];
            RibbonTab drawingSketchTab  = drawingRibbon.RibbonTabs["id_TabSketch"];
            RibbonTab assemblySketchTab = assemblyRibbon.RibbonTabs["id_TabSketch"];

            //reference the panels collection in a variable so that you can call the add method in a clean fashion
            RibbonPanels partSketchTabPanels     = partSketchTab.RibbonPanels;
            RibbonPanels drawingSketchTabPanels  = drawingSketchTab.RibbonPanels;
            RibbonPanels assemblySketchTabPanels = assemblySketchTab.RibbonPanels;

            //Add your panel to the panels collection
            partRectControlsPanel = partSketchTabPanels.Add("Rectangles", RectangleControlsPanelInternalName,
                                                            StandardAddInServer.AddInServerId, "id_PanelP_2DSketchConstrain", true);
            drawingRectControlsPanel = drawingSketchTabPanels.Add("Rectangles", RectangleControlsPanelInternalName,
                                                                  StandardAddInServer.AddInServerId, "id_PanelD_2DSketchConstrain", true);
            assemblyRectControlPanel = assemblySketchTabPanels.Add("Rectangles", RectangleControlsPanelInternalName,
                                                                   StandardAddInServer.AddInServerId, "id_PanelA_2DSketchConstrain", true);

            //Create an Inventor Object collection that will hold the buttons for the split control that gets added to
            //the rectangles panel.  To add a split button control you have to pass in a collection.
            ObjectCollection objectCollection = StandardAddInServer.InventorApplication.TransientObjects.CreateObjectCollection();

            //Add the rectangle buttons to the collection
            objectCollection.Add(centerPointRectangleBtn.ButtonDefinition);
            objectCollection.Add(diagonalCenterPointRectangleButton.ButtonDefinition);
            objectCollection.Add(hzMidPointRectangleBtn.ButtonDefinition);
            objectCollection.Add(vertMidPointRectangleBtn.ButtonDefinition);

            //Add the split button control to the rectangles panel
            partRectangleSplitButton =
                partRectControlsPanel.CommandControls.AddSplitButton
                    (DisplayedControl: DefaultDisplayControl,
                    ButtonDefinitions: objectCollection, UseLargeIcon: true);
            drawingRectangleSplitButton =
                drawingRectControlsPanel.CommandControls.AddSplitButton
                    (DisplayedControl: DefaultDisplayControl,
                    ButtonDefinitions: objectCollection, UseLargeIcon: true);
            assemblyRectangleSplitButton =
                assemblyRectControlPanel.CommandControls.AddSplitButton
                    (DisplayedControl: DefaultDisplayControl,
                    ButtonDefinitions: objectCollection, UseLargeIcon: true);
        }
        /// <summary>
        /// This method gets called to add a new panel to the ribbon to be the container for
        /// the rectangle buttons
        /// </summary>
        public void CreateRibbonUserInterface()
        {
            //create a reference to the ribbon
            Ribbon partRibbon     = StandardAddInServer.InventorApplication.UserInterfaceManager.Ribbons["Part"];
            Ribbon drawingRibbon  = StandardAddInServer.InventorApplication.UserInterfaceManager.Ribbons["Drawing"];
            Ribbon assemblyRibbon = StandardAddInServer.InventorApplication.UserInterfaceManager.Ribbons["Assembly"];

            //create a reference to the tab you want to add a control to
            RibbonTab partSketchTab     = partRibbon.RibbonTabs["id_TabSketch"];
            RibbonTab drawingSketchTab  = drawingRibbon.RibbonTabs["id_TabSketch"];
            RibbonTab assemblySketchTab = assemblyRibbon.RibbonTabs["id_TabSketch"];

            //reference the panels collection in a variable so that you can call the add method in a clean fashion
            RibbonPanels partSketchTabPanels     = partSketchTab.RibbonPanels;
            RibbonPanels drawingSketchTabPanels  = drawingSketchTab.RibbonPanels;
            RibbonPanels assemblySketchTabPanels = assemblySketchTab.RibbonPanels;

            //Add your panel to the panels collection
            RibbonPanel partRectControlsPanel = partSketchTabPanels.Add("Rectangles",
                                                                        RectangleControlsPanelInternalName, StandardAddInServer.AddInServerId,
                                                                        "id_PanelP_2DSketchConstrain", true);
            RibbonPanel drawingRectControlsPanel = drawingSketchTabPanels.Add("Rectangles",
                                                                              RectangleControlsPanelInternalName, StandardAddInServer.AddInServerId,
                                                                              "id_PanelD_2DSketchConstrain", true);
            RibbonPanel assemblyRectControlPanel = assemblySketchTabPanels.Add("Rectangles",
                                                                               RectangleControlsPanelInternalName, StandardAddInServer.AddInServerId,
                                                                               "id_PanelA_2DSketchConstrain", true);

            //Add the Center Point Rectangle Button to the ribbon panels
            CommandControl partCentPtRecBtn = partRectControlsPanel.CommandControls.AddButton
                                                  (ButtonDefinition: this.centerPointRectangleBtn.ButtonDefinition,
                                                  UseLargeIcon: true);
            CommandControl dwgCentPtRecBtn = drawingRectControlsPanel.CommandControls.AddButton
                                                 (ButtonDefinition: this.centerPointRectangleBtn.ButtonDefinition,
                                                 UseLargeIcon: true);
            CommandControl assyCentPtRecBtn = assemblyRectControlPanel.CommandControls.AddButton
                                                  (ButtonDefinition: this.centerPointRectangleBtn.ButtonDefinition,
                                                  UseLargeIcon: true);

            //Add the Diagonal Center Point Rectangle Button to the ribbon panels
            CommandControl parttDiagCentPtRecBtn = partRectControlsPanel.CommandControls.AddButton
                                                       (ButtonDefinition: this.diagonalCenterPointRectangleButton.ButtonDefinition,
                                                       UseLargeIcon: true);
            CommandControl dwgDiagCentPtRecBtn = drawingRectControlsPanel.CommandControls.AddButton
                                                     (ButtonDefinition: this.diagonalCenterPointRectangleButton.ButtonDefinition,
                                                     UseLargeIcon: true);
            CommandControl assyDiagCentPtRecBtn = assemblyRectControlPanel.CommandControls.AddButton
                                                      (ButtonDefinition: this.diagonalCenterPointRectangleButton.ButtonDefinition,
                                                      UseLargeIcon: true);

            //Add Horizontal Mid-Point Rectangle Button to the ribbon panels
            CommandControl ptHzMPtRectBtn = partRectControlsPanel.CommandControls.AddButton
                                                (ButtonDefinition: this.hzMidPointRectangleBtn.ButtonDefinition,
                                                UseLargeIcon: true);
            CommandControl dwgHzMPtRectBtn = drawingRectControlsPanel.CommandControls.AddButton
                                                 (ButtonDefinition: this.hzMidPointRectangleBtn.ButtonDefinition,
                                                 UseLargeIcon: true);
            CommandControl assyHzMPtRectBtn = assemblyRectControlPanel.CommandControls.AddButton
                                                  (ButtonDefinition: this.hzMidPointRectangleBtn.ButtonDefinition,
                                                  UseLargeIcon: true);

            //Add Vertical Mid-Point Rectangle Button to the ribbon panels
            CommandControl ptVertMPtRectBtn = partRectControlsPanel.CommandControls.AddButton
                                                  (ButtonDefinition: this.vertMidPointRectangleBtn.ButtonDefinition,
                                                  UseLargeIcon: true);
            CommandControl dwgVertMPtRectBtn = drawingRectControlsPanel.CommandControls.AddButton
                                                   (ButtonDefinition: this.vertMidPointRectangleBtn.ButtonDefinition,
                                                   UseLargeIcon: true);
            CommandControl assyVertMPtRectBtn = assemblyRectControlPanel.CommandControls.AddButton
                                                    (ButtonDefinition: this.vertMidPointRectangleBtn.ButtonDefinition,
                                                    UseLargeIcon: true);
        }
Beispiel #5
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            try
            {
                SetupDynamoPaths();
                inventorApplication = addInSiteObject.Application;
                PersistenceManager.InventorApplication = inventorApplication;
                userInterfaceManager = inventorApplication.UserInterfaceManager;

                //initialize event delegates
                userInterfaceEvents = inventorApplication.UserInterfaceManager.UserInterfaceEvents;

                UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars);
                userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;

                UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments);
                userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;

                UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface);
                userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate;

                appEvents = inventorApplication.ApplicationEvents;
                appEvents.OnActivateDocument   += appEvents_OnActivateDocument;
                appEvents.OnDeactivateDocument += appEvents_OnDeactivateDocument;

                Icon dynamoIcon = Resources.logo_square_32x32;

                //retrieve the GUID for this class
                GuidAttribute addInCLSID;
                addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(this.GetType(), typeof(GuidAttribute));
                string addInCLSIDString;
                addInCLSIDString = "{" + addInCLSID.Value + "}";

                dynamoAddinButton = new DynamoInventorAddinButton(
                    buttonDisplayName, buttonInternalName, CommandTypesEnum.kShapeEditCmdType,
                    addInCLSIDString, "Initialize Dynamo.",
                    "Dynamo is a visual programming environment for Inventor.", dynamoIcon, dynamoIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);

                CommandCategory assemblyUtilitiesCategory = inventorApplication.CommandManager.CommandCategories.Add(commandCategoryDisplayName, commandCategoryInternalName, addInCLSID);
                assemblyUtilitiesCategory.Add(dynamoAddinButton.ButtonDefinition);

                if (firstTime == true)
                {
                    InterfaceStyleEnum interfaceStyle;
                    interfaceStyle = userInterfaceManager.InterfaceStyle;

                    if (interfaceStyle == InterfaceStyleEnum.kClassicInterface)
                    {
                        CommandBar assemblyUtilityCommandBar;

                        assemblyUtilityCommandBar = userInterfaceManager.CommandBars.Add(commandBarDisplayName,
                                                                                         commandBarInternalName,
                                                                                         CommandBarTypeEnum.kRegularCommandBar,
                                                                                         addInCLSID);
                    }

                    else
                    {
                        Inventor.Ribbons ribbons           = userInterfaceManager.Ribbons;
                        Inventor.Ribbon  assemblyRibbon    = ribbons["Assembly"];
                        RibbonTabs       ribbonTabs        = assemblyRibbon.RibbonTabs;
                        RibbonTab        assemblyRibbonTab = ribbonTabs["id_AddInsTab"];
                        RibbonPanels     ribbonPanels      = assemblyRibbonTab.RibbonPanels;
                        assemblyRibbonPanel = ribbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);
                        CommandControls assemblyRibbonPanelCtrls = assemblyRibbonPanel.CommandControls;
                        CommandControl  assemblyCmdBtnCmdCtrl    = assemblyRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false);

                        Inventor.Ribbon partRibbon       = ribbons["Part"];
                        RibbonTabs      partRibbonTabs   = partRibbon.RibbonTabs;
                        RibbonTab       modelRibbonTab   = partRibbonTabs["id_AddInsTab"];
                        RibbonPanels    partRibbonPanels = modelRibbonTab.RibbonPanels;
                        partRibbonPanel = partRibbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);
                        CommandControls partRibbonPanelCtrls = partRibbonPanel.CommandControls;
                        CommandControl  partCmdBtnCmdCtrl    = partRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false);

                        Inventor.Ribbon drawingRibbon       = ribbons["Drawing"];
                        RibbonTabs      drawingRibbonTabs   = drawingRibbon.RibbonTabs;
                        RibbonTab       drawingRibbonTab    = drawingRibbonTabs["id_AddInsTab"];
                        RibbonPanels    drawingRibbonPanels = drawingRibbonTab.RibbonPanels;
                        drawingRibbonPanel = drawingRibbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);
                        CommandControls drawingRibbonPanelCtrls = drawingRibbonPanel.CommandControls;
                        CommandControl  drawingCmdBtnCmdCtrl    = drawingRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false);
                    }
                }
            }

            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }