DCSIMG
Creating a custom tool for ArcGis products - YsA.Net

Creating a custom tool for ArcGis products

Posted Friday, January 11, 2008 11:57 AM by ysa

ESRI's desktop products can be extended by adding tools and command buttons integrally into the environment. This can be done by using VBA inside the products, or creating controls in .Net using the .Net ADF that's supplied with the product installation.

In order to create a custom command/tool you need to install the desktop products, and the .Net SDK for them. After the installation, new templates are added to visual studio.

To start creating the tool follow these steps :

  1. Open visual studio.
  2. File -> New -> project -> Visual C# -> ArcGis -> Desktop -> Class Library (product - ArcMap,ArcCatalog,etc...)
  3. Select Assemblies to reference (If you don't know you can return to this selection by right click on the references icon under the project -> Add ArcGis reference).

Now you have a project that can contain the new controls for the desktop, and it's time to create a new control. There are several types of controls you can create : command,tool, dockable window, etc...

The difference between command and tool is :

  • A tool receives input from the environment, like mouse events. For example : Zoom-in is a tool. A tool stays selected until you chose another tool.
  • A command is like a button. You click on it and something happens. For example : Full-extent is a command. Command does not effect the selected tool, and after you click a command, if a tool was selected before it will stay selected after the command preformed.

Ok. Lets create a simple tool for ArcMap that will display coordinate on which we clicked with the mouse. In order to do this, create a project of type Class Library (ArcMap) as describe earlier and add the assemblies : Display,Geometry,ArcMap. Then right click on the project -> New class -> ArcGis -> Base tool. Now selected ArcMap as the target product. As you can see a new class was generated :

  • It derives from BaseTool which is the base class for tools. There is also BaseCommand for command.
  • It contains methods for COM registrations. Because the all of ESRI's products are COM based, you need to register the control for COM usage. For this you need the GUID attribute on the class. These methods are triggered when you build your projects. You can also trigger them with an installer (when you deploy the tool as an MSI).
  • The constructor contains several initializations. You can set the caption on the tool,tooltip, bitmap - for icon on the button, and more important : In which category the tool will be placed (We will go back to that later).
  • Overrides for the events the tool can handle. You can see there are, among else, mouse events.

Set the variables in the constructor to the following values :

base.m_catagory = "YsA tools"; base.m_caption = "Show position"; ... base.m_name = "YsATools_ShowPosition";

In the OnMouseDown event, write this code :

IPoint point = m_application.Display.DisplayTransformation.ToMapPoint(X,Y); MessageBox.Show("X : " + point.X + ", Y : " +point.Y);

In order to use the tool do the following :

  1. Build the solution.
  2. Open ArcMap.
  3. Tools->Customize
  4. In the category list chose the category you set in the constructor - "YsA Tools".
  5. Search for the tool "Show position" in the commands list, and drag it onto one of the toolbars.
  6. Close the dialog box.
  7. Click on the tool button. As you can see it stays active.
  8. Click on the map. A message box will popup and display the coordinates on which you clicked (in decimal format).

This is a very simple example. You can do a lot of things in these controls - open forms and receive user input, use ArcObjects to perform geographic operations, etc... The sky is the limit.

Comments

# re: Creating a custom tool for ArcGis products

Friday, January 11, 2008 11:05 PM by Yoav

מגניב מאיפה למדת את זה ?

# Creating a setup project for ArcGis custom tools

Friday, January 18, 2008 9:13 AM by YsA.Net

In my last post I described how to create extensions to ArcGis products. After we've finished developing

# re: Creating a custom tool for ArcGis products

Sunday, August 10, 2008 8:45 AM by TDenis

ArcGis 9.2 + VS'05:

m_application.Display.DisplayTransformation.ToMapPoint(X, Y);

generates:

Error 1 'ESRI.ArcGIS.Framework.IApplication' does not contain a definition for 'Display'

instead:

IMxDocument aDoc = (IMxDocument)m_application.Document;

IActiveView aView = aDoc.ActiveView;

IPoint point = aView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

MessageBox.Show("X : " + point.X + ", Y : " + point.Y);

# re: Creating a custom tool for ArcGis products

Wednesday, August 13, 2008 3:35 PM by seyi

Can i link ArcGis Commands to a command button in a custom ArcGIS aaplication? I need this support fast. Thanks

# re: Creating a custom tool for ArcGis products

Wednesday, December 17, 2008 11:52 AM by Tim

Using ArcGIS9.3 + VS2008

m_application does not exist in current context.

using the suggesting posted on Aug 10, IActiveView, IMxDocument do not exist

# re: Creating a custom tool for ArcGis products

Thursday, December 18, 2008 8:28 PM by ysa

Tim,

I haven't tried this in 9.3.

I'll check it out.

# re: Creating a custom tool for ArcGis products

Monday, February 15, 2010 5:43 PM by Michael Collins

9.3 has been out for a while, please update this tutorial so it works. It does not work if you follow it exactly.

# re: Creating a custom tool for ArcGis products

Tuesday, February 16, 2010 4:19 PM by Michael Collins

I think you need to add some references to get it to work, but I can't figure out which ones

# re: Creating a custom tool for ArcGis products

Tuesday, February 16, 2010 8:27 PM by Michael Collins

sorry for the multiple posts; I had to add the following to get it to work for 9.3.1

private ESRI.ArcGIS.Carto.IPageLayout m_PageLayout;

then under OnMouseDown

IActiveView activeView = m_PageLayout as IActiveView;

m_PageLayout = m_hookHelper.PageLayout;

IScreenDisplay screenDisplay = activeView.ScreenDisplay;

IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

ESRI.ArcGIS.Geometry.IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

MessageBox.Show("X : " + point.X + ", Y : " + point.Y);

# re: Creating a custom tool for ArcGis products

Monday, October 18, 2010 1:23 PM by Carin

Can anyone help me please. I need a tool to split my streetline and then ad in from and to. for example 1 st avenue is from 2 nd avenue to 3 rd avenue.  Et wizard only have a function where you can put in from and to with a point but not with the same streetline shape file.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: