Application/Map Hook - Obtaining a reference to the currently loaded map

223
4
04-12-2011 05:01 AM
Highlighted
New Contributor
Hello,

I'm developing a customization for ArcMap 10 using C#.NET and ArcObjects and am trying to access the current map.

I'm fleshing out this customization: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/0001/0001000004s8000000.htm

Essentially, I'd like a high-level overview of application hooks and how they can be used to get a reference to the current map (I don't need the current application reference as of yet, but if it contains the map element itself, I can deal with that instead). I don't have any Windows development experience and this concept is new to me. I've tried adding the OnCreate method, but that didn't work, and I wasn't sure to which file it should be added.

If anyone could give me any insight into how application hooks work and how they are integrated into ArcObjects customizations it'd be greatly appreciated.

Thanks!
Reply
0 Kudos
4 Replies
Highlighted
Regular Contributor II
The hook is meant to support different types of application for the same code.  When you develop with ArcGIS desktop, you register your components (ESRIRegAsm.)  That places a reference to the component you developed in the registry in a category.  There are many categories, some apply only to arcmap, others apply to ArcMap, Globe, Catalog, Engine, etc.  When any of these applications start up, they read the registry to see which components apply to it.  At various other times components are read from the registry and created.  For a command or and extension, that is when the oncreate will be called by the ArcMap application.  In your development, you need to be able to get a reference to the ArcMap application or to the map, this is what the hook is for, it allows you to get a handle or hook into the application that created the component.

A command for example could be registered to work in any ArcGIS application.  In that case, when the ICommand.OnCreate is invoked, any of these applications or hooks could be passed into to the command.  You need to be able to handle the different possibilities,  the hookhelper is a generic way to handle any type of application, it applies to all of them.
Reply
0 Kudos
Highlighted
New Contributor
Wow, thanks, that explanation helped out a lot.

There was already an OnCreate implementation in my current codebase, but it's in a file called AddEXTCLSID.cs, which is the main file that's loaded during ArcMap startup. I essentially associate this component with a feature class in the editor and my actual implementation (StreetName.cs) is used automatically when editing address points in the configured feature class.

What I can't seem to find is where my implementation class is instantiated. There's no call to its constructor anywhere in my codebase, and since I don't know where it's being instantiated, I don't know how I can pass a reference to the current IApplication, which resides in the AddEXTCLSID object, to my actual implementation class. Since it's declared as a private member variable, and since my implementation class doesn't have a reference to the instantiated object anyway, I don't see how I can access this.

Any ideas?
Reply
0 Kudos
Highlighted
Regular Contributor II
The example you reference is for a ClassExtension.  The command just registers the class extension to the featureclass.  From that point on, the feature class has a reference to the an extension id (guid, I think) in the database.  So when the featureclass is edited or identified or whatever, Arcmap checks if the featureclass is registered as having a class extension, then looks in the windows registry for where the code for that extension is and loads it.  You cannot instantiate the code your self, that is done by arcmap/arcobjects for you.   The class extension init method passes a reference to the featureclass.  You wouldn't want to use a reference to the application directly in a class extension since, in some cases there might not be one.  It is possible to write a console exe that uses arcobjects and edits or does something to a featureclass that has a class extension that will get instantiated at run time by arcobjects.

Class extension are a little tricky to work with, I suggest you read this part in the help.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Creating_class_extensio...
Reply
0 Kudos
Highlighted
New Contributor
Thanks for the detailed explanation; it definitely helps clarify what's happening with my editor extension.

As a result of your explanation I did some additional investigation and realized that I can call get_Datasets on the IWorkspace object that I do have a reference to, which will give me access to pretty much anything in the current document.

Thanks a million for all of your help; it's been greatly appreciated.
Reply
0 Kudos