The CogoPoint object on Civil 3D can hold labels with more information than the regular Description, which contains only part of the information (and sometimes not the same showed on the point).
One alternative could be the CogoPoint.GetLabelTextComponentOverride method, passing the IDs obtained from. Unfortunately this will output the format of the text, as shown on the Text Component Editor, not the actual value.
So one workaround, although not very elegant, can be explode the CogoPoint in memory, then explode again and again all the containing BlockReference and MText objects, to end up with DBText, which is the information we seek. The following code show the idea.
[CommandMethod("getPointText")]
public void CmdGetPointText()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult resPoint = ed.GetEntity("Select point: ");
if (resPoint.Status != PromptStatus.OK) return;
ed.WriteMessage(GetText(resPoint.ObjectId));
}
private string GetText(ObjectId id)
{
// store the DBTexts
StringBuilder entityText = new StringBuilder();
Database db = Application.DocumentManager.
MdiActiveDocument.Database;
using (Transaction trans = db.
TransactionManager.StartTransaction())
{
// open the entity
Entity point = trans.GetObject(id,
OpenMode.ForRead) as Entity;
// do a full explode (considering explode again
// all BlockReferences and MText)
List<DBObject> objs = FullExplode(point);
foreach (Entity ent in objs)
{
// now get the text of each DBText
if (ent.GetType() == typeof(DBText))
{
DBText text = ent as DBText;
entityText.AppendLine(text.TextString);
}
}
trans.Commit();
}
return entityText.ToString();
}
private List<DBObject> FullExplode(Entity ent)
{
// final result
List<DBObject> fullList = new List<DBObject>();
// explode the entity
DBObjectCollection explodedObjects = new DBObjectCollection();
ent.Explode(explodedObjects);
foreach (Entity explodedObj in explodedObjects)
{
// if the exploded entity is a blockref or mtext
// then explode again
if (explodedObj.GetType() == typeof(BlockReference) ||
explodedObj.GetType() == typeof(MText))
{
fullList.AddRange(FullExplode(explodedObj));
}
else
fullList.Add(explodedObj);
}
return fullList;
}