DuplicateRecordCloning.Replace exception "eHandleExists"

DuplicateRecordCloning.Replace exception "eHandleExists"

richardpangburn
Enthusiast Enthusiast
345 Views
0 Replies
Message 1 of 1

DuplicateRecordCloning.Replace exception "eHandleExists"

richardpangburn
Enthusiast
Enthusiast

EDIT:

 

I think I realized the problem. It seems you cannot copy the exact same object from the source drawing into the destination drawing more than once. You CAN have a block with the same name in the destination drawing, however.

 

Using the replace DuplicateRecordCloning.Replace enumeration will replace the block table record with the clone. However, if you try to copy the exact same clone object from the exact same source drawing into the exact same destination drawing again, you get the eHandleExists error because the clone object and the previously cloned object have the exact same name and handle.

 

It seems the problem wasn't with my code itself, but with what I was trying to do, and not understanding what "Replace" was doing.

 

I'll leave my question below just incase it helps anyone else out there.

 

Hi,

 

I am writing a program that allows users to select a host drawing and a set of destination drawings and specify a block. The program will look into the source drawing for that blocktablerecord and I use the wblockcloneobjects() method to grab the block and insert it into the list of other drawings.


This is working fine, except in the case where the blocktablerecord already exists in the destination drawing. In this situation I allow my users a radio button to replace the block in the destination drawing with the clone from the source drawing:

 

 

 

 

 

if (replaceDuplicate == true)
{
//replace the existing block in the destination drawing and insert the clone
sourceDatabase.WblockCloneObjects(objectIdCollection, destinationDatabase.BlockTableId, map, DuplicateRecordCloning.Replace, false);
}

 

 

 

 

 

The help doc API says this about the Replace enumeration on DuplicateRecordCloning:

 

If a duplicate is found, replace it with the cloned record. 

 

This seems straightforward enough, but when I test this, I receive an exception "eHandleExists" which I take it to mean the replace function is not exactly doing what is says, or more likely, I've made a mistake in the way I've structured my method. EDIT: I've shortened my problem code down to the area where it's throwing the exception and tried to make it a little easier to read. 

 

 

 

 using (Database destinationDatabase = new Database(true, true))
{                                destinationDatabase.ReadDwgFile(destinationFilePath, FileOpenMode.OpenForReadAndWriteNoShare, false, null);
destinationDatabase.CloseInput(true);
HostApplicationServices.WorkingDatabase = destinationDatabase;

using (Transaction destinationTransaction1 = destinationDatabase.TransactionManager.StartTransaction())
{
BlockTable destinationBlockTable = destinationTransaction1.GetObject(destinationDatabase.BlockTableId, OpenMode.ForWrite) as BlockTable;
if (destinationBlockTable.Has(blockName))
{

if (replaceDuplicate == true)
{
IdMapping map = new IdMapping();
                                                sourceDatabase.WblockCloneObjects(objectIdCollection, destinationDatabase.BlockTableId, map, DuplicateRecordCloning.Replace, false); //THE CODE CRASHES ON THIS LINE WITH 'eHandleExists'
}

if (newReferenceOnDuplicate == true)
{
//ignore will discard the clone and insert a new reference of the existing block already in the target drawing
IdMapping map = new IdMapping();
                                                sourceDatabase.WblockCloneObjects(objectIdCollection, destinationDatabase.BlockTableId, map, DuplicateRecordCloning.Ignore, false);
}

if (doNothingDuplicate == true)
{
//If the user chooses to do nothing....
return;
}
}
else
{
IdMapping map = new IdMapping();
                                            sourceDatabase.WblockCloneObjects(objectIdCollection, destinationDatabase.BlockTableId, map, DuplicateRecordCloning.Replace, false);
}
destinationTransaction1.Commit();
}
                       
//after this I do the block reference insertion in the destination db, then I save it.
                                    destinationDatabase.SaveAs(destinationFilePath, true, DwgVersion.Current, thisDrawing.Database.SecurityParameters);

 

 

 

Any help would be appreciated.

 

 

 

 

 

346 Views
0 Replies
Replies (0)