1

I encountered a runtime error when I used the sample code from ESRI on Accessing a topology. The sample code is as follows:

Dim topoUiD As UID = New UIDClass
topoUiD.Value = "esriEditorExt.TopologyExtension"
Dim m_application As IApplication   ' this line is added by me
Dim topologyExt As ITopologyExtension = CType(m_application.FindExtensionByCLSID(topoUiD),  ITopologyExtension)
Dim topology As ITopology
topology = CType(topologyExt.CurrentTopology, ITopology)

A runtime error occurs when execute: Dim topologyExt As ITopologyExtension = CType(m_application.FindExtensionByCLSID(topoUiD), ITopologyExtension

I guess it is caused by the definition of m_application, anybody can tell me how to define it? thanks.

  • 1
    What is the runtime error? Is m_application set to something? What level of license are you using? TopologyExtension is not available for Basic (View) license. – Michael Stimson Jul 31 '14 at 4:01
  • I even don't have a chance to see the runtime error, it just close the ArcMap directly. From the example, I don't know what should set to the m_application. I am using standard license. – ppLily Jul 31 '14 at 5:27
  • 2
    dim m_application as IApplication = ArcMap.Application assuming you are using an add-in. – Michael Stimson Jul 31 '14 at 5:30
  • Thanks Michael, with your kindly help I can successfully access a topology. I am using a add-in and very new to it so many silly questions. – ppLily Jul 31 '14 at 5:52
  • We all started somewhere. Don't be ashamed of a 'silly' mistake we've all made mistakes before. – Michael Stimson Jul 31 '14 at 22:00
2

To clarify the comments, the problem is that you have an IApplication object but haven't linked it to ArcMap (initialized the object):

Dim topoUiD As UID = New UIDClass
topoUiD.Value = "esriEditorExt.TopologyExtension"
Dim m_application As IApplication =  My.ArcMap.Application  ' initialize the object
Dim topologyExt As ITopologyExtension = CType(m_application.FindExtensionByCLSID(topoUiD),  ITopologyExtension)
Dim topology As ITopology
topology = CType(topologyExt.CurrentTopology, ITopology)

The object is created an initialized: Dim m_application As IApplication = My.ArcMap.Application, note in C# My is not used and it's IApplication m_application = ArcMap.Application;

Here is a link showing how to start an Add in.

Here is a link to the ArcMap object

In your add in it's important to link to the current application/document using My.ArcMap.IApplication (IApplication) or the other important one My.ArcMap.Document (an IMXDocument)

You can condense these two lines:

Dim m_application As IApplication =  My.ArcMap.Application  ' initialize the object
Dim topologyExt As ITopologyExtension = CType(m_application.FindExtensionByCLSID(topoUiD),  ITopologyExtension)

into:

Dim topologyExt As ITopologyExtension = CType(My.ArcMap.Application.FindExtensionByCLSID(topoUiD),  ITopologyExtension)

As long as you don't need the m_application object later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.