@gosbee30 here is an Editor extension method to get a CogoPoint by selection or by entering the Name or Number of the point:
/// <summary>
/// Allows the user to select a cogo point by picking an item in the drawing or
/// entering the PointName or PointNumber.
/// The cogo point is returned as an ObjectId.
/// </summary>
public static ObjectId SelectCogoPoint(this Editor ed, string prompt)
{
ObjectId result = ObjectId.Null;
PromptEntityOptions entOpts = new PromptEntityOptions(prompt);
entOpts.SetRejectMessage("...not a CogoPoint, try again.");
entOpts.AddAllowedClass(typeof(CogoPoint), true);
entOpts.Keywords.Add("Number");
entOpts.Keywords.Add("nAme");
PromptEntityResult entRes = ed.GetEntity(entOpts);
if(entRes.Status== PromptStatus.Keyword)
{
if (entRes.StringResult == "Number")
{
var intOpts = new PromptIntegerOptions("\n...Point Numner:");
intOpts.AllowNegative = false;
intOpts.AllowZero = false;
var intRes = ed.GetInteger(intOpts);
if (intRes.Status != PromptStatus.OK)
return result;
var points = CivilApplication.ActiveDocument.CogoPoints;
result = points.GetPointByPointNumber((uint)intRes.Value);
}
else if (entRes.StringResult == "nAme")
{
var strOpts = new PromptStringOptions("\n...Point Name:");
var strRes = ed.GetString(strOpts);
if (strRes.Status != PromptStatus.OK || strRes.StringResult == "")
return result;
foreach (ObjectId id in CivilApplication.ActiveDocument.CogoPoints)
{
using (var pt = (CogoPoint)id.Open(OpenMode.ForRead))
{
if (pt.PointName == strRes.StringResult)
{
result = id;
pt.Close();
break;
}
pt.Close();
}
}
}
}
else if (entRes.Status == PromptStatus.OK)
result = entRes.ObjectId;
return result;
}
And here is an extension method for reading UDPs
/// <summary>
/// Method to get the string value of any PointUDP, useful for writing values out to text files
/// </summary>
/// <param name="pt"></param>
/// <param name="udp"></param>
/// <returns></returns>
public static string GetUDPValue(this CogoPoint pt, SettingsRoot sr, UDP udp)
{
string retVal = "";
if (udp == null)
return retVal;
object val = null;
try
{
val = pt.GetUDPValue((UDPDouble)udp);
retVal = sr.FormatDistance((double)val);
}
catch { }
try
{
val = pt.GetUDPValue((UDPBoolean)udp);
retVal = val.ToString();
}
catch { }
try
{
val = pt.GetUDPValue((UDPInteger)udp);
retVal = val.ToString();
}
catch { }
try
{
val = pt.GetUDPValue((UDPString)udp);
retVal = val.ToString();
}
catch { }
try
{
val = pt.GetUDPValue((UDPEnumeration)udp);
retVal = val.ToString(); ;
}
catch { }
return retVal;
}