Working on a coordinate export program to export the xyz coordinates of all block references with attributes to a csv file.
I thought everything was cool until I encountered a 'strange' occurance.
db = Acdb.HostApplicationServices.WorkingDatabase
tr = (db.TransactionManager.StartTransaction())
openMode = AcDb.OpenMode.ForRead
public static IEnumerable<AcDb.BlockReference> GetBlockReferencesByName(AcDb.Database db, AcDb.Transaction tr, AcDb.OpenMode openMode, string blockName)
{
List<AcDb.BlockReference> brlist = new List<AcDb.BlockReference>();
AcDb.BlockTable bt = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
try {
if (!bt.Has(blockName)) {
throw new AcRx.Exception(AcRx.ErrorStatus.InvalidBlockName);
}
AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(bt.Item(blockName), AcDb.OpenMode.ForRead);
foreach (AcDb.ObjectId oid in btr.GetBlockReferenceIds(true, false)) {
AcDb.BlockReference br = (AcDb.BlockReference)tr.GetObject(oid, openMode);
brlist.Add(br);
}
return brlist;
}
catch (AcRx.Exception ex) {
AcAp.Application.ShowAlertDialog(ex.Message);
}
return brlist;
}
This code is supposed to return all blockreferences of a given name contained in the working database. Which it does!
For a test, copy a number of blocks from a drawing using copybase
Start a new drawing and pasteorig or something
The program, when executed on this new drawing picks up two blocktables, i think - the one in memory and the newly created objects. Odd.
I know I am missing some part of this? Any ideas?