Exemple #1
0
        /// <summary>
        /// 创建一个新的UCS
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="UCSName">要创建的UCS名称</param>
        /// <returns>返回创建的UCS的Id</returns>
        public static ObjectId AddUCS(this Database db, string UCSName)
        {
            var trans = db.TransactionManager;
            //打开UCS表
            UcsTable ut = (UcsTable)trans.GetObject(db.UcsTableId, OpenMode.ForRead);

            if (!ut.Has(UCSName))//如果不存在名为UCSName的UCS,则新建一个UCS
            {
                //定义一个新的UCS
                UcsTableRecord utr = new UcsTableRecord();
                utr.Name = UCSName; //设置UCS名
                ut.UpgradeOpen();   //切换UCS表的状态为写以添加新的UCS
                //将UCS的信息添加到UCS表中
                ut.Add(utr);
                //把UCS添加到事务处理中
                trans.AddNewlyCreatedDBObject(utr, true);
                ut.DowngradeOpen(); //为了安全,将UCS表的状态切换为读
            }
            return(ut[UCSName]);    //返回新添加的UCS的ObjectId
        }
Exemple #2
0
        public void Test()
        {
            Document document = Application.DocumentManager.MdiActiveDocument;
            Editor   ed       = document.Editor;
            Matrix3d mt       = ed.CurrentUserCoordinateSystem;
            Point3d  basePt   = new Point3d(1000, 1000, 0);
            Vector3d vecX     = new Vector3d(100, 100, 0);
            Vector3d vecY     = vecX.GetPerpendicularVector();

            using (Transaction trans = document.TransactionManager.StartTransaction())
            {
                UcsTable       ut  = trans.GetObject(document.Database.UcsTableId, OpenMode.ForRead) as UcsTable;
                UcsTableRecord utr = new UcsTableRecord();
                utr.Name   = "TestUcs";
                utr.Origin = basePt;
                utr.XAxis  = vecX;
                utr.XAxis  = vecY;
                ut.UpgradeOpen();
                ut.Add(utr);
                ut.DowngradeOpen();
                trans.AddNewlyCreatedDBObject(utr, true);
                trans.Commit();
            }
        }