Built-In Parameters of Elements in Teigha BIM

Ivan Serbinovsky

August 02, 2018

Elements in Teigha BIM can have built-in parameters. To get all of the built-in parameters of an element, you can use this method:

void getListParams(OdBuiltInParamArray& aParams) const;

Each class that has parameters implements the method and adds its parameters in an array. The class is also responsible for the values of parameters if it adds them, and it must process a parameter if accessed for its value.

As commonly known, there is a set of methods for getting a parameter’s value:

OdResult getParam(const OdBm::BuiltInParameter::Enum& parameterId, double& value) const;
OdResult getParam(const OdBm::BuiltInParameter::Enum& parameterId, OdInt32& value) const;
OdResult getParam(const OdBm::BuiltInParameter::Enum& parameterId, OdString& value) const;
OdResult getParam(const OdBm::BuiltInParameter::Enum& parameterId, OdBmObjectId& value) const;

If you do not know the type of the value, you need to use the most common method:

OdResult getParam(const OdBm::BuiltInParameter::Enum& parameterId, OdTfVariant& value) const;

The BmParamsCmd command is an example of working with built-in parameters of an element. You can find the command in TB_DevGuideCommands, and you can run it in OdaBimApp by choosing Edit -> Registered Commands -> Parameters -> BmParamsCmd.

OdBmElementPtr pElem = pDb->getObjectId(OdDbHandle(OdUInt64(iHandle))).safeOpenObject();

OdBuiltInParamArray aParams;
pElem->getListParams(aParams);

OdBmAUnitsPtr pUnits = pDb->getUnits();
for (OdBuiltInParamArray::iterator it = aParams.begin(); it != aParams.end(); it++)
{
  OdString mesBP;
  mesBP.format(OD_T("%s: "), OdBm::BuiltInParameter(*it).toString().c_str());

  OdBmParamElemPtr pParamElem = pDb->getObjectId(*it).safeOpenObject();
  OdBmParamDefPtr pDescParam = pParamElem->getParamDef();
  OdBm::UnitType::Enum utEnum = pDescParam->getUnitType();
      
  OdString mes;
  OdTfVariant value;
  OdResult res = pElem->getParam(*it, value);
  if (res == eOk)
  {
    OdVariant::Type odType = value.type();        
    switch (odType) {
    case OdVariant::kInt32: {
      if (utEnum > -2)
        mes.format(OD_T("integer %i asString %s"), value.getInt32(), OdBmLabelUtilsEnModule::format(*pUnits, utEnum, value.getInt32()).c_str());
      else
        mes.format(OD_T("integer %i"), value.getInt32());
    } break;
    case OdVariant::kDouble: {
      mes.format(OD_T("double %f asString %s"), value.getDouble(), OdBmLabelUtilsEnModule::format(*pUnits, utEnum, value.getDouble()).c_str());
    } break;
    case OdVariant::kString: {
      mes.format(OD_T("string %s"), value.getString().c_str());
    } break;
    default: {
      if (odType == OdTfVariant::kDbStubPtr) {
        OdDbStub* pStub = value.getDbStubPtr();
        if (pStub)
        {
          OdBmObjectId rawValue = OdBmObjectId(pStub);
          mes.format(OD_T("id %lld"), (OdUInt64)(rawValue.getHandle()));
        }
        else
          mes.format(OD_T("0"));
      }
    }}
    pIO->putString(mesBP + mes);
  }
  else
  {
    mes.format(OD_T(" Invalid param. OdResult %i"), res);
    pIO->putString(mesBP + mes);
  }
}