CommandBars.Find not working in 10.2.1.3497

1781
5
Jump to solution
03-19-2014 06:16 AM
FrancescoGiovinazzo
New Contributor III
Hello,

I have created a simple ArcMap AddIn, Framework .Net 3.5, with a single button in it.

The click method is this one:

protected override void OnClick() {     try     {         UID commandID = new UIDClass();         commandID.Value = "esriArcMapUI.ZoomToSelectedCommand";          ICommandItem comm = ArcMap.Application.Document.CommandBars.Find(commandID.Value);           if(comm != null)              comm.Execute();     }     catch     {     } }


The problem is,
comm
is always null, no matter wich button i search or if i use the guid instead, nothing is returned

Anyone with the same problem, and hopefully, a solution?

This code was working up to 10.1

Thanks

Fra
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
In VB .net this code works, the main differences are highlighted in bold red:

Dim uid As New UIDClass
uid.Value = "esriArcMapUI.ZoomToSelectedCommand"
Dim pCommandItem As ICommandItem
pCommandItem = My.ArcMap.Application.Document.CommandBars.Find(uid, True)
If Not pCommandItem Is Nothing Then
      pCommandItem.Execute()
End If


Duncan

View solution in original post

0 Kudos
5 Replies
DuncanHornby
MVP Notable Contributor
In VB .net this code works, the main differences are highlighted in bold red:

Dim uid As New UIDClass
uid.Value = "esriArcMapUI.ZoomToSelectedCommand"
Dim pCommandItem As ICommandItem
pCommandItem = My.ArcMap.Application.Document.CommandBars.Find(uid, True)
If Not pCommandItem Is Nothing Then
      pCommandItem.Execute()
End If


Duncan
0 Kudos
FrancescoGiovinazzo
New Contributor III
Hello Duncan,

in C# there is no need for the My prefix, and the true you highlight is basicly an override of the default parameter "noRecurse = false"

However, i tried the same code with the , true and nothing changed, still null, thank you for trying that

Fra
0 Kudos
AhmedEl-Sisi
Occasional Contributor III
Try "esriArcMapUI.MxSelectionMenu" instead of "esriArcMapUI.ZoomToSelectedCommand"
protected override void OnClick()
{
    try
    {
        UID commandID = new UIDClass();
        commandID.Value = "esriArcMapUI.MxSelectionMenu";

        ICommandItem comm = ArcMap.Application.Document.CommandBars.Find(commandID.Value);

         if(comm != null)
             comm.Execute();
    }
    catch
    {
    }
}


All 10.2 GUIDs (CLSID / ProgID):
http://resources.arcgis.com/en/help/arcobjects-net/conceptualHelp/#/ArcMap_commands/00010000029s0000...

Regards,
0 Kudos
FrancescoGiovinazzo
New Contributor III
Hello cc4ever,

I tried many of the ids in the link you gave me, but everyone is still returning null, without errors... i don't know where i could possibly look into

On a sidenote, if I add to watch the instruction "Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported" and evaluate the expression, it says "Predefined type 'Microsoft.CSharp.RuntimeBinder.Binder' is not defined or imported"

A quick google shows me that it's a 4.0 issue, but my addin is 3.5... mysteries

Regards

Fra
0 Kudos
FrancescoGiovinazzo
New Contributor III
Found my problem, and i think i am stupid, giving credit to Duncan for the fix

I was passing commandID.Value to the Find method, instead of the commandID itself

Problem solved

This

ICommandItem comm = ArcMap.Application.Document.CommandBars.Find(commandID);


Is now working as expected

Thank you

Fra
0 Kudos