public static Field GetFieldInText(ObjectId acObjId)
{
Field field = null;
try
{
// Get the current document and database, and start a transaction
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.
MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Get the current document editor
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.
MdiActiveDocument.Editor;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table record for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for read
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForRead) as BlockTableRecord;
using (DBText text = acTrans.GetObject(acObjId, OpenMode.ForWrite) as DBText)
{
string str = text.TextString;
if (text.HasFields)
{
ObjectId FieldId = text.GetField();
field = acTrans.GetObject(FieldId, OpenMode.ForRead) as Field;
if (field != null && field.HyperLink != null)
{
string hyperLink = field.HyperLink.Description;
}
}
}
}
return field;
}
catch (System.Exception e)
{
Editor acDocEd = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
acDocEd.WriteMessage(String.Format("Ошибка. {0}{1}" + Environment.NewLine, e.Message, e.StackTrace));
return field;
}
}