As you may already know, linetype definition in AutoCAD consists of series of values representing the pattern and can include text and shapes. Here is a sample code to iterate the linetypes loaded in the database and display the definition. In case of embedded shapes, a preview of the shape is created by adding an AcDbShape to the modelspace.
Acad::ErrorStatus es;
double previewOffset = 5.0;
AcGePoint3d pos = AcGePoint3d::kOrigin;
AcApDocument *pActiveDoc
= acDocManager->mdiActiveDocument();
AcDbDatabase *pDB = pActiveDoc->database();
AcDbLinetypeTable* pLineTypeTable = NULL;
if ( pDB->getLinetypeTable(
pLineTypeTable, AcDb::kForRead) != Acad::eOk)
return ;
es = acDocManager->lockDocument(pActiveDoc);
AcDbBlockTableRecordPointer
pMS(ACDB_MODEL_SPACE, pDB, AcDb::kForWrite);
AcDbLinetypeTableIterator* pIter = NULL;
es = pLineTypeTable->newIterator( pIter);
es = pLineTypeTable->close();
for (;! pIter->done(); pIter->step())
{
AcDbLinetypeTableRecord* pLinetype = NULL;
if ( pIter->getRecord( pLinetype,
AcDb::kForRead) == Acad::eOk)
{
const ACHAR *pLinetypeName = NULL;
es = pLinetype->getName(pLinetypeName);
acutPrintf(_T("\\nLinetype : %s" ),
pLinetypeName);
for ( int dash = 0; dash <
pLinetype->numDashes(); ++dash)
{
int shapeNumber
= pLinetype->shapeNumberAt(dash);
double dashLen
= pLinetype->dashLengthAt(dash);
AcDbObjectId objIdShape
(pLinetype->shapeStyleAt( dash));
if ( objIdShape == AcDbObjectId::kNull)
{
const ACHAR *pText = NULL;
es = pLinetype->textAt(dash, pText);
if (pText == NULL)
acutPrintf(_T("\\nDash : %d DashLen : %lf" ),
dash, dashLen);
else
acutPrintf(_T("\\nDash : %d Text : %s" ),
dash, pText);
continue ;
}
// Shape involved, lets preview it...
AcDbObject* pObject = NULL;
es = acdbOpenAcDbObject(
pObject, objIdShape, AcDb::kForRead);
AcDbTextStyleTableRecord* pTextSyleTableRec
= AcDbTextStyleTableRecord::cast( pObject);
Adesk::Boolean isShapeFile
= pTextSyleTableRec->isShapeFile();
if (isShapeFile)
{
// Create a preview of the shape
AcDbShape *pShape = new AcDbShape
(AcGePoint3d::kOrigin, 1.0);
if ( pShape->setShapeNumber(shapeNumber)
!= Acad::eOk ||
pShape->setStyleId(objIdShape)
!= Acad::eOk)
{
delete pShape;
pShape = NULL;
}
if (pShape)
{
es = pShape->setWidthFactor(1.0);
AcDbObjectId id;
es = pMS->appendAcDbEntity(id, pShape);
es = pShape->setPosition(pos);
pos +=
AcGeVector3d::kXAxis * previewOffset;
es = pShape->setSize(1);
es = pShape->setRotation(0);
es=pShape->close();
const ACHAR *pShapeFileName = NULL;
Acad::ErrorStatus es
= pTextSyleTableRec->fileName
(pShapeFileName);
acutPrintf(_T("\\nDash : %d
ShapeNumber : %d
ShapeName : %s
ShapeFile : %s"),
dash, shapeNumber,
pShape->name(), pShapeFileName);
}
}
else
{
const ACHAR *pText = NULL;
es = pLinetype->textAt(dash, pText);
acutPrintf(_T("\\nDash : %d Text : %s" ),
dash, pText);
}
pObject->close();
}
pLinetype->close();
}
}
delete pIter;
es = acDocManager->unlockDocument(pActiveDoc);
The output generated by this code snippet is as seen in this screenshot :