public static bool TryGetPointFromUser(out Point3d result, bool inWCS, string message, Point3d? point)
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointOptions ppo = new PromptPointOptions("\n" + message);
if (point.HasValue)
{
ppo.BasePoint = point.Value;
ppo.UseBasePoint = true;
}
while (true)
{
PromptPointResult res = ed.GetPoint(ppo);
if (res.Status == PromptStatus.Cancel)
{
result = Point3d.Origin;
return false;
}
else if (res.Status == PromptStatus.OK)
{
result = res.Value;
if (inWCS) result = result.TransformBy(ed.CurrentUserCoordinateSystem);
return true;
}
}
}
public static bool GetObjectInPoint(out List<ObjectId> result, List<Type> types, string message, List<ObjectId> excludes, Point3d? point = null, double? precision = null)
{
result = new List<ObjectId>();
Point3d clickPoint;
while (true)
{
if (point.HasValue) clickPoint = point.Value;
else if (!TryGetPointFromUser(out clickPoint, false, message, null)) return false;
if (precision == null) precision = Tolerance.Global.EqualPoint;
string typeString = "";
foreach (Type type in types)
{
if (type.Equals(typeof(ProxyEntity)))
{
typeString += "ACAD_PROXY_ENTITY,";
continue;
}
typeString += RXClass.GetClass(type).DxfName + ",";
}
if (typeString.Length > 1) typeString = typeString.Substring(0, typeString.Length - 1);
//выбираем типы для множественного выбора
TypedValue[] values = new TypedValue[]
{
new TypedValue((int)DxfCode.Start,typeString)
};
//объявляем фильтр
SelectionFilter filter = new SelectionFilter(values);
//создаем точки для выбора объектов в области
Point3d pt1 = new Point3d(clickPoint.X - precision.Value, clickPoint.Y - precision.Value, 0);
Point3d pt2 = new Point3d(clickPoint.X + precision.Value, clickPoint.Y + precision.Value, 0);
//выбираем объекты в области вокруг выбранной точки
PromptSelectionResult psr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
.MdiActiveDocument.Editor.SelectCrossingWindow(pt1, pt2, filter);
if (psr.Value != null)
{
if (excludes != null) result.AddRange(psr.Value.GetObjectIds().Except(excludes));
else result.AddRange(psr.Value.GetObjectIds());
return true;
}
}
}