60000432 I want a way to search the Document for inserts that have a certain Block.

Article 60000432
Type HowTo
Product Engine
Date Added 2/26/2008 12:00:00 AM
Fixed (2/26/2008 12:00:00 AM)
Submitted by Peter Chanios

Summary

I want a way to search the whole Document for inserts that have a certain Block.

Solution

You can try a code like :


vdFramedControl.BaseControl.ActiveDocument.Prompt("Block name to search:");
string blockname = vdFramedControl.BaseControl.ActiveDocument.ActionUtility.getUserString();
vdFramedControl.BaseControl.ActiveDocument.Prompt(
null);
if (blockname == null) return;
vdBlock blk = vdFramedControl.BaseControl.ActiveDocument.Blocks.FindName(blockname);
if (blk == null) return;

//search all vdPrimaries that are document register with handle != 0
vdSelection set = new vdSelection();//create a selection to hold the items
vdPrimariesList list = vdFramedControl.BaseControl.ActiveDocument.GetPrimaries(true);
foreach (vdPrimary var in list)
{
vdInsert test = var as vdInsert;
if (test == null) continue;
if (!object.ReferenceEquals(test.Block, blk)) continue;
set.AddItem(test,
false, vdSelection.AddItemCheck.Nochecking);
}

Send comments on this topic.