Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Working with Database Containers > Working with Predefined Tables of Named Records > Basics of Predefined Tables of Named Records > Example of Selecting a Predefined Table Object
Example of Selecting a Predefined Table Object

This example demonstrates selecting a predefined table object from the database object. The SelectDatabasePredefinedTable() function requires one argument — the pointer to the database object from which the predefined table must be obtained — and returns the OdDbObjectId instance associated with the predefined table object selected by the user or returns an OdDb::kNull instance if the user cancels selection.

The SelectDatabasePredefinedTable() function organizes the loop in which it displays the list of predefined tables of the specified database, inquires about the operation code associated with a table, and uses the switch statement to select whether the case must be performed. The function uses methods of the database object to get the Object ID of the selected table. When the user selects the [U] operation, the function gets the Object ID of the UCS table object using the getUCSTableId() method. When the user selects the [V] operation, the function gets the Object ID of the view table object using the getViewTableId() method. When the user selects the [B] operation, the function gets the Object ID of the block table object using the getBlockTableId() method. When the user selects the [L] operation, the function gets the Object ID of the layer table object using the getLayerTableId() method. When the user selects the [T] operation, the function gets the Object ID of the linetype table object using the getLinetypeTableId() method. When the user selects the [P] operation, the function gets the Object ID of the viewport table object using the getViewportTableId() method. When the user selects the [S] operation, the function gets the Object ID of the text style table object using the getTextStyleTableId() method. When the user selects the [D] operation, the function gets the Object ID of the dimension style table object using the getDimStyleTableId() method. When the user selects the [R] operation, the function gets the Object ID of the registered application table object using the getRegAppTableId() method. When the user selects the [Q] operation, the function breaks the loop and sets the Object ID to kNull. If the user enters another operation code, the function repeats the loop.

The SelectDatabasePredefinedTable() function has the following implementation:


OdDbObjectId SelectDatabasePredefinedTable(OdDbDatabase* pDb)
{
  wchar_t ch;

  do {
    wcout << L"\nThe predefined tables:"
          << L"\nU. UCSs table"
          << L"\nV. Views table"
          << L"\nB. Blocks table"
          << L"\nL. Layers table"
          << L"\nT. lineTypes table"
          << L"\nP. viewPorts table"
          << L"\nS. text Styles table"
          << L"\nD. Dimension styles table"
          << L"\nR. Reg-applications table"
          << L"\nQ. Quit (cancel)";
    wcout << L"\nSelect the operation:>";
    wcin >> ch;

    switch(ch)
    {
      case L'U':
      case L'u':  return pDb->getUCSTableId();

      case L'V':
      case L'v':  return pDb->getViewTableId();

      case L'B':
      case L'b':  return pDb->getBlockTableId();

      case L'L':
      case L'l':  return pDb->getLayerTableId();

      case L'T':
      case L't':  return pDb->getLinetypeTableId();

      case L'P':
      case L'p':  return pDb->getViewportTableId();

      case L'S':
      case L's':  return pDb->getTextStyleTableId();

      case L'D':
      case L'd':  return pDb->getDimStyleTableId();

      case L'R':
      case L'r':  return pDb->getRegAppTableId();

      case L'Q':
      case L'q':  return (OdDbObjectId::kNull);

      default:    wcout << L"Incorrect operation\n";
    }
  } 
  while(1);

  return (OdDbObjectId::kNull);
}

The following example demonstrates listing records for the predefined table. The PrintTableRecords() function requires one argument — the pointer to the predefined table object whose content must be printed — and does not return a value. To display the list of records, the function creates the iterator using the newIterator() method, moves the iterator to the next record using the step() method, checks whether the traversing is completed using the done() method, and gets the handle and name of the current record object using the getRecordId(), getHandle(), getName(), and getRecord() methods.

The PrintDictionaryObjects() function has the following implementation:


void PrintTableRecords(OdDbSymbolTable* pTable)
{
  OdDbSymbolTableIteratorPtr itRecord;

  wcout << L"\nThe list of " << pTable->isA()->name().mid(4, pTable->isA()->name().find(L"Table")-4) + L" objects";

  for(itRecord = pTable->newIterator() ; !itRecord->done() ; itRecord->step())
  {
    wcout << L"\n" << itRecord->getRecordId().getHandle().ascii() 
          << L"-\"" << itRecord->getRecord()->getName() << L"\"";
  }
  itRecord = NULL;
}

The DemoBase() function tests the SelectDatabasePredefinedTable() and PrintTableRecords() functions. The DemoBase() function requires a pointer to the database object and organizes the loop in which it calls the SelectDatabasePredefinedTable() function for selecting a predefined table. If the returned Object ID is not null, the function gets the pointer to the predefined table object, calls the PrintTableRecords() function, and passes it the pointer to the obtained predefined table for listing its records.

The DemoBase() function has the following implementation:


void DemoBase(OdDbDatabase* pDb)
{
  OdDbObjectId idTable;
  
  wcout << L"Start testing";
  do {
    idTable = SelectDatabasePredefinedTable(pDb);
    if(idTable.isNull()) break;
    PrintTableRecords((OdDbSymbolTable*) idTable.safeOpenObject().get());
  } 
  while(1);
  wcout << L"Stop testing";
}

Testing gives the following results:


Start testing
The predefined tables:
U. UCSs table
V. Views table
B. Blocks table
L. Layers table
T. lineTypes table
P. viewPorts table
S. text Styles table
D. Dimension styles table
R. Reg-applications table
Q. Quit (cancel)
Select the operation:>B

The list of Block objects
1F-"*Model_Space"
1B-"*Paper_Space"
23-"*Paper_Space0"

Select the operation:>T

The list of Linetype objects
14-"ByBlock"
15-"ByLayer"
16-"Continuous"

Select the operation:>Y
Incorrect operation

Select the operation:>Q
Stop testing 

The SelectDatabasePredefinedTable()function is used in the documented examples that require selecting a predefined table.

See Also

Collecting Database Objects using Predefined Tables of Named Records

Specific Classes of Predefined Table Objects

Specific Classes of Named Record Objects

Example of Using the Record-Table Interface for Selecting Objects

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.