Esempio n. 1
1
			public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
			{
				
				m_inventorApplication = addInSiteObject.Application;
				
				m_ApplicationEvents = m_inventorApplication.ApplicationEvents;
                m_ApplicationEvents.OnOpenDocument += this.m_ApplicationEvents_OnOpenDocument;
				
				mControlForm = new Form1(m_inventorApplication);
				mControlForm.ShowModeless();
				
			}
Esempio n. 2
0
        /// <summary>
        /// Attaches the wrapper to inventor
        /// </summary>
        public static void Attach()
        {
            try
            {
                // try to attach to a running instance of inventor
                _inventor = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
                _events   = _inventor.ApplicationEvents;
            }
            // if the attachment process failed
            catch (Exception)
            {
                // try to start a new session of inventor
                try
                {
                    Type invAppType = Type.GetTypeFromProgID("Inventor.Application");

                    _inventor         = (Inventor.Application)System.Activator.CreateInstance(invAppType);
                    _events           = _inventor.ApplicationEvents;
                    _inventor.Visible = true;
                }
                catch (Exception exception)
                {
                    throw new Exception("Unable to get or start inventor");
                }
            }
        }
Esempio n. 3
0
            public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
            {
                m_inventorApplication = addInSiteObject.Application;

                m_ApplicationEvents = m_inventorApplication.ApplicationEvents;
                m_ApplicationEvents.OnOpenDocument += this.m_ApplicationEvents_OnOpenDocument;

                mControlForm = new Form1(m_inventorApplication);
                mControlForm.ShowModeless();
            }
Esempio n. 4
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.
            m_appEvents = m_inventorApplication.ApplicationEvents;
            m_appEvents.OnActivateDocument += new ApplicationEventsSink_OnActivateDocumentEventHandler(ApplicationEvents_OnActivateDocument);
        }
Esempio n. 5
0
        public void Deactivate()
        {
            // This method is called by Inventor when the AddIn is unloaded.
            // The AddIn will be unloaded either manually by the user or
            // when the Inventor session is terminated

            // TODO: Add ApplicationAddInServer.Deactivate implementation

            // Release objects.
            m_inventorApplication           = null;
            m_appEvents.OnActivateDocument -= new ApplicationEventsSink_OnActivateDocumentEventHandler(ApplicationEvents_OnActivateDocument);

            m_appEvents = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Esempio n. 6
0
        public MainForm(Inventor.Application app)
        {
            InitializeComponent();

            imageList.Images.Add(kContext, Resources.FolderOpened_16x);
            imageList.Images.Add(kReference, Resources.Key_16x);

            m_app = app;
            m_docsWithContexts = new HashSet <string>();

            ReferenceKeysTreeView.AfterSelect += ReferenceKeysTreeView_AfterSelect;

            m_events = m_app.ApplicationEvents;
            m_events.OnActivateDocument   += M_events_OnActivateDocument;
            m_events.OnDeactivateDocument += M_events_OnDeactivateDocument;

            LoadData();
        }
Esempio n. 7
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());
            }
        }
Esempio n. 8
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());
            }
        }
Esempio n. 9
0
 /// <summary>
 /// If you are developing an add-in use this method to attach the wrapper to inventor
 /// </summary>
 /// <param name="inventor"></param>
 public static void AddinAttach(Inventor.Application inventor)
 {
     _inventor = inventor;
     _events   = _inventor.ApplicationEvents;
 }
