- 积分
- 223
- 明经币
- 个
- 注册时间
- 2005-12-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
public class Testinsert { [CommandMethod("testinsert")] static public void DoIt() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptResult res = ed.GetString("Give me a file to insert"); if (res.Status != PromptStatus.OK) return; string fname = res.StringResult; if (!File.Exists(fname)) fname = HostApplicationServices.Current.FindFile(fname, doc.Database, FindFileHint.Default); using (Database db = new Database(false, false)) { //read drawing db.ReadDwgFile(fname, FileShare.Read, true, null); using (Transaction t = doc.TransactionManager.StartTransaction()) { //insert it as a new block ObjectId idBTR = doc.Database.Insert("test", db, false); //create a ref to the block BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); using (BlockReference bref = new BlockReference(Point3d.Origin, idBTR)) { btr.AppendEntity(bref); t.AddNewlyCreatedDBObject(bref, true); } t.Commit(); } } } }
|
|