Message 1 of 18
c# block insert
Not applicable
08-23-2006
10:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can anybody help me
Can anybody help me, the following source code doesn't work and I understand
not what is the error.
[CommandMethod("AsdkCmd1")]
static public void test()
{
string comp = "d:\temp\test.dwg";
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Transaction tr = doc.TransactionManager.StartTransaction();
try
{
string dwgName =
HostApplicationServices.Current.FindFile(comp,acadApp.DocumentManager.MdiActiveDocument.Database,FindFileHint.Default);
Database db = new Database(false, false);
db.ReadDwgFile(dwgName,System.IO.FileShare.Read, true, "");
ObjectId NewBlkId = new ObjectId();
NewBlkId = doc.Database.Insert(dwgName, db, false);
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId,
OpenMode.ForRead,true);
BlockTableRecord btr
=(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
BlockReference bref = new BlockReference(new
Autodesk.AutoCAD.Geometry.Point3d(10,10,0), NewBlkId);
btr.AppendEntity(bref);
tr.AddNewlyCreatedDBObject(bref, true);
tr.Commit();
}
finally
{
tr.Dispose();
}
}
Best regards and thanks
Ernst
Can anybody help me, the following source code doesn't work and I understand
not what is the error.
[CommandMethod("AsdkCmd1")]
static public void test()
{
string comp = "d:\temp\test.dwg";
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Transaction tr = doc.TransactionManager.StartTransaction();
try
{
string dwgName =
HostApplicationServices.Current.FindFile(comp,acadApp.DocumentManager.MdiActiveDocument.Database,FindFileHint.Default);
Database db = new Database(false, false);
db.ReadDwgFile(dwgName,System.IO.FileShare.Read, true, "");
ObjectId NewBlkId = new ObjectId();
NewBlkId = doc.Database.Insert(dwgName, db, false);
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId,
OpenMode.ForRead,true);
BlockTableRecord btr
=(BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
BlockReference bref = new BlockReference(new
Autodesk.AutoCAD.Geometry.Point3d(10,10,0), NewBlkId);
btr.AppendEntity(bref);
tr.AddNewlyCreatedDBObject(bref, true);
tr.Commit();
}
finally
{
tr.Dispose();
}
}
Best regards and thanks
Ernst