Changes of AcMapMap.GroupModified and AcMapMap.LayerModified event args

By Daniel Du

In Map 3D 2013 Geospatial platform API, the argument type of the AcMapMap.GroupModified and AcMapMap.LayerModified event handlers has been changed from AcMapMappingEventArgs to AcMapMapObjectModifiedEventArgs, because the latter contains the Modification property, which let us know what we have changed.

The Modification property is a bit field of the properties that changed during a layer or group modified event, as follows:

      /// <summary>

      /// Name property changed during the event.

      ///</summary>

      static const INT32 Name               = 1;

      /// <summary>

      /// Visibility changed during the event.

      ///</summary>

      static const INT32 Visibility         = 2;

      /// <summary>

      /// Layer selectability during the event.

      ///</summary>

      static const INT32 LayerSelectability = 4;

      /// <summary>

      /// Parent changed during the event.

      ///</summary>

      static const INT32 ParentChanged      = 8;

Here is a sample code snippet to demo how to use it:

[CommandMethod("ListenToLayerChange")]

public void ListenToLayerChange()

{

  AcMapMap currentMap = AcMapMap.GetCurrentMap();

  currentMap.GroupModified +=

    new GroupModifiedHandler(currentMap_GroupModified);

  currentMap.LayerModified +=

    new LayerModifiedHandler(currentMap_LayerModified);

 

}

 

void currentMap_LayerModified(object sender,

                              AcMapMapObjectModifiedEventArgs args)

{

  OutputChanges(args.Modification);

}

void currentMap_GroupModified(object sender,

                              AcMapMapObjectModifiedEventArgs args)

{

  OutputChanges(args.Modification);

}

 

private static void OutputChanges(int modification)

{

  Editor ed = Autodesk.AutoCAD.ApplicationServices.Application

    .DocumentManager.MdiActiveDocument.Editor;

 

  ///// <summary>

  ///// Name property changed during the event.

  /////</summary>

  //static const INT32 Name               = 1;

  ///// <summary>

  ///// Visibility changed during the event.

  /////</summary>

  //static const INT32 Visibility         = 2;

  ///// <summary>

  ///// Layer selectability during the event.

  /////</summary>

  //static const INT32 LayerSelectability = 4;

  ///// <summary>

  ///// Parent changed during the event.

  /////</summary>

  //static const INT32 ParentChanged      = 8;

  switch (modification)

  {

    case 1:

      ed.WriteMessage("\n Layer or LayerGroup name is changed.");

      break;

 

    case 2:

      ed.WriteMessage(" \nLayer or LayerGroup Visibility  is changed.");

      break;

 

    case 4:

      ed.WriteMessage(" \nLayer or LayerGroup LayerSelectability is changed.");

      break;

 

    case 8:

      ed.WriteMessage(" \nLayer or LayerGroup Parent is changed.");

      break;

    default:

      break;

  }

}

 

when I change the name of layer in task pane of Map 3D, the LayerModified event is trigger, with “args.Modification”, I know that it is the layer’s name is changed. Similarly, when I turn on/off a layer, I get a notification of the changes of visibility of layer. And when I drag one layer from one layer group to another, I get a notification saying that the parent of layer is changed.

 

The result output is as below:

————————————-

Command:
Command: netload
Command: LISTENTOLAYERCHANGE
Layer or LayerGroup name is changed.
Layer or LayerGroup Visibility  is changed
Layer or LayerGroup Parent is changed.
Command:

————————————-

Hope this helps.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading