> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IBatchItems

> IBatchItems は、documentsやページの並べ替えに使用する Move メソッドを備えた IBatchItem 要素のコレクションで、set-assembly のサンプルスクリプトも含まれます。

<div id="what-it-is">
  ## 概要
</div>

[IBatchItem](/ja/flexi-capture/appendix/scripts/i-batch-item) のコレクションです。

<Note>
  このオブジェクトは、ルールをローカルでチェックする目的では Web Verification Station では利用できません。
</Note>

<div id="methods">
  ## メソッド
</div>

<table width="100%"><thead><tr><th style={{textAlign: 'left'}}><p><strong>定義</strong></p></th><th style={{textAlign: 'left'}}><p><strong>説明</strong></p></th></tr></thead><tbody><tr><td><p>Move(item : <a href="/ja/flexi-capture/appendix/scripts/i-batch-item">IBatchItem</a>, position : int)</p></td><td><p>要素をコレクション内の指定した位置に移動します。</p><p><strong>注: </strong>このメソッドは、要素を移動する先のコレクションに対して呼び出します。</p><p><strong>注: </strong><code>position</code>パラメーターには、0 からコレクションのサイズまでの値を指定できます。</p></td></tr></tbody></table>

<div id="properties">
  ## プロパティ
</div>

| **名前** | **型** | **アクセス** | **説明**       |
| ------ | ----- | -------- | ------------ |
| Count  | int   | 読み取り専用   | コレクション内の要素の数 |

<div id="example-of-the-move-method">
  ## Move メソッドの例
</div>

このスクリプトは、未分類のドキュメントリストからセットをアセンブルするために、一連のシナリオを順に実行します。

* セットを分解する
* 指定した順序で、ドキュメントを型ごとにグループ化する
* 指定したキーフィールドごとにドキュメントをグループ化する
* 同じキーフィールドを持つドキュメントをセットにアセンブルする

```csharp theme={null}
using System.Collections.Generic;
IBatchItems batch = Batch.AsBatchItem.ChildItems;
List<string> docDefs = new List<string> {"DocSet","Doc1","Doc2"}; // ドキュメントのアセンブリ順序
// キーフィールド名
// （すべてのドキュメントでインデックス化され、同じ名前である必要があります）
string keyFieldName = "SSN";
List<string> keyFields = new List<string>();
// セットの分解
bool foundChildren = false;
do
{
    foreach (IBatchItem itm in batch)
    {
        if (itm.ChildItems.Count > 1)
        {
            int shift = 0;
            foreach (IBatchItem subItm in itm.ChildItems)
            {
                shift++;
                batch.Move(subItm, itm.Index + shift);
            }
        }
    }
    foreach (IBatchItem itm in batch)
        if (itm.ChildItems.Count > 1)
            foundChildren = true;
} while (foundChildren);
// セット内の正しい順序にドキュメントを並べ替える
// （セット自体の後にすべてのサブドキュメントが続く順序）
foreach (string docDefName in docDefs)
{
    List<int> indexList = new List<int>();
    foreach (IBatchItem itm in batch)
        if (itm.Type == TBatchItemType.BIT_Document)
            if (itm.AsDocument.DefinitionName == docDefName) indexList.Add(itm.Index);
    for (int i = 0; i < indexList.Count; i++)
        batch.Move(batch[indexList[i]-i], batch.Count);
}
// バッチ内のキーフィールドの値をすべて検索する
foreach (IBatchItem itm in batch)
{
    if (itm.Type == TBatchItemType.BIT_Document)
    {
        string keyFieldValue = (string)itm.AsDocument.IndexedItemValue(keyFieldName);
        if (!keyFields.Contains(keyFieldValue))
            keyFields.Add(keyFieldValue);
    }
}
// 同じキーフィールドを持つドキュメントをアセンブルする
foreach (string keyFieldValue in keyFields)
{
    List<int> indexList = new List<int>();
    foreach (IBatchItem itm in batch)
        if (itm.Type == TBatchItemType.BIT_Document)
            if ((string)itm.AsDocument.IndexedItemValue(keyFieldName) == keyFieldValue) indexList.Add(itm.Index);
    for (int i = 0; i < indexList.Count; i++)
        batch.Move(batch[indexList[i]-i], batch.Count);
}
// キーフィールドが一致する場合にのみサブドキュメントをセットに移動する
// （セットのセクションを先に、子ドキュメントを後に）
int ind = 0;
while (ind < batch.Count)
{
    if (batch[ind].Type == TBatchItemType.BIT_Document)
        // セットの先頭を検索する
        if (batch[ind].AsDocument.DefinitionName == docDefs[0])
            // セットの後のドキュメントがセットでなく、キーフィールドが一致する場合、
            // そのドキュメントをこのセットに追加する
            while (ind+1 < batch.Count &&
                   batch[ind+1].AsDocument.DefinitionName != docDefs[0] &&
                   (string)batch[ind+1].AsDocument.IndexedItemValue(keyFieldName) == (string)batch[ind].AsDocument.IndexedItemValue(keyFieldName))
                batch[ind].ChildItems.Move(batch[ind+1], batch[ind].ChildItems.Count);
    ind++;
}
```
