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);

 

转载于:https://www.cnblogs.com/edata/p/10718731.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值