TheSwamp

Code Red => ARX Programming => Topic started by: It's Alive! on October 20, 2008, 06:25:33 PM

Title: How to make a Table in Bricscad
Post by: It's Alive! 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!"));
  }
};