Select to view content in your preferred language

Custom Toolbar VB.NET

672
2
05-21-2010 01:16 PM
RuchiraWelikala
Regular Contributor
Hi All,
I have made several tools via Base Commands using VB.NET for ArcMap.  After building the solution, I open up ArcMap and the tools are available for me to add through TOOLS>CUSTOMIZE>COMMANDS (tab). 
I want to put the tools that I created into a Toolbar using VB.NET and the BaseToolBar template. 
The example in the template shows this:

        AddItem("esriArcMapUI.ZoomOutTool")
        BeginGroup() 'Separator
        AddItem("{FBF8C3FB-0480-11D2-8D21-080009EE4E51}", 1) 'undo command
        AddItem(New Guid("FBF8C3FB-0480-11D2-8D21-080009EE4E51"), 2) 'redo command


How would I insert my own tools into the toolbar?  Do I use the GUIDS or can I use the UniqueID I set in the source code of each individual tool? 

Any help or pointers would be much appreciated.
Thanks
0 Kudos
2 Replies
AlexanderGray
Honored Contributor
You can use the name, it should work but I usually use the GUID.  If the tool and the commandbar are in the same project, you can reference the class_Name.ClassId since the class id is a public constant on the class

AddItem(New Guid(cmdMyTool.ClassId))
0 Kudos
RuchiraWelikala
Regular Contributor
You can use the name, it should work but I usually use the GUID.  If the tool and the commandbar are in the same project, you can reference the class_Name.ClassId since the class id is a public constant on the class

AddItem(New Guid(cmdMyTool.ClassId))


Thanks for your reply Alexander. 
My tools are in separate solutions.  The code below shows the beginning portion of one of the tools that I'm trying to add to the toolbar.  Is there away to use the m.Name or should I just use the class id GUID?

Thanks again

ComClass(WellsUpdate.ClassId, WellsUpdate.InterfaceId, WellsUpdate.EventsId), _
 ProgId("DataUpdateTools.WellsUpdate")> _
Public NotInheritable Class WellsUpdate
    Inherits BaseCommand

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "5ec71862-3712-4b4e-8f31-2e58516eb72f"
    Public Const InterfaceId As String = "6c0adce7-40f3-4a77-8cce-5dde019e1533"
    Public Const EventsId As String = "ca799000-3199-47f6-802e-6a70735db83c"
#End Region

#Region "COM Registration Function(s)"
    <ComRegisterFunction(), ComVisibleAttribute(False)> _
    Public Shared Sub RegisterFunction(ByVal registerType As Type)
        ' Required for ArcGIS Component Category Registrar support
        ArcGISCategoryRegistration(registerType)

        'Add any COM registration code after the ArcGISCategoryRegistration() call

    End Sub

    <ComUnregisterFunction(), ComVisibleAttribute(False)> _
    Public Shared Sub UnregisterFunction(ByVal registerType As Type)
        ' Required for ArcGIS Component Category Registrar support
        ArcGISCategoryUnregistration(registerType)

        'Add any COM unregistration code after the ArcGISCategoryUnregistration() call

    End Sub

#Region "ArcGIS Component Category Registrar generated code"
    Private Shared Sub ArcGISCategoryRegistration(ByVal registerType As Type)
        Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
        MxCommands.Register(regKey)

    End Sub
    Private Shared Sub ArcGISCategoryUnregistration(ByVal registerType As Type)
        Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
        MxCommands.Unregister(regKey)

    End Sub

#End Region
#End Region


    Private m_application As IApplication

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()

        ' TODO: Define values for the public properties
        MyBase.m_category = "PetroGIS Tools"  'localizable text 
        MyBase.m_caption = "Wells Update"   'localizable text 
        MyBase.m_message = "Update Well Data From Database"   'localizable text 
        MyBase.m_toolTip = "Wells Update" 'localizable text 
        MyBase.m_name = "PetroGISTools_WellsUpdate"  'unique id, non-localizable (e.g. "MyCategory_ArcMapCommand")
0 Kudos