AcDbTable表格实体的简单例子

例子是创建一个含有表格实体的块定义

效果如下(手动插入的块)

源代码如下,简单示意,采用了我不是很熟悉的智能指针创建实体对象,代码仅供参考

AcDbObjectPointer<AcDbTable> pTable;
        Acad::ErrorStatus es= pTable.create();
        if (Acad::eOk != es)
            return;

        AcDbDictionary *pDict = NULL;
        AcDbObjectId idTblStyle;
        acdbHostApplicationServices()->workingDatabase()->getTableStyleDictionary(pDict,AcDb::kForRead);
        pDict->getAt(_T("Standard"),idTblStyle);
        pDict->close();
        pTable->setTableStyle( idTblStyle );

        AcDbTextStyleTable* pTextStyle = NULL;
        acdbHostApplicationServices()->workingDatabase()->getTextStyleTable(pTextStyle,AcDb::kForRead);
        AcDbObjectId textID;
        pTextStyle->getAt(_T("Standard"),textID);
        pTextStyle->close();
        if( !textID.isNull() )
        {
            pTable->setTextStyle(textID);
        }

        pTable->setNumColumns(3);
        pTable->setNumRows(8);
        pTable->generateLayout(); 
        pTable->suppressHeaderRow(false);//禁用表头
        //定义插入点
        pTable->setPosition(AcGePoint3d(100,100, 0));
        //定义行高
        pTable->setRowHeight(0,30);
        pTable->setRowHeight(1,5);
        pTable->setRowHeight(2,5);
        pTable->setRowHeight(3,5);
//         pTable->setRowHeight(4,5);
//         pTable->setRowHeight(5,5);
//         pTable->setRowHeight(6,5);
//         pTable->setRowHeight(7,5);
        //定义列宽
        pTable->setColumnWidth(0,45);
        pTable->setColumnWidth(1,40);
        pTable->setTextString(1,1,_T("sfsfsdfsd"));
        pTable->setAutoScale(1,1,true);
        //重新计算表格块,在添加到块定义的时候(也许后台数据库也需要),需要重新计算
        //表格样式id一定要给
        pTable->recomputeTableBlock();
        pTable->setRegen();

        AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase();
        if (NULL == pDb) 
            return;
        AcDbBlockTablePointer pTbl(pDb,AcDb::kForWrite);
        if (Acad::eOk != pTbl.openStatus())
            return;
//         AcDbBlockTableRecordPointer pModelSpace(ACDB_MODEL_SPACE,pDb,AcDb::kForWrite);
//         if (Acad::eOk != pModelSpace.openStatus())
//             return;        
        AcDbBlockTableRecordPointer pBlkRcd;
        if (Acad::eOk != pBlkRcd.create())
            return;
        pBlkRcd->setName(_T("智能指针创建的块"));
        AcDbObjectId objId=AcDbObjectId::kNull;
        pBlkRcd->appendAcDbEntity(objId,pTable);        
        pTbl->add(pBlkRcd);

 

posted @ 2019-04-16 17:51  edata  阅读(1407)  评论(0编辑  收藏  举报