Diagram / Diagram DOM / Batches
In This Topic
Batches
In This Topic
 About Batches

Batches serve as a functionality layer between the DDOM and the user. They help you apply a uniform operation to a set of diagram items. All types of batches derive from the base NBatch<TItem> abstract class, where TItem should be a NDiagramItem. Some batch operations are constrained by permissions (see Abilities, Protection and Permissions for more information). The batches are defined in the Nevron.Nov.Diagram.Batches namespace.

Prior to executing some batch operation you must first call it's Build method, which takes a single argument - array of nodes, from which the batch must be built.

Batches are used to perform different operations on a set of diagram items, which are optionally recorded as a single transaction in the document history service. All batch methods, which record transactions in the document history service return an instance of the NTransactionResult structure.

Following is a brief description of the currently available batches:

Batch class TItem base type Description
NBatchCompose NPageItem Facilitate the Composite Solid Geometry operations with shape geometries (e.g. Union, Intersect, Subtract and ExclusiveOr).
NBatchDelete NDiagramItem Facilitate the deletion of multiple diagram items
NBatchFormat NPageItem Facilitate format operations (mainly with shapes geometry and text block).
NBatchGroup NPageItem Facilitate the grouping of shapes (e.g. the creation of a new group from a set of shapes)
NBatchInplaceEdit NPageItem Facilitate inlace edit operations, such as ReplaceAll instances of a text string in a set of shapes
NBatchInsert NDiagramItem Facilitate the insertion of multiple elements in one collection.
NBatchLayout NPageItem Provides transaction based layout operations. Implements common alignment, resize, horizontal spacing, vertical spacing and center in page operations.
NBatchOperation NPageItem Provide miscellaneous transaction based operations, which are not constrained by permissions and purely rely on the type of items inside the batch.
NBatchReorder NDiagramItem Facilitates the reorder of items in their containers (e.g. Z-Order)
NBatchTransform NPageItem Facilitates transformation based operations on a set of shapes
NBatchTranslate NPageItem Facilitates the translation of multiple items together with their translation slaves
NBatchUngroup NPageItem Facilitates the ungrouping of groups (e.g. the destruction of existing groups)
 Examples

Format batch example: The following code applies solid red color filling to all selected elements:

C#
Copy Code
// create a new format batch associated with the specified document
NBatchFormat batchFormat = new NBatchFormat(m_DrawingDocument);
// build it from the active page selection
batchFormat.Build(m_DrawingDocument.Content.ActivePage.Selection.SelectedItems);
// check if the style of all batch nodes can be changed
if (batchFormat.CanFormat())
{
    // set red fill style to all batch nodes
    batchFormat.ChangeGeometryFill(new NColorFill(NColor.Red));
}

Layout batch example: The following code horizontally aligns the selected nodes to the selection anchor left side:

C#
Copy Code
// get the active page
NPage activePage = m_DrawingDocument.Content.ActivePage;
// create a new layout batch associated with the specified document
NBatchLayout batchLayout = new NBatchLayout(m_DrawingDocument);
// build it from the active page selection
batchLayout.Build(activePage.Selection.SelectedItems);
// check if all batch nodes can be aligned to the selection anchor
if (batchLayout.CanAlignHorizontally(activePage.Selection.AnchorItem as NShape))
{
    // align the lefts of all batch nodes to the selection anchor left side
    batchLayout.AlignHorizontally(activePage.Selection.AnchorItem as NShape, ENHorizontalAlignment.Left);
}

Translate batch example: The following code translates the selected elements and their translation slaves:

C#
Copy Code
// create a new translate batch associated with the specified document
NBatchTranslate batchTranslate = new NBatchTranslate(m_DrawingDocument);
// build it from the active page selection
batchTranslate.Build(m_DrawingDocument.Content.ActivePage.Selection.SelectedItems);
// check if all batch nodes can be translated with the specified amounts
if (batchTranslate.CanTranslate(10, 10, false))
{
    // translate all batch nodes with the specified amounts
    batchTranslate.Translate(10, 10, false);
}

Transform batch example: The following code rotates the selected models to 90 degrees:

C#
Copy Code
// create a new transform batch associated with the specified document
NBatchTransform batchTransform = new NBatchTransform(m_DrawingDocument);
// build it from the view selection
batchTransform.Build(m_DrawingDocument.Content.ActivePage.Selection.SelectedItems);
// check if all batch nodes can be rotated to 90 degrees
if (batchTransform.CanRotate(90))
{
    // translate all batch nodes with the specified amounts
    batchTransform.Rotate(90);
}

Delete batch example: The following code deletes all selected elements

C#
Copy Code
// create a new delete batch associated with the specified document
NBatchDelete batchDelete = new NBatchDelete(m_DrawingDocument);
// build it from the view selection
batchDelete.Build(m_DrawingDocument.Content.ActivePage.Selection.SelectedItems);
// check if the delete operation can be performed
if (batchDelete.CanDelete())
{
    // delete all batch nodes
    batchDelete.Delete();
}