Poblem with add-in, commandbar doesn´t load on inventor?

Poblem with add-in, commandbar doesn´t load on inventor?

Anonymous
Not applicable
548 Views
5 Replies
Message 1 of 6

Poblem with add-in, commandbar doesn´t load on inventor?

Anonymous
Not applicable
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
0 Likes
549 Views
5 Replies
Replies (5)
Message 2 of 6

Mike.Wohletz
Collaborator
Collaborator
What version of Inventor are you using? I have only taken a quick look at the code but I don't see where you are adding the button to a panel! In Inventor you should have a programing help that will show how to do this, if you are using 2010 you will need to create a ribbon panel or know the name of an existing one to add this to.
0 Likes
Message 3 of 6

Anonymous
Not applicable
I'm using IV 2010. well with this code i'm only creating the toolbar for the add-in, and later on i will be adding the button image,right?
0 Likes
Message 4 of 6

Mike.Wohletz
Collaborator
Collaborator
I hope that this has enough information on it to get you started, please notice that when dealing with the ribbon you will need to know in what type of document you would like to have your menu viable. the code that I have showing will only have a menu in a part document because of this line
{code}

Dim oRibbonP As Ribbon = oUIManager.Ribbons.Item("Part")

{code}

to ge the it to show up in other locations you will need to add the appropriate locations with something like this

{code}

Dim oRibbonZD As Ribbon = oUIManager.Ribbons.Item("ZeroDoc")
Dim oRibbonP As Ribbon = oUIManager.Ribbons.Item("Part")
Dim oRibbonD As Ribbon = oUIManager.Ribbons.Item("Drawing")
Dim oRibbonA As Ribbon = oUIManager.Ribbons.Item("Assembly")
{code}


this is some sample code that you need to review what you have going on in your sub activate.

{code}

#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
' create the pictures for the buttons

Dim clp As stdole.IPictureDisp
clp = Microsoft.VisualBasic.Compatibility.VB6.IconToIPicture(My.Resources.Editor)

' create the picture for the button
Dim controlDefs As ControlDefinitions
controlDefs = m_inventorApplication.CommandManager.ControlDefinitions
' create the button definition

m_CLStartButtonDef = controlDefs.AddButtonDefinition( _
"I CL", _
"Inventor CL Application", _
CommandTypesEnum.kQueryOnlyCmdType, _
"{3B187401-3D85-4d88-ABC3-C4212051E34D}", _
"Add part numbers & descriptions to parts", _
"CL", _
clp)


Dim oUIManager As UserInterfaceManager = m_inventorApplication.UserInterfaceManager

If firstTime = True Then
If oUIManager.InterfaceStyle = InterfaceStyleEnum.kRibbonInterface Then
' create a ribbon interface

Dim oRibbonP As Ribbon = oUIManager.Ribbons.Item("Part") ' THIS WILL ONLY SHOW UP WHEN A PART FILE IS ACTIVE

' create a new tab

Dim oTabP As RibbonTab = oRibbonP.RibbonTabs.Add("MY MENU", "MYMenuTabPart", "{3B187401-3D85-4d88-ABC3-C4212051E34D}", , , False)

''create a new pannel within the tab

Dim oPanelP As RibbonPanel = oTabP.RibbonPanels.Add("MY Part Items", "MYMenuTabPanelParts", "{3B187401-3D85-4d88-ABC3-C4212051E34D}")

With oPanelP.CommandControls
.AddButton(m_CLStartButtonDef)
' IF YOU HAVE OTHER BUTTONS DEFINED YOU CAN ADD THEM IN THIS SAME AREA
End With


Else
' create a clasic interface
' create a new command bar (tool bar) and make it visible
Dim commandBars As CommandBars
commandBars = m_inventorApplication.UserInterfaceManager.CommandBars
Dim commandBar As CommandBar
commandBar = commandBars.Add("MY Menu", "MY Menu", CommandBarTypeEnum.kRegularCommandBar, _
"{3B187401-3D85-4d88-ABC3-C4212051E34D}")
commandBar.Visible = True
' Add the controlles to the command bar
With commandBar.Controls

.AddButton(m_CLStartButtonDef)

End With
End If

End If

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

End Sub

{code}

hope this will help solve the problem.
0 Likes
Message 5 of 6

Anonymous
Not applicable
will i have to use also the ribbons in the code with the inventor setted up to the classic menu choice?
0 Likes
Message 6 of 6

Mike.Wohletz
Collaborator
Collaborator
No you do not, however the code I provided will add the correct information for either munu type and the clasic is added in this section:

Else
' create a clasic interface
' create a new command bar (tool bar) and make it visible

I always do it like this because I want the same inforation provided if the user has IV 2009 or 2010 or has ribbon turned off in 2010. the choice is yours.
0 Likes