Message 1 of 6
Nobody seems to have solved the insert block problem
Not applicable
08-10-2005
04:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi again (I know, I post like crazy. Sorry!),
There have been many threads about inserting a block (WBLOCKed as a .dwg
file) into a drawing, but the final post in each thread is always the same -
they result in a fatal error. Has anyone solved this problem? The method
that all of the attempts suggest is along these lines:
Document doc=Application.DocumentManager.MdiActiveDocument;
string fname = "PathAndFilenameOfBlockFile";
HostApplicationServices.Current.FindFile(fname, doc.Database,
FindFileHint.Default);
using(Database db = new Database(false, false))
{
db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null);
using(Transaction t = doc.TransactionManager.StartTransaction())
{
ObjectId idBTR = doc.Database.Insert("BlockName",db,false);
BlockTable bt = (BlockTable)t.GetObject
(doc.Database.BlockTableId,
OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)t.GetObject
(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Point3d origin = new Point3d(0, 0, 0);
using(BlockReference bref = new BlockReference(origin, idBTR))
{
btr.AppendEntity(bref);
t.TransactionManager.AddNewlyCreatedDBObject(bref, true);
}
t.Commit();
t.Dispose();
}
}
The fatal error is:
Unhandled Access Violation Reading 0xfffffff Exception
at 7ef399f9h
Thanks,
Carlos
There have been many threads about inserting a block (WBLOCKed as a .dwg
file) into a drawing, but the final post in each thread is always the same -
they result in a fatal error. Has anyone solved this problem? The method
that all of the attempts suggest is along these lines:
Document doc=Application.DocumentManager.MdiActiveDocument;
string fname = "PathAndFilenameOfBlockFile";
HostApplicationServices.Current.FindFile(fname, doc.Database,
FindFileHint.Default);
using(Database db = new Database(false, false))
{
db.ReadDwgFile(fname, System.IO.FileShare.Read, true, null);
using(Transaction t = doc.TransactionManager.StartTransaction())
{
ObjectId idBTR = doc.Database.Insert("BlockName",db,false);
BlockTable bt = (BlockTable)t.GetObject
(doc.Database.BlockTableId,
OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)t.GetObject
(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Point3d origin = new Point3d(0, 0, 0);
using(BlockReference bref = new BlockReference(origin, idBTR))
{
btr.AppendEntity(bref);
t.TransactionManager.AddNewlyCreatedDBObject(bref, true);
}
t.Commit();
t.Dispose();
}
}
The fatal error is:
Unhandled Access Violation Reading 0xfffffff Exception
at 7ef399f9h
Thanks,
Carlos