[Back to Blog](/blog) # Work with Mechanical Layers and Layer Groups (Part 2 of 2)

Dmytro Kabenok June 11, 2021 [\#mechanical](/blog/tag/mechanical) [\#getting started](/blog/tag/getting-started)

<a class="a2a_button_facebook"></a><a class="a2a_button_twitter"></a><a class="a2a_button_linkedin"></a>

#### Examples of Working with Layer Groups

This is the second article in a series about mechanical layers and layer groups. For the first article in the series, see [Part 1](https://www.opendesign.com/blog/2021/may/work-mechanical-layers-and-layer-groups-part-1-2).

To get an array of all existing mechanical layer group names, use the following code example:

```
// Note: The next block of code requires additional inclusion of "AmiLayer.h"

OdDbDatabase* pDb = ... // get a pointer to the current database

OdStringArray layerGroupNames; // array for group names
AmiStatus status = amiGetLayerGroups(layerGroupNames, pDb);
if (status.success())
{
  ... // Perform an action on the array. For example, display it on the screen.
}
else
{
  ... // Failure during execution
}
```

To get an array of mechanical layer names from a specific group, use the following code example:

```
// Note: The next block of code requires additional inclusion of "AmiLayer.h"

OdDbDatabase* pDb = ... // get a pointer to the current database

OdStringArray layerNames; // array for layer names
OdString groupName = ... // specify the group name

AmiStatus status = amiGetLayersFromGroup(groupName, layerNames, pDb);
if (status.success())
{
  ... // Perform an action on the array. For example, display it on the screen.
}
else
{
  ... // Failure during execution
}
```

To move all entities from one group to another, use the following code example:

```
// Note: The next block of code requires additional inclusion of "AmiLayer.h"

OdDbDatabase* pDb = ... // get a pointer to the current database

OdString srcGroup = ... // specify the source group name
OdString targetGroup = ... // specify the name of the group to which the
                           // entities will be moved. If no such group exists,
                           // it will be created if the original group contains
                           // at least one element

AmiStatus status = amiMoveLayerGroupEntities(srcGroup, targetGroup, pDb);
if (status.success())
{
  ... // Entities successfully moved
}
else
{
  ... // Failure during execution or input parameters are incorrect
}
```

To get an array of entity IDs from a specific layer group, use the following code example:

```
// Note: The next block of code requires additional inclusion of "AmiLayer.h"

OdDbDatabase* pDb = ... // get a pointer to the current database

// Default mechanical layer group: 'Base Layergroup'
// For getting entity IDs from all layers use '*' as groupName

OdString groupName = ... // specify the layer group name
bool bIgnoreBlocks = ... // set to “true” if blocks should be ignored
bool bOnlyBlockRefs = ... // set to “true” if only block references should be collected
bool bIgnore_FLO_Objects = ... // set to “true” if frozen, locked and off layers should be ignored

OdDbObjectIdArray entityIds; // array for entity IDs

AmiStatus status = amiGetLayerGroupEntities(pDb, groupName, entityIds, bIgnoreBlocks, bOnlyBlockRefs, bIgnore_FLO_Objects);
if (status.success())
{
  ... // Perform an action on the array. For example iterate through array and display entity names on the screen.
}
else
{
  ... // Failure during execution or input parameters are incorrect
}
```

## Get started today

**Try ODA software free for 60 days.  
No risk, no credit card required.**

[Try for Free](https://www.opendesign.com/free-trial)
