Author Topic: How to make a Table in Bricscad  (Read 1868 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6934
  • AKA Daniel
How to make a Table in Bricscad
« on: October 20, 2008, 06:25:33 PM »
Even though Bricscad does not support tables, the ODA libraries do, so it is possible to add a table to the DWG through DRX.  Bricscad will draw it as a block.


Code: [Select]
//++-- A sample Command class...Daniel Marcotte
class CommandAddTable : public OdStaticRxObject<OdEdCommand>
{
public:
  const OdString localName() const {return globalName();}
  const OdString groupName() const {return DD_T("DRXGLOBAL");}
  const OdString globalName() const {return DD_T("AddTable");}

  void execute(OdEdCommandContext* pCmdCtx)
  {
    ASSERT(pCmdCtx != NULL);
    if(pCmdCtx == NULL)
      return;

    OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
    OdDbUserIOPtr pDbIO = pDbCmdCtx->dbUserIO();
    OdDbDatabasePtr pDb = pDbCmdCtx->database();
    if(pDb.isNull())
      return;

    //++--
    OdGePoint3d startPt = pDbIO->getPoint(DD_T("Get Point"));

    //++-- Here we use the method ::createObject() instead of new.
    OdDbTablePtr pNewTable = OdDbTable::createObject();
    if(pNewTable.isNull())
      return;

    //++-- This sets the defaults such as layer ...
    pNewTable->setDatabaseDefaults(pDb);
    pNewTable->setPosition(startPt);

    pNewTable->setNumColumns(5);
    pNewTable->setNumRows(5);

    //++-- you need to do this
    pNewTable->generateLayout();

    //++-- merge the top row
    pNewTable->mergeCells(0,0,0,4);
    pNewTable->setTextString(0,0,DD_T("Does this work"));

    double textHeight = pDb->getTEXTSIZE();

    pNewTable->setRowHeight(textHeight);
    pNewTable->setColumnWidth(textHeight * 15);
   
    //++-- Get the modelspace ID
    OdDbObjectId spaceId = pDb->getModelSpaceId();
    if(spaceId.isNull())
      return;

    //++-- Open the BTR for write
    OdDbBlockTableRecordPtr pBtr = spaceId.openObject(OdDb::kForWrite);
    if(pBtr.isNull())
      return;

    //++-- add the table
    pBtr->appendOdDbEntity(pNewTable);
    pDbIO->putString(_T("\nDone!"));
  }
};