public static void CreateUCS(string ucsName, double[] origin, double[] xAxis, double[] yAxis, bool makeCurrent)
{
// Get the current document and database, and start a transaction
Document acDoc = AQME_ACAD.AQMEACADInstance.ActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
using (DocumentLock dl = AQME_ACAD.AQMEACADInstance.ActiveDocument.LockDocument())
{
// Open the UCS table for read
UcsTable acUCSTbl;
acUCSTbl = acTrans.GetObject(acCurDb.UcsTableId, OpenMode.ForWrite) as UcsTable;
UcsTableRecord acUCSTblRec;
// Check to see if the ucsName UCS table record exists
if (acUCSTbl.Has(ucsName) == false)
{
acUCSTblRec
= new UcsTableRecord
(); acUCSTblRec.Name = ucsName;
acUCSTbl.Add(acUCSTblRec);
acTrans.AddNewlyCreatedDBObject(acUCSTblRec, true);
}
else
{
acUCSTblRec = acTrans.GetObject(acUCSTbl[ucsName], OpenMode.ForWrite) as UcsTableRecord;
}
acUCSTblRec
.Origin = new Point3d
(origin
); //calulate vector between two points
Point3d origin1
= new Point3d
(origin
); Point3d xPoint
= new Point3d
(xAxis
); Point3d yPoint
= new Point3d
(yAxis
);
Vector3d vectx = origin1.GetVectorTo(xPoint);
Vector3d vecty = origin1.GetVectorTo(yPoint);
acUCSTblRec.XAxis = vectx;
acUCSTblRec.YAxis = vecty;
acTrans.Commit();
}
}
if (makeCurrent == true)
{
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
using (DocumentLock dl = AQME_ACAD.AQMEACADInstance.ActiveDocument.LockDocument())
{
// Open the UCS table for read
UcsTable acUCSTbl;
acUCSTbl = acTrans.GetObject(acCurDb.UcsTableId, OpenMode.ForWrite) as UcsTable;
UcsTableRecord acUCSTblRec;
// Check to see if the ucsName UCS table record exists
if (acUCSTbl.Has(ucsName) == true)
{
acUCSTblRec = acTrans.GetObject(acUCSTbl[ucsName], OpenMode.ForWrite) as UcsTableRecord;
// call the set tolerances method to set the tolerances.
// Open the active viewport
ViewportTableRecord acVportTblRec;
acVportTblRec = acTrans.GetObject(acDoc.Editor.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;
// Display the UCS Icon at the origin of the current viewport
acVportTblRec.IconAtOrigin = true;
acVportTblRec.IconEnabled = true;
// Set the UCS current
acVportTblRec.SetUcs(acUCSTblRec.ObjectId);
acDoc.Editor.UpdateTiledViewportsFromDatabase();
acTrans.Commit();
}
}
}
}
}