2 Replies Latest reply on Aug 6, 2013 10:25 AM by Josh Brady

    Possible issues using ISWApp.IActiveDoc2.SelectionManager or Interfaces Directly Related to ModelDoc2.

    Jacob Corder

      I am wanting to get rid of setting a ModelDoc2 Object along with SelectionManager and FeatureManager objects in my code where i would substitute the following


      Current Method i use to write code


      Dim ModDoc as ModelDoc2  = ISwapp.iactivedoc2

      If Isnothing(ModDoc) = false then

           Dim SelMgr as SelectionManager = ModDoc.ISelectionManager

           Dim FeatMgr as FeatureManager = ModDoc.FeatureManager

           Dim SKMgr as SketchManager = ModDoc.SketchManager



           DO SOMETHING



      End If


      The way i would like to do it is as follows. I know that not setting these to a memory location will not let me access these if the active document changes which is fine as i am always using the active document. I am trying to avoid having to clean up my com objects after functions.


      Let me know your thoughts.


      If IsNothing(Iswapp.IactiveDoc2) = false then

      If IsNothing(ISwapp.IActiveDoc2.ISelectionManager) = false and isnothing(ISwApp.IActiveDoc2.FeatureManager) = false and isnothing(ISwApp.IActiveDoc2.SketchManager) = false then



           DO SOMETHING




      end if

        • Re: Possible issues using ISWApp.IActiveDoc2.SelectionManager or Interfaces Directly Related to ModelDoc2.
          Josh Brady

          I think the main issue is that your code will run way slower.


          Of course, if you have a short macro and way slower means 0.05s instead of 0.005s, nobody will ever notice. 

          • Re: Possible issues using ISWApp.IActiveDoc2.SelectionManager or Interfaces Directly Related to ModelDoc2.
            Josh Brady

            Here's something I found with a quick Google search:


            (source: http://edndoc.esri.com/arcobjects/8.3/gettingstarted/vbenvgeneral.htm)


            Often interfaces have properties that are actually pointers to other interfaces. Visual Basic allows you to access these properties in a shorthand fashion by chaining interfaces together. For instance, assume that you have a pointer to the IFoo interface, and that interface has a property called Gak that is an IGak interface with the method DoSomething(). You have a choice on how to access the DoSomething method. The first method is the long-handed way.

              Dim pGak as IGak Set pGak = pFoo      'Assign IGak interface to local variable pGak.DoSomething     'Call method on IGak interface

            Alternatively, you can chain the interfaces and accomplish the same thing on one line of code.

              pFoo.Gak.DoSomething  'Call method on IGak interface

            When looking at the sample code, you will see both methods. Normally the former method is used on the simpler samples, as it explicitly tells you what interfaces are being worked with. More complex samples use the shorthand method.

            This technique of chaining interfaces together can always be used to get the value of a property, but it cannot always be used to set the value of a property. Interface chaining can only be used to set a property, if all the interfaces in the chain are set by reference. For instance, the code below would execute successfully.

              Dim pMxDoc As ImxDocument Set pMxDoc = ThisDocument pMxDoc.FocusMap.Layers(0).Name = "Foo"

            The above example works because both the Layer of the Map and the Map of the document are returned by reference. The lines of code below would not work since the Extent envelope is set by value on the active view.

              pMxDoc.ActiveView.Extent.Width = 32

            The reason that this does not work is that the VBVM expands the Inter-face chain in order to get the end property. Because an interface in the chain is dealt with by value, the VBVM has its own copy of the variable, not the one chained. To set the Width property of the extent envelope in the above example, the VBVM must write code similar to this:

              Dim pActiveView as IActiveView Set pActiveView = pMxDoc.ActiveView  Dim pEnv as IEnvelope Set pEnv = pActiveView.Extent  ' This is a get by value,  pEnv.Width = 32   ' The VBVM has set its copy of the Extent and not ' the copy inside the ActiveView

            For this to work the VBVM requires the extra line below.

              pActiveView.Extent = pEnv  ' This is a set by value,