Message 1 of 7
how to copy block from an unopened docment?
Not applicable
07-15-2005
06:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried many times and use several method to copy a block in an unopened file to current document. com method is ok,but net arx method always failed .who can help me and post a sample of net arx.
the following is my code of arx method
private static ObjectId GetBlockArx(string blockFile, String name )
{
ObjectId block = ObjectId.Null;
Database db = new Database();
db.ReadDwgFile(blockFile, System.IO.FileShare.Read, false, null);
ArrayList list = new ArrayList();
Transaction dbTrans = db.TransactionManager.StartTransaction();
try
{
BlockTable dbbt = dbTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord dbBtr = dbTrans.GetObject(dbbt[name], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId entId in dbBtr)
{
Entity ent = dbTrans.GetObject(entId, OpenMode.ForRead) as Entity;
Entity newEnt = ent.Clone() as Entity;
list.Add(newEnt);
}
dbTrans.Commit();
}
finally
{
dbTrans.Dispose();
db.Dispose();
}
Transaction trans = Arx.Tm.StartTransaction();
try
{
BlockTable bt = trans.GetObject(Arx.Db.BlockTableId, OpenMode.ForWrite) as BlockTable;
foreach (ObjectId idd in bt)
{
BlockTableRecord btrr = trans.GetObject(idd, OpenMode.ForWrite) as BlockTableRecord;
if (btrr.Name.ToUpper() == name.ToUpper())
{
btrr.Erase();
}
}
BlockTableRecord newBtr = new BlockTableRecord();
newBtr.Name = name;
block = bt.Add(newBtr);
trans.AddNewlyCreatedDBObject(newBtr, true);
foreach (object obj in list)
{
newBtr.AppendEntity(obj as Entity);
trans.AddNewlyCreatedDBObject(obj as Entity, true);
}
foreach (ObjectId nentId in newBtr)
{
Entity nent = trans.GetObject(nentId, OpenMode.ForRead) as Entity;
}
trans.Commit(); // a fatal error here
}
finally { trans.Dispose(); }
return block;
}
the following is my code of arx method
private static ObjectId GetBlockArx(string blockFile, String name )
{
ObjectId block = ObjectId.Null;
Database db = new Database();
db.ReadDwgFile(blockFile, System.IO.FileShare.Read, false, null);
ArrayList list = new ArrayList();
Transaction dbTrans = db.TransactionManager.StartTransaction();
try
{
BlockTable dbbt = dbTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord dbBtr = dbTrans.GetObject(dbbt[name], OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId entId in dbBtr)
{
Entity ent = dbTrans.GetObject(entId, OpenMode.ForRead) as Entity;
Entity newEnt = ent.Clone() as Entity;
list.Add(newEnt);
}
dbTrans.Commit();
}
finally
{
dbTrans.Dispose();
db.Dispose();
}
Transaction trans = Arx.Tm.StartTransaction();
try
{
BlockTable bt = trans.GetObject(Arx.Db.BlockTableId, OpenMode.ForWrite) as BlockTable;
foreach (ObjectId idd in bt)
{
BlockTableRecord btrr = trans.GetObject(idd, OpenMode.ForWrite) as BlockTableRecord;
if (btrr.Name.ToUpper() == name.ToUpper())
{
btrr.Erase();
}
}
BlockTableRecord newBtr = new BlockTableRecord();
newBtr.Name = name;
block = bt.Add(newBtr);
trans.AddNewlyCreatedDBObject(newBtr, true);
foreach (object obj in list)
{
newBtr.AppendEntity(obj as Entity);
trans.AddNewlyCreatedDBObject(obj as Entity, true);
}
foreach (ObjectId nentId in newBtr)
{
Entity nent = trans.GetObject(nentId, OpenMode.ForRead) as Entity;
}
trans.Commit(); // a fatal error here
}
finally { trans.Dispose(); }
return block;
}