Fire custom tool from another custom tool

446
4
Jump to solution
05-08-2019 05:53 AM
BrianBulla
Occasional Contributor III

Hi,

I'm trying to run a custom tool from an Editor Extension I am building.  I've done this before with out of the box ArcMap tools (ie. Zoom to Selection), but for some reason this code I am using will not work for a custom tool I have created.  The tool GUID is {079952c5-83c1-49e8-bd1a-4440f623281f} and it is definitely in my map, but when I run the tool it can't seem to find it based on the GUID, so cmdItem is null and the line "cmdItem.Execute();" does not run.

Any ideas what I am doing wrong??

                            if (inFeature.Fields.FindField("FACILITYID") != -1)
                            {
                                ICommandBars cmdBars = ArcMap.Application.Document.CommandBars;
                                
                                UID uid = new UID();
                                uid.Value = "{079952c5-83c1-49e8-bd1a-4440f623281f}";
                                ICommandItem cmdItem = cmdBars.Find(uid, false, false);
                                if (cmdItem != null)
                                    cmdItem.Execute();
                            }
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hey Brian,

Where are you getting the GUID for the tool from? If its an add-in dont get confused with the GUID of the add-in itself, as shown in the config file.

For an add-in tool you would normally use the ID of the tool to find it.

e.g. config.esriaddinx

 <AddIn language="CLR" library="ExplodePartAsFeature.dll" namespace="ParttoFeature">
    <ArcMap>
      <Commands>
        <Tool id="ParttoFeature_ParttoFeatureCmd" ...
        <Button id="ParttoFeature_ActivatePart" ...
      </Commands>

to find the "ParttoFeature_ParttoFeatureCmd" tool

      //find the addin tool
      ICommandBars documentBars = ArcMap.Application.Document.CommandBars;
      UID cmdID = new UIDClass();
      cmdID.Value = "ParttoFeature_ParttoFeatureCmd";
      ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
      ArcMap.Application.CurrentTool = cmdItem;‍‍‍‍‍‍

View solution in original post

4 Replies
GKmieliauskas
Esri Regular Contributor

Hi Brian,

I use Execute for custom Commands and CurrentTool method from IApplication for custom Tools. They work a little bit different.

0 Kudos
BrianBulla
Occasional Contributor III

Thanks Gintatuas, Sean Jones

I've done some messing around and my code seems to work with other tools in the map (ie. {AB073B49-DE5E-11D1-AA80-00C04FA37860} which is the Zoom to Selection button), but with my custom tool this bit of code...

UID uid = new UIDClass();
uid.Value = "{079952c5-83c1-49e8-bd1a-4440f623281f}";                                             
ICommandItem cmdItem = cmdBars.Find(uid, false, false);

cannot find the tool.  That is for sure the GUID of the tool.  Do you know if there is a setting in the Config.esriaddinx file that I might need to set to make it 'Public'??

0 Kudos
by Anonymous User
Not applicable

Hey Brian,

Where are you getting the GUID for the tool from? If its an add-in dont get confused with the GUID of the add-in itself, as shown in the config file.

For an add-in tool you would normally use the ID of the tool to find it.

e.g. config.esriaddinx

 <AddIn language="CLR" library="ExplodePartAsFeature.dll" namespace="ParttoFeature">
    <ArcMap>
      <Commands>
        <Tool id="ParttoFeature_ParttoFeatureCmd" ...
        <Button id="ParttoFeature_ActivatePart" ...
      </Commands>

to find the "ParttoFeature_ParttoFeatureCmd" tool

      //find the addin tool
      ICommandBars documentBars = ArcMap.Application.Document.CommandBars;
      UID cmdID = new UIDClass();
      cmdID.Value = "ParttoFeature_ParttoFeatureCmd";
      ICommandItem cmdItem = documentBars.Find(cmdID, false, false);
      ArcMap.Application.CurrentTool = cmdItem;‍‍‍‍‍‍
BrianBulla
Occasional Contributor III

Hi Sean Jones‌.  Changing from using the GUID from the Config file to the ID worked.

Thanks!  I would have thought using the GUID would have been the proper choice.

0 Kudos