I noticed something when creating a new block reference in a drawing.
I thought I should be able to append the new blockReference to the blockTableRecord of that name, but it creates a duplicate block table record.
So appending the reference to the modelspace blocktablerecord works as expected but isn't the block reference owned by the blocktable record of that name?
I have both ways shown in the code below for an example.
//check for existence of block record.
ObjectId bid = ObjectId.Null;
bid = table[blkName];
//if record exists.
if (!bid.IsNull)
{
BlockTableRecord btr = (BlockTableRecord)transaction.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockTableRecord WBAY = (BlockTableRecord)transaction.GetObject(bid, OpenMode.ForWrite);
//check for references in drawing.
ObjectIdCollection oidc = WBAY.GetBlockReferenceIds(false, false);
//if there are no existing references in the drawing.
if (oidc.Count == 0)
{
//get scale information.
ZoomToExtents(document);
double vwsize = System.Convert.ToDouble(AcadApp.GetSystemVariable("VIEWSIZE"));
ZoomToPercent(document);
BlockReference bref = new BlockReference(Point3d.Origin, bid); //add new reference to database @ 0,0,0.
> btr.AppendEntity(bref); //if I use the modelspace tablerecord, everything is fine.
> WBAY.AppendEntity(bref); //if I use the blocktablerecord of that name, it creates a circular (duplicate) block record(with not good results).
transaction.AddNewlyCreatedDBObject(bref, true);