Hi,
The easy way is to call the _UCS command.
[CommandMethod("TEST1")]
public static void Test1()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var peo = new PromptEntityOptions("\nSelect Polyline: ");
peo.SetRejectMessage("\nSelected object is not a Polyline.");
peo.AddAllowedClass(typeof(Polyline), true);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
ed.Command("_.ucs", "_object", per.ObjectId);
}
But you can also mimic the native command by computing the Matrix3d.
[CommandMethod("TEST2")]
public static void Test2()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var peo = new PromptEntityOptions("\nSelect Polyline: ");
peo.SetRejectMessage("\nSelected object is not a Polyline.");
peo.AddAllowedClass(typeof(Polyline), true);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
var origin = pline.StartPoint;
var xAxis = pline.GetFirstDerivative(pline.StartParam);
var zAxis = pline.Normal;
var yAxis = zAxis.CrossProduct(xAxis).GetNormal();
var ocs = Matrix3d.AlignCoordinateSystem(
Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
origin, xAxis, yAxis, zAxis);
ed.CurrentUserCoordinateSystem = ocs;
tr.Commit();
}
}