try
{
using (db)
{
db.ReadDwgFile(@"-------.dwg", FileOpenMode.OpenForReadAndAllShare, false, null);
db.CloseInput(true);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference br;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
foreach (ObjectId id in btr)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
if (ent is Line)
{
Line line = (Line)ent;
if (line.Handle.ToString() == "3D5")
{
Point3d linePt = new Point3d();
linePt = line.StartPoint;
ed.WriteMessage(linePt.ToString());
ObjectId brId = ObjectId.Null;
string blockFile = @"--------.dwg";
string blockName = Path.GetFileNameWithoutExtension(blockFile);
using (Database tempDb = new Database(false, true))
{
tempDb.ReadDwgFile(blockFile, FileShare.Read, true, null);
brId = db.Insert(blockName, tempDb, false);
tempDb.Dispose();
br = new BlockReference(linePt, brId);
//tr.AddNewlyCreatedDBObject(br, true);
}
}
}
}
tr.Commit();
}
db.SaveAs(@"----------.dwg", DwgVersion.Current);
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.ToString());
}
The link you have provided is only for entities. But I am looking for block references, where in I have to consider the insertion point and the name.
Thanks
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
if (ent is BlockReference)
{
BlockReference bref = (BlockReference)tr.GetObject(ent.ObjectId, OpenMode.ForRead);