I have no time to test this for now.
Points obtained through Editor.GetPoint are always in UCS.
If the picked point has to participate into some geometry creation or calculation, it has to be transformed from its UCS to WCS since all AutoCAD geometry information is stored in WCS.
Look at the example below:
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointResult ppr = ed.GetPoint("\nSpecify base point: ");
if (ppr.Status != PromptStatus.OK) return;
// point in UCS
Point3d ucsPt = ppr.Value;
// point in WCS
Point3d wcsPt = ucsPt.TransformBy(ed.CurrentUserCoordinateSystem);
Try:
private ObjectId SelectPolyline(out Point3d pickPoint)
{
pickPoint = Point3d.Origin;
var opt = new PromptEntityOptions("\nSelect a polyline:");
opt.SetRejectMessage("\nInvalid: not a polyline!");
opt.AddAllowedClass(typeof(CadDb.Polyline), true);
var res = _ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
{
using (var tran = res.ObjectId.Database.TransactionManager.StartTransaction())
{
var poly = (CadDb.Polyline)tran.GetObject(res.ObjectId, OpenMode.ForRead);
//make sure the output point is on the polyline
//pickPoint = poly.GetClosestPointTo(res.PickedPoint, false);
// from UCS to WCS
pickPoint = poly.GetClosestPointTo(res.PickedPoint.TransformBy(_ed.CurrentUserCoordinateSystem), false);
tran.Commit();
}
return res.ObjectId;
}
else
{
return ObjectId.Null;
}
}
private bool SelectTwoPointsOnPolyline(ObjectId polyId, Point3d prevPoint, out Point3d startPt, out Point3d endPt)
{
startPt = Point3d.Origin;
endPt = Point3d.Origin;
_firstPoint = prevPoint;
var nextPoint = Point3d.Origin;
_polylineId = polyId;
bool ok = false;
using (var tran = _dwg.TransactionManager.StartTransaction())
{
var poly = (CadDb.Polyline)tran.GetObject(polyId, OpenMode.ForRead);
while (true)
{
ClearGhostPolyline();
var opt = new PromptPointOptions("\nSelect second point on the polyline:")
{
AppendKeywordsToMessage = true,
AllowNone = true
};
opt.Keywords.Add("First point");
opt.Keywords.Default = "First point";
PromptPointResult res;
try
{
// when selecting another point on polyline
// show the part of polyline to be cloned
// as Transient Graphics
_ed.PointMonitor += Editor_PointMonitor;
res = _ed.GetPoint(opt);
}
finally
{
_ed.PointMonitor -= Editor_PointMonitor;
ClearGhostPolyline();
}
if (res.Status == PromptStatus.OK)
{
//nextPoint = poly.GetClosestPointTo(res.Value, false);
// from UCS to WCS
nextPoint = poly.GetClosestPointTo(res.Value.TransformBy(_ed.CurrentUserCoordinateSystem), false);
ok = true;
break;
}
else if (res.Status == PromptStatus.Keyword)
{
// re-select the first point on polyline
var cancel = false;
while (true)
{
var op = new PromptPointOptions("\nSelect first point on polyline:");
var rs = _ed.GetPoint(op);
if (rs.Status == PromptStatus.OK)
{
//_firstPoint = poly.GetClosestPointTo(rs.Value, false);
// from UCS to WCS
_firstPoint = poly.GetClosestPointTo(rs.Value.TransformBy(_ed.CurrentUserCoordinateSystem), false);
break;
}
else
{
cancel = true;
break;
}
}
if (cancel)
{
ok = false;
break;
}
}
else
{
ok = false;
break;
}
}
if (ok)
{
SortPickedPoints(poly, _firstPoint, nextPoint, out startPt, out endPt);
}
tran.Commit();
}
return ok;
}
If I haven't forgotten something I think it should work.