REdefine an existing block ekeynotfound

REdefine an existing block ekeynotfound

GeeHaa
Collaborator Collaborator
542 Views
3 Replies
Message 1 of 4

REdefine an existing block ekeynotfound

GeeHaa
Collaborator
Collaborator

Hi

I'm trying to redefine an existing block in a drawing and I'm getting an ekeynotfound message when trying the currDBase .insert method. ConnName  is the drawing name with the full path and txb_blockname.text has the existing blockname with no extension.  Can someone tell me what I'm doing wrong? It looks like it should work.

 

Thanks,

G

Using mytrans As Transaction = CurrDBase.TransactionManager.StartTransaction
 Using mydb As Database = New Database(False, True)                                
  mydb.ReadDwgFile(ConnName, FileOpenMode.OpenForReadAndReadShare, True, "")
  Dim insConnsDEFid As ObjectId = currDBase.Insert(ConnName, _ 
       TXB_BlockName.Text, mydb, True)
   mydb.CloseInput(True)
  End Using
  mytrans.Commit()
End Using

 

0 Likes
Accepted solutions (1)
543 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor
Accepted solution

I guess the reason you use the rarely used overload Insert(string, string, Database, bool) method, instead of most commonly used Insert(string, Database, bool), is to "redefine" a block definition in the current drawing.

 

However, are you sure the overloaded Insert(string, string,...) is the one you (or anyone) want to use? According to .NET API document on this method:

 

<QUOTE>

This function creates a new block table record in the database executing this function. This new block table record is given the name pointed to by destinationBlockName. Then, each entity in the block table record whose name is sourceBlockName and which resides in the database pointed to by dataBase is copied into the new block table record.

</QUOTE>

 

That means, not only a new block definition with "destinationBlockName" is created from the inserted block file, all entities in an existing block definition names as sourceBlockName" would also copied to the newly created block definition (i.e. you get a new block definition with 2 sets of entities combined). I really do not see why someone wants to do things in this odd way by code.

 

If your purpose is to update/redefine an existing block from a block DWG file, you simply use the overloaded Insert(string, database, bool). If the passed block name already exists, this method simply redefine the block with inserted block file; if not, a new block definition is created.

 

Even you does intentionally use Insert(string, string, database, bool) with fully understanding what it does, your code is still problematic: you use full file path as the block name (variable ConnName, which, I suppose,  should be a fully pathed file name, because you used it in ReadDwgFile() method). In current database, there could not be a block with that name., not to mention a fully pathed file name contains invalid characteres to be used as symbol name. You should parse the full path into a valid block name, like:

 

Dim blkName As String = System.IO.Path.GetFileNameWithoutExtension(ConnName)

....Insert(blockName, TXB_BlockName.Text, ...)

 

Again, in most cases, using Insert(string, Database, bool) is the usual way to force block definition redefine.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4

GeeHaa
Collaborator
Collaborator

Thanks for the thorough reply.

Where do I find the API Documents?

0 Likes
Message 4 of 4

GeeHaa
Collaborator
Collaborator

Never mind They are  the  CHM files in  the objectarx folders on my c drive. I always forget to look there first.

Thanks Again.

0 Likes