Community

Error adding new block to imageViewer

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

0

Comments

2 comments

  • Avatar
    Oksana Serdyuk

    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.

    0
  • Avatar
    Andres Muñoz

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

    0

Please sign in to leave a comment.