Hi,
I'm trying to copy a particular block in a drawing opened in side database, and paste it at equal distances n times. Here's my code:
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());
}
Unfortunately, it doesn't work. Please help.
Thanks