AcMapLayerGroup Documentation?

AcMapLayerGroup Documentation?

Anonymous
Not applicable
801 Views
3 Replies
Message 1 of 4

AcMapLayerGroup Documentation?

Anonymous
Not applicable

Can any help me find some documentation on the Acmaplayergroup class(s)?

 

I've looked through the SDK and i can't found anything other then one reference to it saying that you can add mulitple layers and they most be unique but nothing about how to create them.

 

does it need a resouce id? does it need a library path? do you need to create a mglayergroup object then add it as an acmaplayergroup (as you do with a layer)?

 

either that or sample c# code of adding a layergroup Smiley Wink

 

any help would be great.

 

Mark

0 Likes
802 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

AcMapLayerGroup derives from MgLayerGroup so that methods and properties of MgLayerGroup also apply to AcMapLayerGroup

 

MgLayerGroup does not require a resource id as it is not a resource. It is a container by which MgLayerBase objects (and its derivatives MgLayer and AcMapLayer) can belong in by calling its SetGroup() method (or assigning to its Group property)

 

So what you would do is:

 

  1. Get a reference to the current map
  2. Add your layer groups to the map
  3. For each layer you create you can optionally assign to one of the layer groups by calling its SetGroup() method (or assigning to its Group property)

 

- Jackie

0 Likes
Message 3 of 4

Anonymous
Not applicable

Jackie,

 

Thanks for the response. That's what i suspected but if that is the case then i most of missed something. below is the c# code i am running where;

 

 layergroup = a text string of layergroup name i want to use.

cmap = current map (surprise surprise).

layer is the mglayerbase object i am adding (its already had its resource id, definition, etc set)

ed is the autocad editor

 

 if (layergroup != null )
 {
  MgLayerGroupCollection layergroups = cmap.GetLayerGroups();
  foreach (MgLayerGroup group in layergroups)
  {
   if (group.Name == layergroup)
   {
    ed.WriteMessage("\nThe Layergroup called (" + layergroup + ")has been found");
    layer.SetGroup(group);
   }
  }

}
 AcMapMap.GetCurrentMap().GetLayers().Add(layer);

 

I am getting the "The Layergroup ... found" line on the commandline but the layer is not being added to the group. Am i missing something that you can see?
 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

 Ok I have found away of doing it (so this is an FYI for anyone else trying to do the same)

 

Basically you have to first add the layer to the map and then assign the group to the added layer.

MgLayerBase setgrouplayer =  AcMapMap.GetCurrentMap().GetLayers().GetItem(layername);
MgLayerGroupCollection groups = cmap.GetLayerGroups();
foreach (MgLayerGroup group in groups)
{
    if (group.Name == layergroup)
    {
        setgrouplayer.SetGroup(group);
    }
}

 where;

layername = the name of the layer you wish to move to the group (string)
layergroup = the name of the group you wish to add the layer to (string & must be exisitng in the current map)

 

Is it possible for this to be outlined in the SDK docs for the next release please (unless I have the concept incorrect)

 

Regards

Mark

 

 

0 Likes