Product : Converter, Version : 4.0.4.1023, ArticleID : 41022247

HowTo : Blocks with same name

Article41022247
TypeHowTo
ProductConverter
Version4.0.4.1023
Date Added9/19/2003
Submitted byHans BERENDE
Keywords

Subject

Blocks with same name

Summary

We have a couple of thousand dxf files containing parts of our products. We use VectorDraw to assemble these parts to a drawing of a product.
 The most convenient way to handle single parts is to load them as blocks. 
 I have been using axVDPro.ActiveDocument.Blocks.AddFromFile() to do so.
 I guess this works without a problem when using VDF files, however, DXF files more often than not cause problems when they contain block definitions themselves...
 What happens is that the block appear in the block list twice: once with the filename (without path and extention, from now on referred to as Name1) and once with the internal blockname as specified inside the DXF file (from now on referred to as Name2). 
 Erasing Block Name1 does not affect the picture, however, erasing block Name2 does! The block, formally named Name1 (according to property vdBlock.Name) is erased istead! Furthermore, if a second DXF file is loaded carrying a block named Name2 too, problems arize: depending on the Redefine setting of vdBlocks.AddFromFile either the first or the second block gets lost.
 
 I would like to have the possibility to import one or more blocks from a DXF file keeping the names of the blocks as the are defined inside the file. An event may be fired when a block name already exists, giving the application programmer the opportunity to either 1) rename the new block, or 2) to replcace the existing block by the current one or 3) to cancel loading the current block.
 
 Would it be possible to solve the described problem in a satisfying way???
 
 Regards,
 Hans BERENDE.

Solution

The only thing you can do is to check the import drawing ( example : hare.dxf ) in another control before you insert it in drawing.

For example in your code add another VectorDraw Professional and named axVDPro1.

Before insert the new drawing/block check if the blocks for double names.
If you find, then rename the new block in the second control.
Check all blocks then save to a temporary file and then insert the temporary file.

Code:

   axVDPro1.ActiveDocument.Open ("..\\..\\hare.dxf", 0, 0);

   string NewName, OldName;
   VDProLib.vdBlock Block = axVDPro1.ActiveDocument.Blocks.Start;
   while (Block != null)
   {
    if ( (Block.Name != "VDDIM_DEFAULT") && (Block.Name != "VDDIM_NONE") )
     if ( axVDPro.ActiveDocument.Blocks.FindName ( Block.Name ) != null ) //RENAME BLOCK
     {
      OldName = Block.Name;
      NewName = axVDPro1.ActiveDocument.FileName + "-" + Block.Name;
      Block.Name = NewName;
      

            // Check for inserts within the block.
      VDProLib.vdFigure Fig = Block.Start;
      while ( Fig != null )
      {
       if ( Fig.Type == "VDINSERT")
        if (((VDProLib.vdInsert)Fig).BlockName == OldName ) ((VDProLib.vdInsert)Fig).BlockName = NewName;
       Fig = Block.Next;
      }

            // Check for inserts within the entities.
      Fig = axVDPro1.ActiveDocument.Entities.Start;
      while ( Fig != null )
      {
       if ( Fig.Type == "VDINSERT")
        if (((VDProLib.vdInsert)Fig).BlockName == OldName ) ((VDProLib.vdInsert)Fig).BlockName = NewName;
       Fig = axVDPro1.ActiveDocument.Entities.Next;
      }
     }
    Block = axVDPro1.ActiveDocument.Blocks.Next;
   }
   

   axVDPro1.ActiveDocument.SaveAs ("..\\..\\temp1234.vdf", VDProLib.VdConstFileVer.Vd4x4 );

   axVDPro.ActiveDocument.Blocks.AddFromFile( "..\\..\\temp1234.vdf", true );
   axVDPro.CommandAction.CmdInsertBlockDialog ();
   axVDPro.CommandAction.Zoom ("E", 0,0);