Nevron .NET Vision Documentation
Batches

Batches serve as a functionality layer between the DOM and views. They generally help you apply a uniform operation to a set of elements. All types of batches derive from the base NBatch abstract class. Some batch operations are constrained by permissions (see Abilities, Protection and Permissions for more information). The batches are defined in the Nevron.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 elements, 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.

Where applicable batch methods can contain a rollbackOnFail argument, which indicates whether the entire transaction must be rolled back, if the batch operation failed for a single node.

Following is a brief description of the currently available batches:

Batch class Description
NBatchAction Provides miscellaneous transaction based operations, which are not constrained by permissions and purely rely on the interfaces implemented by the batch nodes
NBatchCompose Facilitate the composition of shapes (e.g. the creating of a NCompositeShape from the primitives of other shapes)
NBatchDecompose Facilitate the decomposition of shapes (e.g. the creation of a primitive shape wrapper for the primitives of other shapes)
NBatchDelete Facilitate the deletion of multiple elements
NBatchFormat Facilitate format operations for styleable elements
NBatchGroup Facilitate the grouping of shapes (e.g. the creation of a new group from a set of shapes)
NBatchInsert Facilitate the insertion of multiple elements in one composite
NBatchLayout Provides transaction based layout operations. Currently implements common alignment, resize, horizontal spacing, vertical spacing and center in document operations.
NBatchReorder Facilitates the reorder of elements in their containers (e.g. Z-Order)
NBatchTransform Facilitates transformation based operations on a set of models
NBatchTranslate Facilitates the translation of multiple elements together with their translation slaves
NBatchUngroup 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(document);

// build it from the view selection
batchFormat.Build(view.Selection.Nodes);

// check if the style of all batch nodes can be changed
if (batchFormat.CanChangeStyle(true))
{
        // set red fill style to all batch nodes
        batchFormat.ChangeFillStyle(new NColorFillStyle(Color.Red), true);
}
Visual Basic
Copy Code
' create a new format batch associated with the specified document
Dim batchFormat As New NBatchFormat(document)

' build it from the view selection
batchFormat.Build(view.Selection.Nodes)

' check if the style of all batch nodes can be changed
If (batchFormat.CanChangeStyle(True)) Then
        ' set red fill style to all batch nodes
        batchFormat.ChangeFillStyle(New NColorFillStyle(Color.Red), True)
End If

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

C#
Copy Code
// create a new layout batch associated with the specified document
NBatchLayout batchLayout = new NBatchLayout(document);

// build it from the view selection
batchLayout.Build(view.Selection.Nodes);

// check if all batch nodes can be aligned to the selection anchor
if (batchLayout.CanAlignHorizontally(view.Selection.AnchorNode, true))
{
        // align the lefts of all batch nodes to the selection anchor left side
        batchLayout.AlignHorizontally(view.Selection.AnchorNode, HorzAlign.Left, true);
}
Visual Basic
Copy Code
' create a new layout batch associated with the specified document
Dim batchLayout As New NBatchLayout(document) 

' build it from the view selection
batchLayout.Build(view.Selection.Nodes)

' check if all batch nodes can be aligned to the selection anchor
If (batchLayout.CanAlignHorizontally(view.Selection.AnchorNode, True)) Then
        ' align the lefts of all batch nodes to the selection anchor left side
        batchLayout.AlignHorizontally(view.Selection.AnchorNode, HorzAlign.Left, True)
End If

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(document);

// build it from the view selection
batchTranslate.Build(view.Selection.Nodes);

// check if all batch nodes can be translated with the specified amounts
if (batchTranslate.CanTranslate(10, 10, false, true))
{
        // translate all batch nodes with the specified amounts
        batchTranslate.Translate(10, 10, false, true);
}
Visual Basic
Copy Code
' create a new translate batch associated with the specified document
Dim batchTranslate As New NBatchTranslate(document)

' build it from the view selection
batchTranslate.Build(view.Selection.Nodes)

' check if all batch nodes can be translated with the specified amounts
If (batchTranslate.CanTranslate(10, 10, False, True)) Then
        ' translate all batch nodes with the specified amounts
        batchTranslate.Translate(10, 10, False, True)
End If

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(document);

// build it from the view selection
batchTransform.Build(view.Selection.Nodes);

// check if all batch nodes can be rotated to 90 degrees
if (batchTransform.CanRotate(90, true))
{
        // translate all batch nodes with the specified amounts
        batchTransform.Rotate(90, true);
}
Visual Basic
Copy Code
' create a new transform batch associated with the specified document
Dim batchTransform As New NBatchTransform(document)

' build it from the view selection
batchTransform.Build(view.Selection.Nodes)

' check if all batch nodes can be rotated to 90 degrees
If (batchTransform.CanRotate(90, True)) Then
        ' translate all batch nodes with the specified amounts
        batchTransform.Rotate(90, True)
End If

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(document);

// build it from the view selection
batchDelete.Build(view.Selection.Nodes);

// check if the delete operation can be performed
if (batchDelete.CanDelete(true))
{
        ' delete all batch nodes
        batchDelete.Delete(true);
}
Visual Basic
Copy Code
' create a new delete batch associated with the specified document
Dim batchDelete As New NBatchDelete(document)

' build it from the view selection
batchDelete.Build(view.Selection.Nodes)

' check if the delete operation can be performed
If (batchDelete.CanDelete(True)) Then
        ' delete all batch nodes
        batchDelete.Delete(True)
End If
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback