using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; //using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; [assembly: CommandClass (typeof(gw.Class1ofgw))] namespace gw { public class Class1ofgw { //画一个圆 [CommandMethod("KCircle")] public void huayuan() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acDd = acDoc.Database; using (Transaction acTrans=acDd.TransactionManager.StartTransaction()) { BlockTable acBlkTbl = (BlockTable)acTrans.GetObject(acDd.BlockTableId, OpenMode.ForRead); BlockTableRecord acBlkTblRec = (BlockTableRecord)acTrans.GetObject((acBlkTbl[BlockTableRecord.ModelSpace]), OpenMode.ForWrite); BlockTableRecord[] acBlkTblRecs=new BlockTableRecord[100]; int i; i = 0; foreach (ObjectId rec in acBlkTbl) { acBlkTblRecs=(BlockTableRecord)acTrans.GetObject(rec, OpenMode.ForRead); i++; } //Circle acCir = new Circle(); //acCir.SetDatabaseDefaults(); //acCir.Center = new Point3d(1, 1, 0); //acCir.Diameter = 100; //acBlkTblRec.AppendEntity(acCir); //acTrans.AddNewlyCreatedDBObject(acCir, true); //acTrans.Commit(); } } } }
我用acBlkTblRecs数组来记录acBlkTbl 中的每一个BlockTableRecord 我在图形中手工加入了一个块定义b1(只有一个圆),还在模型空间中画了一个圆,但是执行后我发现acBlkTblRecs只有4个成员 他们的base.name分别是*Model_Space,*PaperSpace,*PaperSpace0,b1,前面3个的layout属性都是ture。怎么没有那个圆所属的BlockTableRecord呢? 还有,我想查看b1中所有的图形定义,怎么查看呢?难道是通过acBlkTblRecs【3】,也就是b1的BlockBeginID,BlockEndID? 谢谢! |