Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Adding and Naming Linetypes

To create a new linetype, declare a variable of the OdDbLinetypeTableRecordPtr type and use the pseudo-constructor of the linetype record object. This pseudo-constructor is the static method that creates a new dynamic linetype instance and returns a smart pointer to it. For example:


OdDbLinetypeTableRecordPtr pLinetype = OdDbLinetypeTableRecord::createObject();

The created instance exists independently from the database. Many properties of the linetype record object are invalid and the linetype instance does not get an ID until the linetype is added in the database. The linetype table object cannot manipulat the new linetype without the OdDbObjectId instance associated with the created linetype record object. The new linetype instance gets an empty name by default. The linetype table object cannot identify a linetype without a name. Therefore, after creating, the program must assign a name for the new linetype, and then, must add it in the linetype table of the database.

The linetype name is an arbitrary nonempty string that can be up to 255 characters long and can contain letters, digits, blank spaces, underscores, and some special characters, but cannot contain inadmissible letters (see Naming objects). The database contains three predefined linetypes whose names are fixed: "ByLayer", "ByBlock", and "Continuous". The linetype record object has the getName() method for getting the name and the setName() method for setting the name.

To get the name, use the getName() method of the linetype record object; it does not have arguments and returns the linetype name as an OdString value. For example:


OdString sName = pLinetype->getName();
odPrintConsoleString(L"\nLinetype has the name: %s", sName.c_str());

To set the name, use the setName() method of the linetype record object; it requires the name as a nonempty OdString value and does not return a value. For example:


pLinetype->setName("NewLinetypeX");

If the linetype name contains inadmissible letters, the setName() method generates the exception: «37 - Invalid Symbol Table name». If the linetype name is an empty string, the setName() method generates the exception: «106 - Empty Record name».

To add the linetype in the linetype table, use the add() method of the linetype table object; it requires one argument — the pointer to the linetype instance to be added — and returns the OdDbObjectId instance associated with the added linetype record object. In the example below, the pLinetypes variable stores a pointer to the linetype table object. For example:


OdDbObjectId idLinetype = pLinetypes->add(pLinetype);

If the linetype table already contains a linetype with the same name as the new name, the add() and setName() methods generate the exception: «104 - Duplicate Record name object [10]». The exception message contains the handle of the duplicate linetype in the square brackets. To check whether the linetype table contains the linetype with the specified name, use the has() method of the linetype table object.

To catch exceptions, use the try … catch statement when the program adds the linetype record object in the table. The following example demonstrates the procedure:


void NewLinetype(OdString sLinetypeName, OdDbLinetypeTablePtr pLinetypes)
{
  if(sLinetypeName.isEmpty())

    odPrintConsoleString(L"\nThe linetype name is undefined\n");

  else if(sLinetypeName.findOneOf("<>/\\\":;?,|=`") != -1)

    odPrintConsoleString(L"\nThe linetype name contains inadmissible letters\n");

  else if(pLinetypes->has(sLinetypeName))

    odPrintConsoleString(L"\nThe linetype with name \"%s\" already exists\n", sLinetypeName.c_str());

  else
  {
    OdDbLinetypeTableRecordPtr pLinetype = OdDbLinetypeTableRecord::createObject();

    try {
      pLinetype->setName(sLinetypeName);
      pLinetypes->add(pLinetype);
    }
    catch(OdError& e)
    {
      odPrintConsoleString(L"\nError: %d - %ls\n", e.code(), e.description());
      pLinetype->erase();
    }
  }
}

See Also

Working with Linetypes

Getting and Checking Linetypes

Deleting and Recovering Linetypes

Example of Working with the Linetype Table Object

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