This document is archived and information here might be outdated.  Recommended version.


ICommandBars.Find Method (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference (Framework)  

ICommandBars.Find Method

Searches for the item specified by identifier.

[Visual Basic .NET]
Public Function Find ( _
    ByVal identifier As Object, _
    [ByVal noRecurse As Boolean], _
    [ByVal noCreate As Boolean] _
) As ICommandItem
[C#]
public ICommandItem Find (
    object identifier,
    bool noRecurse,
    bool noCreate
);
[C#]

Optional Values

noRecurse   Supply false as a default value.
noCreate   Supply false as a default value.

Product Availability

Available with ArcGIS Desktop.

Description

identifier is the unique identifier of the item you want to find. For built-in commands and commandbars, use the UID. For VBA commandbars, macros and UIControls use the name.

noRecurse Use False to search all menus and toolbars for the item; otherwise use True. [Optional]

noCreate Use False if you want the item to get instantiated if it isn't already; otherwise use True. [Optional]

 

Remarks

Here is the syntax that can be used for identifier for each type of commandbar or command item.

Built-in commands, menus, and toolbars
Use the unique identifier (UID) of the command, menu, or toolbar. The built-in Normal.ArcID module can be used to find the UID's.

 CommandBars.Find(arcid.Standard_Toolbar)
 CommandBars.Find(arcID.File_AddData) 

Instead of using the ArcID module, you can write your own code to get the UID of the object.

 

To find the CLSID, ProgID, and subtype of an ESRI command, menu, or toolbar refer to the following technical documents:

ArcObjects Developer Help > Technical Documents > ArcMap: Names and IDs of commands and commandbars

ArcObjects Developer Help > Technical Documents > ArcCatalog: Names and IDs of commands and commandbars

Custom VBA toolbars and menus
Use a string that represents the full name of the custom toolbar or menu. The name of the toolbar or menu must include the project or template in which this item was created.

 CommandBars.Find("Normal.MyToolbar")
 CommandBars.Find("Project.MyToolbar")
 CommandBars.Find("Normal.New Menu") 

When you create new menus using the Customize dialog, the first menu you create is named "New Menu", the second menu you create is called "New Menu 1", etc... In the Find method, you need to use the default name of the menu instead of the caption you assigned to it. Here is an example of how custom menu naming works.

If you write code to create a new toolbar or menu then the name of that item will be prefixed by the project or template in which the module was located.

UIControls
Use a string that represents the full name of the UIControl. The name of the UIControl must include the project or template in which this UIControl was created.

  CommandBars.Find("Normal.UIButtonControl1")
  CommandBars.Find("Project.UIToolControl1")
  CommandBars.Find("TemplateProject.UICombboxControl1") 

Macro Items
Use a string that represents the full name of the VBA macro. The name of the macro must include the name of the VBA project and module in which this macro is located. Only Macros that are placed on a toolbar or menu can be found using CommandBars.Find.

  CommandBars.Find("Project.NewMacros.Test")
  CommandBars.Find("Normal.ThisDocument.MyMacro") 

Custom commands, menus, and toolbars
Use the unique identifier (UID) of your custom command, menu, or toolbar. You can create a UID object and set the value of the UID to the CLSID or ProgID of your custom object. For your custom objects, the ProgID is a string composed of the name of your project used to make the command and the class name of the command. For example if you have a Visual Basic project called MyCustomTools and there is a class module for your command called cmdMyZoomTool in that project, then the ProgID for this command would be "MyCustomTools.cmdMyZoomTool". To find the CLSID for this command, you could search the system registry for this ProgID. Note, if you have a command that is a subtype then you also have to set the SubType property on IUID to the subtype value.

 

Calling During Startup
Do not call Find until the Framework has fully initialized itself as indicated by the IApplicationStatus::Initialized property.  For example, custom Extensions may load before the Framework has completely initialized and calling Find at this point may return an error.  During startup, use the IApplicationStatusEvents::Initialized event instead of OnOpenDocument or OnNewDocument to receive notification of when it is safe to use this method.

See Also

ICommandBars Interface | ICommandBars Interface | ICommandBar Interface | ICommandItem Interface | IApplicationStatusEvents Interface | IApplicationStatus Interface

.NET Snippets

Get Command by Name | List ArcMap Visible Toolbars | Use Custom Tool on Windows Form | Find Command and Execute | Set Tool Active in ToolBar | Statements - Use a Tool in a Windows Form | Get Command on Toolbar by Names | Get Toolbar by Name

.NET Samples

Applying user interface customizations at startup (Code Files: AcmeExt)

.NET Related Topics

How to create multiple commands or tools in a single class subtyped command