The database has a unified interface for getting and setting system variables that uses tagged data technology for the exchange of values. This interface includes the getSysVar() method which gets the current value of the specified system variable as an instance of tagged data and the setSysVar() method which sets the system variable using its name and tagged data as a new value. Both methods use the resbuf-instance for data exchange. Usually, the data type of resbuf-instance applied for system variables is known first, therefore group code checking can be skipped. Variable names are case-insensitive strings.
There are two types of system variables:
OdDbDatabase and OdDbHostAppServices classes provide unique methods of the OdDbDatabase class to return and set each system variable; they are getXXX() and setXXX() methods, where XXX is the name of the system variable (for example, getSPLINESEGS() and setSPLINESEGS() methods).
To get a value of a system variable using the getSysVar() method, declare a variable of the OdResBufPtr type and use the getSysVar() method which requires a variable name as an argument of the OdString type and returns the resbuf-instance as a value of the specified variable. The resbuf-instance contains the group code which defines the data type of the system variable and contains the data value which defines the variable value.
For example:
OdResBufPtr pRb1 = pDb->getSysVar(L"ELEVATION");
if(OdDxfCode::_getType(pRb1->restype()) == OdDxfCode::Double)
{
double elevation = pRb1->getDouble();
odPrintConsoleString(L"\nElevation for new entities = %d", elevation);
}
OdResBufPtr pRb3 = pDb->getSysVar(L"INSBASE");
if(OdDxfCode::_getType(pRb3->restype()) == OdDxfCode::Point)
{
OdGePoint3d point = pRb3->getPoint3d();
odPrintConsoleString(L"\nBase point = (%g,%g,%g)", point.x, point.y, point.z);
}
To get a value of a system variable using its unique get method, declare a variable of the system variable type and call the getXXX() method of the OdDbDatabase or OdDbHostAppServices class.
For example:
// For saved in Database system variable
double elevation;
elevation = pDb->getELEVATION();
odPrintConsoleString(L"\nELEVATION = %f", elevation);
// For saved in Registry system variable
OdInt16 demandload;
demandload = pDb->appServices()->getDEMANDLOAD();
odPrintConsoleString(L"\nDEMANDLOAD = %x", demandload);
To set a value of the system variable using the setSysVar() method, declare a variable of the OdResBufPtr type, create a new resbuf-instance using the newRb() static pseudo-constructor, assign the group code and data value for the new instance, and use the setSysVar() method which requires a variable name as the first argument of the OdString type, the variable value as the second argument of the OdResBuf type, and does not return a value. The second argument is a pointer to the resbuf-instance which stores the new value for the variable.
For example:
OdResBufPtr pRb2 = OdResBuf::newRb(OdResBuf::kRtDouble, 8.5);
pDb->setSysVar(L"ELEVATION", pRb2);
OdResBufPtr pRb4 = OdResBuf::newRb(OdResBuf::kRtPoint3d, OdGePoint3d(2.5,3.1,0.6));
pDb->setSysVar(L"INSBASE", pRb4);
To set a value of a system variable using its unique set method, declare a variable of the system variable type and call the setXXX() method of the OdDbDatabase or OdDbHostAppServices class, which will take the value as a parameter.
For example:
// For saved in Database system variable
double elevation = 3.0;
pDb->setELEVATION(elevation);
// For saved in Registry system variable
OdInt16 demandload = 1;
pDb->appServices()->setDEMANDLOAD(demandload);
Note: To initialize the resbuf-instance, use the group codes with the kRt prefix, such as kRtBool, kRtString, kRtInt8, kRtInt16, kRtInt32, kRtInt64, kRtDouble, kRtPoint2d, kRtPoint3d, kRtVector2d, kRtVector3d, kRtColor, kRtObjectId, kRtEntName, kRtHandle, and so on.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|