Work with Mechanical Layers and Layer Groups (Part 2 of 2)

Dmytro Kabenok

June 11, 2021

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.

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
}