Esempio n. 10
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            // Add event handlers
            m_AppEvents = m_inventorApplication.ApplicationEvents;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.


            // Define the buttons on ribbons
            Inventor.UserInterfaceManager UIManager = m_inventorApplication.UserInterfaceManager;

            // Define ControlDefinition (Button on the ribbon panel)
            ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions;

            // SPECIFICATION BUTTON
            // Define Command
            string CommandID = "SpecificationCmd";

            try
            {
                // try to get the existing command definition
                SpecificationCommand = (Inventor.ButtonDefinition)controlDefs[CommandID];
            }

            catch
            {
                // or create it
                IPictureDisp SmallPicture = (Inventor.IPictureDisp)PictureDispConverter.ToIPictureDisp(AutoSpecification.Properties.Resources.SimpleIcon16);
                IPictureDisp LargePicture = (Inventor.IPictureDisp)PictureDispConverter.ToIPictureDisp(AutoSpecification.Properties.Resources.SimpleIcon32);

                SpecificationCommand = controlDefs.AddButtonDefinition(
                    "Создание спецификаций на агрегат", CommandID,
                    CommandTypesEnum.kEditMaskCmdType,
                    Guid.NewGuid().ToString(),
                    "Автоспецификации",
                    "Создание спецификаций на агрегат",
                    SmallPicture,
                    LargePicture, ButtonDisplayEnum.kNoTextWithIcon);
            }
            // register the method that will be executed
            SpecificationCommand.OnExecute += new Inventor.ButtonDefinitionSink_OnExecuteEventHandler(SpecificationCommand_OnExecute);

            // add buttons to ribbon
            if (firstTime)
            {
                UserInterfaceManager userInterfaceManager = m_inventorApplication.UserInterfaceManager;
                if (userInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface)
                {
                    // Assembly ribbon

                    // 1. Access the Assebly ribbon
                    Inventor.Ribbon ribbonPart = userInterfaceManager.Ribbons["Assembly"];

                    // 2. Get Assemble tab
                    Inventor.RibbonTab tabSampleBlog = ribbonPart.RibbonTabs["id_TabAssemble"];

                    // 3. Create panel
                    Inventor.RibbonPanel pnlMyCommands = tabSampleBlog.RibbonPanels.Add("Спецификация", "id_Panel_AssemblyAutoSpecification", Guid.NewGuid().ToString());

                    // 4. Add Button to Panel
                    pnlMyCommands.CommandControls.AddButton(SpecificationCommand, true, false);


                    //// Part Ribbon (SheetMetalTab)

                    //// 1. Access the Part ribbon
                    //ribbonPart = userInterfaceManager.Ribbons["Part"];

                    //// 2. Get Part tab
                    //tabSampleBlog = ribbonPart.RibbonTabs["id_TabSheetMetal"];

                    //// 3. Create panel
                    //pnlMyCommands = tabSampleBlog.RibbonPanels.Add("Макросы", "id_Panel_SheetMetalReplacePart", Guid.NewGuid().ToString());

                    //// 4. Add Button to Panel
                    //pnlMyCommands.CommandControls.AddButton(ReplacePartCommand, true, false);
                    //pnlMyCommands.CommandControls.AddSeparator();
                    //pnlMyCommands.CommandControls.AddButton(ExportDXFCommand, true, false);
                    //pnlMyCommands.CommandControls.AddButton(BendTechnologyCommand, true, false);

                    //// Part Ribbon (ModelTab)

                    //// 2. Get Part tab
                    //tabSampleBlog = ribbonPart.RibbonTabs["id_TabModel"];

                    //// 3. Create panel
                    //pnlMyCommands = tabSampleBlog.RibbonPanels.Add("Макросы", "id_Panel_ModelReplacePart", Guid.NewGuid().ToString());

                    //// 4. Add Button to Panel
                    //pnlMyCommands.CommandControls.AddButton(ReplacePartCommand, true, false);
                    ////pnlMyCommands.CommandControls.AddSeparator();
                    ////pnlMyCommands.CommandControls.AddButton(ExportDXFCommand, true, false);
                    ////pnlMyCommands.CommandControls.AddButton(BendTechnologyCommand, true, false);


                    //// Drawing Ribbon (PlaceViewsTab)
                    //// 1. Access the Part ribbon
                    //ribbonPart = userInterfaceManager.Ribbons["Drawing"];

                    //// 2. Get Part tab
                    //tabSampleBlog = ribbonPart.RibbonTabs["id_TabPlaceViews"];

                    //// 3. Create panel
                    //pnlMyCommands = tabSampleBlog.RibbonPanels.Add("Макросы", "id_Panel_PlaceViewsReplacePart", Guid.NewGuid().ToString());

                    //// 4. Add Button to Panel
                    //pnlMyCommands.CommandControls.AddButton(ExportPDFCommand, true, false);
                    //pnlMyCommands.CommandControls.AddButton(TranslateToENCommand, true, false);
                    //pnlMyCommands.CommandControls.AddSeparator();
                    //pnlMyCommands.CommandControls.AddButton(FramePartsListCommand, true, false);

                    //// Drawing Ribbon (TabAnnotateESKD)

                    //// 2. Get Part tab
                    //tabSampleBlog = ribbonPart.RibbonTabs["id_TabAnnotateESKD"];

                    //// 3. Create panel
                    //pnlMyCommands = tabSampleBlog.RibbonPanels.Add("Макросы", "id_Panel_AnnotateESKDReplacePart", Guid.NewGuid().ToString());

                    //// 4. Add Button to Panel
                    //pnlMyCommands.CommandControls.AddButton(ExportPDFCommand, true, false);
                    //pnlMyCommands.CommandControls.AddButton(TranslateToENCommand, true, false);
                    //pnlMyCommands.CommandControls.AddSeparator();
                    //pnlMyCommands.CommandControls.AddButton(FramePartsListCommand, true, false);
                }
            }
        }
Esempio n. 11
0
 public DocumentManager()
 {
     appEvents = InventorApplication.ApplicationEvents;
     appEvents.OnActivateDocument += appEvents_OnActivateDocument;
     appEvents.OnDeactivateDocument += appEvents_OnDeactivateDocument;
 }
Esempio n. 12
0
 public DocumentManager()
 {
     appEvents = InventorApplication.ApplicationEvents;
     appEvents.OnActivateDocument   += appEvents_OnActivateDocument;
     appEvents.OnDeactivateDocument += appEvents_OnDeactivateDocument;
 }