Error adding new block to imageViewer

  • 1.5K Views
  • Last Post 10 December 2015
Andres Muñoz posted this 10 December 2015

Hello,

I want to do the following:
1) Select various regions of the image with mouse (some gray blocks are created)
2) Store the gray blocks (via Layout.VisualBlocks)
3) Use imgViewer.Commands.DoCommand(MenuItemEnum.MI_ReadBlock, true); for recognising the selected area/region of image (gray blocks are removed as a result)
4) Create the gray blocks again (using the stored ones)

But when I do the 4th step, I get an exception (Arguments check failed. Expected: isValidBlockType) What am I doing wrong?

This is the code:


for (var i = 0; i < FrDocument.Pages[0].Layout.VisualBlocks.Count; i++)
          lstRegionesAgregar.Add(FrDocument.Pages[0].Layout.VisualBlocks.Region);//I assume that the block is BlockTypeEnum.BT_AutoAnalysis
imgViewer.Commands.DoCommand(MenuItemEnum.MI_ReadBlock, true);
foreach (var regionAgregar in lstRegionesAgregar)
{
    var regBloque = AbbyyEngineLoader.Engine.CreateRegion();
    regBloque.AddRect(regionAgregar.Left[0], regionAgregar.Top[0], regionAgregar.Right[0], regionAgregar.Bottom[0]);
     FrDocument
        .Pages[0]
        .Layout
        .VisualBlocks
        .AddNew(BlockTypeEnum.BT_AutoAnalysis, regBloque);// <==== ArgumentException is thrown here 
}
imgViewer.Invalidate(true); 

Order By: Standard | Newest | Votes
Oksana Serdyuk posted this 10 December 2015

Hi Andres,

The ArgumentException is thrown because the AddNew method of the LayoutBlocks object cannot contain the following block types: BT_AutoAnalysis, BT_Separator, BT_SeparatorGroup. Please see the description of this method in Developer’s Help for more details. As soon as you change the block type to any of the allowed values, the code will work.

Andres Muñoz posted this 10 December 2015

Thanks, I though I could create a "BlockTypeEnum.BT_AutoAnalysis" block.

Close