直接上代码:
- static bool GetTclValue(UF_MOM_id_t mom_id, char *szName, char *szInfo, std::string &stValue,
- bool bShowValue /*= false*/)
- {
- UF_MOM_ask_string(mom_id, szName, (const char **)&szInfo);
- if (szInfo)
- {
- stValue = szInfo;
- if (bShowValue)
- {
- std::string stInfo = std::string(szName) + " = " + szInfo + "\n";
- WRITE(stInfo.c_str());
- }
- return true;
- }
- else
- {
- if (bShowValue)
- {
- std::string stInfo = std::string(szName) + " not found!\n";
- WRITE(stInfo.c_str());
- }
- }
-
- return false;
- }
-
- static bool GetTclArrayValue(UF_MOM_id_t mom_id, char *szName, char *szIndex, char *szInfo, std::string &stValue,
- bool bShowValue /*= false*/)
- {
- UF_MOM_ask_assoc_string_array(mom_id, szName, szIndex, (char **)&szInfo);
-
- if (szInfo)
- {
- stValue = szInfo;
- if (bShowValue)
- {
- std::string stInfo = std::string(szName) + "'s " + szIndex + " = " + szInfo + "\n";
- WRITE(stInfo.c_str());
- }
- return true;
- }
- else
- {
- if (bShowValue)
- {
- std::string stInfo = std::string(szName) + "'s " + szIndex + " not found!\n";
- WRITE(stInfo.c_str());
- }
- }
-
- return false;
- }
-
- static bool SaveTclValue(UF_MOM_id_t mom_id, char *szName, char *szInfo, std::string &stValue,
- bool bShowValue /*= false*/)
- {
- UF_MOM_ask_string(mom_id, szName, (const char **)&szInfo);
-
- std::string sDst = std::string(szName) + " = ";
- if (szInfo)
- {
- sDst += szInfo;
- sDst += '\n';
- }
-
- std::string sDir = "C:\\toolInfo";
-
- if (!CStdDir::IfAccessDirS(sDir) && !CStdDir::CreateDirS(sDir))
- {
- CLOG::Out("创建目录C:\\toolInfo失败!");
- return false;
- }
-
- CStdFile::SaveTXTLineS("C:\\toolInfo\\toolinfos.txt", sDst, true);
-
- return szInfo != nullptr;
- }
-
- static bool SaveTclArrayValue(UF_MOM_id_t mom_id, char *szName, char *szIndex, char *szInfo, std::string &stValue,
- bool bShowValue /*= false*/)
- {
- UF_MOM_ask_assoc_string_array(mom_id, szName, szIndex, (char **)&szInfo);
-
- std::string sDst = std::string(szName) + "'s "+ szIndex + " = ";
- if (szInfo)
- {
- sDst += szInfo;
- sDst += '\n';
- }
-
- std::string sDir = "C:\\toolInfo";
-
- if (!CStdDir::IfAccessDirS(sDir) && !CStdDir::CreateDirS(sDir))
- {
- CLOG::Out("创建目录C:\\toolInfo失败!");
- return false;
- }
-
- CStdFile::SaveTXTLineS("C:\\toolInfo\\toolinfos.txt", sDst, true);
-
- return szInfo != nullptr;
- }
此代码在获取和保存变量的时候非常方便,有助于NX后处理二次开发的时候快速获取和保存变量,方便调试。

欢迎交流与讨论。