Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Addin load/unload behavior

3 REPLIES 3
Reply
Message 1 of 4
achmidt
803 Views, 3 Replies

Addin load/unload behavior

Hello everyone!

 

I`m writting an addin for inventor 2014 and I`m not sure how to make addin to disapear from the ribbon when user unchecks the unload checkbox in addin manager? and vice versa to apper when user check the box?

 

Any help is appreciated.

 

Thank you,

Alex

 

 

 

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
3 REPLIES 3
Message 2 of 4
adam.nagy
in reply to: achmidt

Hi Alex,

 

In the Activate method you add your Ribbon tabs/panels/buttons, in the Deactivate method you need to remove them:
http://adndevblog.typepad.com/manufacturing/2013/10/unload-net-addin-without-closing-inventor.html

 

Have a look at the SimpleAddIn sample project: C:\Users\Public\Documents\Autodesk\Inventor 2014\SDK\DeveloperTools\Samples\VB.NET\AddIns\SimpleAddIn

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 4
achmidt
in reply to: achmidt

Adam, 

thank you for your respond. I figured out how to unload the addin. I think I missed something and it doesn`t want to load back when I checking the box loaded/unloaded.

 

Below is the part of the code. Can you please look at it and point me into the right direction?

 

 

Public Module Globals
    Public m_inventorApplication As Inventor.Application
End Module

 

 

 Public Class StandardAddInServer
        Implements Inventor.ApplicationAddInServer

        ' Inventor application object.
        Private _buttonDef As ButtonDefinition
        Private panel As RibbonPanel
     
#Region "ApplicationAddInServer Members"

        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate

            ' 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.

            Dim clientId As String = "68aeeec3-0364-4ae5-a6ff-9e8dc99e0e13"

            Dim smallicon As stdole.IPictureDisp
            Dim largeicon As stdole.IPictureDisp

            'Convert icon
            smallicon = clsPictureConverter.ToIPictureDisp(My.Resources.tag_purple16x16)
            largeicon = clsPictureConverter.ToIPictureDisp(My.Resources.tag_purple_32x32)

            _buttonDef = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition( _
          "Add part", "id_TabVP", CommandTypesEnum.kQueryOnlyCmdType, clientId, "TParts", "TParts", _
           smallicon, largeicon, ButtonDisplayEnum.kDisplayTextInLearningMode)

            AddHandler _buttonDef.OnExecute, AddressOf OnExecute

            Try
                panel = m_inventorApplication.UserInterfaceManager.Ribbons("Assembly").RibbonTabs("id_TabAssemble").RibbonPanels("TParts")
            Catch ex As Exception
                panel = m_inventorApplication.UserInterfaceManager.Ribbons("Assembly").RibbonTabs("id_TabAssemble").RibbonPanels.Add( _
                   "TParts", "id_TabVP", clientId)
            End Try

            panel.CommandControls.AddButton(_buttonDef)

        End Sub

 

 

        ' unloads addin
        Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate

            Try
                'release objects
                If Not panel Is Nothing Then panel.Delete()

                Marshal.ReleaseComObject(m_inventorApplication)
                _buttonDef = Nothing
                m_inventorApplication = Nothing

                System.GC.WaitForPendingFinalizers()
                System.GC.Collect()

            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try

        End Sub

 

 

I also looked at the SimpleAddin - I see there are three Handlers : OnResetCommandBars, OnResetEnviroments and OnResetRibbonInterfaceI assume they don`t do anything with load/unload behavior, and need only if user resets the ribbons manually thru the Ribbon Appearance.


Thank you.
Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen
Message 4 of 4
adam.nagy
in reply to: achmidt

Hi,

 

If your code errors out in the Activate method then your AddIn will not reach the "Loaded" status. I'm quite sure the problematic line is where you try to add _buttonDef because the second time around it already exists.

Two possible solutions:

a) Inside Activate method check for the existence of the "Add part" button definition and if it does just assign it to _buttonDef 

b) Inside Deactivate method delete _buttonDef

 

OnResetCommandBars, OnResetEnviroments and OnResetRibbonInterface are not related to load/unload.

 

Cheers,



Adam Nagy
Autodesk Platform Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report