请关注云幽学院的视频课程

时间:2022-05-16 02:52:03

3、添加圆的例子(完整源代码请加云幽学院免费课)

 

[CommandMethod("MKCircle")]
        public void MKCircle()
        {
            //(1)获取当前勾当图形数据库
            Database db = HostApplicationServices.WorkingDatabase;
            //(2)新建一个circle东西 
            Point3d cenPt = new Point3d(0, 100, 0); //圆心
            Circle cir= new Circle(cenPt, Vector3d.ZAxis, 100);
      
            //(3)界说一个指向当前数据库的事务措置惩罚惩罚,,以添加直线
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //(3-1)以读方法打开块表..
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);

//(3-2)以写方法打开模型空间块表记录
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

//(3-3)将图形东西的信息添加到块表记录中,并返回ObjectId东西.
                btr.AppendEntity(cir);

//(3-4)把东西添加到事务措置惩罚惩罚中.
                trans.AddNewlyCreatedDBObject(cir, true);

//(3-5)提交事务措置惩罚惩罚
                trans.Commit();
            }
        }

这个例子非常简单,想学习AutoCAD二次开发(c#、C++等语言)、BIM软件二次开发、Java、python等在线课程的同学,请存眷云幽学院的视频课程。