不要返回值,改一个,其余类似 [CommandMethod("CB")] public void CreateBlock() { Database db = HostApplicationServices.WorkingDatabase; ObjectId blockId = ObjectId.Null;//用于返回所创建的块的对象Id BlockTableRecord record = new BlockTableRecord();//创建一个BlockTableRecord类的对象,表示所要创建的块 record.Name = "Room";//设置块名 using (Transaction trans = db.TransactionManager.StartTransaction()) { Point3dCollection points = new Point3dCollection();//用于表示组成块的多段线的顶点 points.Add(new Point3d(-18.0, -6.0, 0.0)); points.Add(new Point3d(18.0, -6.0, 0.0)); points.Add(new Point3d(18.0, 6.0, 0.0)); points.Add(new Point3d(-18.0, 6.0, 0.0)); Polyline2d pline = new Polyline2d(Poly2dType.SimplePoly, points, 0.0, true, 0.0, 0.0, null);//创建组成块的多段线 record.Origin = points[3];//设置块的基点 record.AppendEntity(pline);//将多段线加入到新建的BlockTableRecord对象 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);//以写的方式打开块表 if (!bt.Has("Room"))//判断是否存在名为"Room"的块 { blockId = bt.Add(record);//在块表中加入"Room"块 trans.AddNewlyCreatedDBObject(record, true);//通知事务处理 trans.Commit();//提交事务 } } //return blockId;//返回创建的块的对象Id }
|