Use AcDbField::getFieldCode() to get the field codes used in MText

By Philippe Leefsma

Q:

I need to get the Field Codes from MText entities. I tried using AcDbMText::explodeFragments() and AcDbMText::contents() but these functions return the value of the evaluated text.  Is there a way to get the control codes?

A:

The AcDbObject::getField() function with AcDbField::getFieldCode() provide a means to get the FieldCodes used in MText.

This example iterates through model space and displays the FieldCode of MText entities:

void AdnGetFieldCodes()

{

        AcDbDatabase * pDb =

            acdbHostApplicationServices()->workingDatabase();

        AcDbBlockTable * blkTbl;

  

        pDb->getBlockTable(blkTbl, AcDb::kForRead);

        AcDbBlockTableRecord * blkTblRec;

        AcDbObjectId * pObjId;

  

        blkTbl->getAt(ACDB_MODEL_SPACE, blkTblRec, AcDb::kForRead);

        blkTbl->close();

  

        AcDbBlockTableRecordIterator* pIterator;

        if (blkTblRec->newIterator(pIterator) == Acad::eOk)

        {

                AcDbEntity* pEntity;

                while (!pIterator->done())

                {

                     pIterator->getEntity(pEntity, AcDb::kForRead);

 

                     if (pEntity->isA() == AcDbMText::desc())

                     {

                         AcDbMText *pt = (AcDbMText *) pEntity;

                         AcDbField * pField;

                         const ACHAR* pFcode = L"TEXT";

     

                         Acad::ErrorStatus es =

                             pt->getField(pFcode, pField, AcDb::kForRead);

 

                         if (es != Acad::eOk)

                         {

                             acutPrintf(L"\n%s", acadErrorStatusText(es));

                             pIterator->step();

                             continue;

&#160
;                       
}

 

                         ACHAR* pszFieldCode;

                         pField->getFieldCode(

                             pszFieldCode,

                             AcDbField::kAddMarkers);

     

                         acutPrintf(L"\n%s",pszFieldCode);

                         delete pszFieldCode;

        

                         pField->close();

                     }

 

                     pEntity->close();

                     pIterator->step();

                }

        }

 

        delete pIterator;

        blkTblRec->close();

}

<

p style=”line-height: normal;margin: 0in 0in 0pt” class=”MsoNormal”> 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading