write_to_file
Write a data block of user data to a file.
int ires = ac_request_special("element_user_data", "read_from_file", string fullpath);
Returns to ires 0 in the absence of errors.
If an error occurs, -1 is returned.
fullpath - path to the file from where to read the data block.
Example.
Pack working tables into a block of user data and write the block to a file, and the reverse operation is to read from the file and unpack into tables.
int WriteTablesToFile()
{
string str, tmppath, filename;
shell_func("get_path", "tmp", tmppath);
filename = "LabPP_SAINT-GOBAIN.ini";
tmppath += "\\" + filename;
coutvar << tmppath;
ac_request_special("element_user_data", "clear");
ts_table(iTableMaterials, "print_to_str_as_json", str);
coutvar << str;
ac_request_special("element_user_data", "set_variable_value", "iTableMaterials", str);
ts_table(iTableSolutionsMats, "print_to_str_as_json", str);
ac_request_special("element_user_data", "set_variable_value", "iTableSolutionsMats", str);
ts_table(iTableSolutions, "print_to_str_as_json", str);
ac_request_special("element_user_data", "set_variable_value", "iTableSolutions", str);
ts_table(iTableSysProps, "print_to_str_as_json", str);
ac_request_special("element_user_data", "set_variable_value", "iTableSysProps", str);
int ires = ac_request_special("element_user_data", "write_to_file", tmppath);
if (ires < 0)
{
tsalert(-2, "Warning", "Failed to write data to file " + tmppath, "This file is for fast loading of GYPROC data. This path may not be writable. Set up config.cpp", "Ok");
return -1;
}
}
int ReadTablesFromFile()
{
string str, tmppath, filename;
filename = "LabPP_SAINT-GOBAIN.ini";
shell_func("get_path", "tmp", tmppath);
tmppath += "\\"+filename;
int ires = ac_request_special("element_user_data", "read_from_file", tmppath);
if (ires < 0)
{
tsalert(-2, "Warning", "Failed to read data from file " + tmppath, "This file contains GYPROC information from an excel file for quick download", "Ok");
return -1;
}
ac_request_special("element_user_data", "get_variable_value", "iTableMaterials", str);
cout << "-------------------------------------\n";
coutvar << str;
ts_table(iTableMaterials, "load_from_json_str", str);
ac_request_special("element_user_data", "get_variable_value", "iTableSolutionsMats", str);
ts_table(iTableSolutionsMats, "load_from_json_str", str);
ac_request_special("element_user_data", "get_variable_value", "iTableSolutions", str);
ts_table(iTableSolutions, "load_from_json_str", str);
ac_request_special("element_user_data", "get_variable_value", "iTableSysProps", str);
ts_table(iTableSysProps, "load_from_json_str", str);
}