Message 1 of 6
Poblem with add-in, commandbar doesn´t load on inventor?

Not applicable
01-28-2010
01:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi everyone!
i'm following the Brian Ekins great tutorials about add-in creation.
in the begining the add-in loaded.
but when i try to add a button to the commandbar,something it's not working and i dont know what.can someone check the code for me?
the code i'm using is the following in StandardAddInServer.vb:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Namespace Gestorproperties
_
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inventorApplication As Inventor.Application
#Region "ApplicationAddInServer Members"
Private m_clientid As String
Private WithEvents m_buttondef As ButtonDefinition
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
m_clientid = AddInGuid(GetType(StandardAddInServer))
Dim controldefs As ControlDefinitions
controldefs = m_inventorApplication.CommandManager.ControlDefinitions
m_buttondef = controldefs.AddButtonDefinition("teste", "AddInteste", CommandTypesEnum.kQueryOnlyCmdType, m_clientid, "teste2", "teste3")
If firstTime Then
Dim commandbars As CommandBars
commandbars = m_inventorApplication.UserInterfaceManager.CommandBars
Dim commandbar As CommandBar
commandbar = commandbars.Add("add-in teste", "addinteste", , m_clientid)
commandbar.Visible = True
commandbar.Controls.AddButton(m_buttondef)
End If
' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.
End Sub
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.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.
Marshal.ReleaseComObject(m_inventorApplication)
m_inventorApplication = Nothing
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
' This property is provided to allow the AddIn to expose an API
' of its own to other programs. Typically, this would be done by
' implementing the AddIn's API interface in a class and returning
' that class object through this property.
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
End Sub
#End Region
#Region "COM Registration"
' Registers this class as an AddIn for Inventor.
' This function is called when the assembly is registered for COM.
_
Public Shared Sub Register(ByVal t As Type)
Dim clssRoot As RegistryKey = Registry.ClassesRoot
Dim clsid As RegistryKey = Nothing
Dim subKey As RegistryKey = Nothing
Try
clsid = clssRoot.CreateSubKey("CLSID\" + AddInGuid(t))
clsid.SetValue(Nothing, "Gestorproperties")
subKey = clsid.CreateSubKey("Implemented Categories{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}")
subKey.Close()
subKey = clsid.CreateSubKey("Settings")
subKey.SetValue("AddInType", "Standard")
subKey.SetValue("LoadOnStartUp", "1")
'subKey.SetValue("SupportedSoftwareVersionLessThan", "")
subKey.SetValue("SupportedSoftwareVersionGreaterThan", "12..")
'subKey.SetValue("SupportedSoftwareVersionEqualTo", "")
'subKey.SetValue("SupportedSoftwareVersionNotEqualTo", "")
'subKey.SetValue("Hidden", "0")
'subKey.SetValue("UserUnloadable", "1")
subKey.SetValue("Version", 0)
subKey.Close()
subKey = clsid.CreateSubKey("Description")
subKey.SetValue(Nothing, "Gestor de funções e propriedades")
Catch ex As Exception
System.Diagnostics.Trace.Assert(False)
Finally
If Not subKey Is Nothing Then subKey.Close()
If Not clsid Is Nothing Then clsid.Close()
If Not clssRoot Is Nothing Then clssRoot.Close()
End Try
End Sub
' Unregisters this class as an AddIn for Inventor.
' This function is called when the assembly is unregistered.
_
Public Shared Sub Unregister(ByVal t As Type)
Dim clssRoot As RegistryKey = Registry.ClassesRoot
Dim clsid As RegistryKey = Nothing
Try
clssRoot = Microsoft.Win32.Registry.ClassesRoot
clsid = clssRoot.OpenSubKey("CLSID\" + AddInGuid(t), True)
clsid.SetValue(Nothing, "")
clsid.DeleteSubKeyTree("Implemented Categories{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}")
clsid.DeleteSubKeyTree("Settings")
clsid.DeleteSubKeyTree("Description")
Catch
Finally
If Not clsid Is Nothing Then clsid.Close()
If Not clssRoot Is Nothing Then clssRoot.Close()
End Try
End Sub
' This property uses reflection to get the value for the GuidAttribute attached to the class.
Public Shared ReadOnly Property AddInGuid(ByVal t As Type) As String
Get
Dim guid As String = ""
Try
Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
guid = "{" + guidAttribute.Value.ToString() + "}"
Finally
AddInGuid = guid
End Try
End Get
End Property
#End Region
End Class
End Namespace
i'm following the Brian Ekins great tutorials about add-in creation.
in the begining the add-in loaded.
but when i try to add a button to the commandbar,something it's not working and i dont know what.can someone check the code for me?
the code i'm using is the following in StandardAddInServer.vb:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Namespace Gestorproperties
_
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inventorApplication As Inventor.Application
#Region "ApplicationAddInServer Members"
Private m_clientid As String
Private WithEvents m_buttondef As ButtonDefinition
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
m_clientid = AddInGuid(GetType(StandardAddInServer))
Dim controldefs As ControlDefinitions
controldefs = m_inventorApplication.CommandManager.ControlDefinitions
m_buttondef = controldefs.AddButtonDefinition("teste", "AddInteste", CommandTypesEnum.kQueryOnlyCmdType, m_clientid, "teste2", "teste3")
If firstTime Then
Dim commandbars As CommandBars
commandbars = m_inventorApplication.UserInterfaceManager.CommandBars
Dim commandbar As CommandBar
commandbar = commandbars.Add("add-in teste", "addinteste", , m_clientid)
commandbar.Visible = True
commandbar.Controls.AddButton(m_buttondef)
End If
' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.
End Sub
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.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.
Marshal.ReleaseComObject(m_inventorApplication)
m_inventorApplication = Nothing
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
' This property is provided to allow the AddIn to expose an API
' of its own to other programs. Typically, this would be done by
' implementing the AddIn's API interface in a class and returning
' that class object through this property.
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
End Sub
#End Region
#Region "COM Registration"
' Registers this class as an AddIn for Inventor.
' This function is called when the assembly is registered for COM.
_
Public Shared Sub Register(ByVal t As Type)
Dim clssRoot As RegistryKey = Registry.ClassesRoot
Dim clsid As RegistryKey = Nothing
Dim subKey As RegistryKey = Nothing
Try
clsid = clssRoot.CreateSubKey("CLSID\" + AddInGuid(t))
clsid.SetValue(Nothing, "Gestorproperties")
subKey = clsid.CreateSubKey("Implemented Categories{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}")
subKey.Close()
subKey = clsid.CreateSubKey("Settings")
subKey.SetValue("AddInType", "Standard")
subKey.SetValue("LoadOnStartUp", "1")
'subKey.SetValue("SupportedSoftwareVersionLessThan", "")
subKey.SetValue("SupportedSoftwareVersionGreaterThan", "12..")
'subKey.SetValue("SupportedSoftwareVersionEqualTo", "")
'subKey.SetValue("SupportedSoftwareVersionNotEqualTo", "")
'subKey.SetValue("Hidden", "0")
'subKey.SetValue("UserUnloadable", "1")
subKey.SetValue("Version", 0)
subKey.Close()
subKey = clsid.CreateSubKey("Description")
subKey.SetValue(Nothing, "Gestor de funções e propriedades")
Catch ex As Exception
System.Diagnostics.Trace.Assert(False)
Finally
If Not subKey Is Nothing Then subKey.Close()
If Not clsid Is Nothing Then clsid.Close()
If Not clssRoot Is Nothing Then clssRoot.Close()
End Try
End Sub
' Unregisters this class as an AddIn for Inventor.
' This function is called when the assembly is unregistered.
_
Public Shared Sub Unregister(ByVal t As Type)
Dim clssRoot As RegistryKey = Registry.ClassesRoot
Dim clsid As RegistryKey = Nothing
Try
clssRoot = Microsoft.Win32.Registry.ClassesRoot
clsid = clssRoot.OpenSubKey("CLSID\" + AddInGuid(t), True)
clsid.SetValue(Nothing, "")
clsid.DeleteSubKeyTree("Implemented Categories{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}")
clsid.DeleteSubKeyTree("Settings")
clsid.DeleteSubKeyTree("Description")
Catch
Finally
If Not clsid Is Nothing Then clsid.Close()
If Not clssRoot Is Nothing Then clssRoot.Close()
End Try
End Sub
' This property uses reflection to get the value for the GuidAttribute attached to the class.
Public Shared ReadOnly Property AddInGuid(ByVal t As Type) As String
Get
Dim guid As String = ""
Try
Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
guid = "{" + guidAttribute.Value.ToString() + "}"
Finally
AddInGuid = guid
End Try
End Get
End Property
#End Region
End Class
End Namespace