public static void NewUCS()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (DocumentLock acLckDoc = doc.LockDocument())// Lock the document
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
UcsTable ut = trans.GetObject(db.UcsTableId, OpenMode.ForRead) as UcsTable;
UcsTableRecord utr;
if (ut.Has("New_UCS") == false) //返回true,如果表中包含一个ObjectID与id匹配的记录。
{
utr = new UcsTableRecord();
utr.Name = "New_UCS";
ut.UpgradeOpen();//升级读写等级
ut.Add(utr);
trans.AddNewlyCreatedDBObject(utr, true);//添加或删除to the transaction是否成功
}
else
{
utr = trans.GetObject(ut["New_UCS"], OpenMode.ForWrite) as UcsTableRecord;
}
//指定原点
PromptPointOptions pPtOpts = new PromptPointOptions("\n指定原点");
PromptPointResult pPtRes = ed.GetPoint(pPtOpts);
if (pPtRes.Status == PromptStatus.OK)
{
utr.Origin = pPtRes.Value;
}
trans.Commit();
}
}
}