Save and Restore Examples

From DocR23

Jump to: navigation, search
Showdoc.png




The following snippet of code demonstrates how one can save an ENTITY_LIST to a SAT FILE. In this example, the units are set to millimeters, the dummy application's name is "Example Application", and the format of the SAT file will be that of the current version of ACIS. The ENTITY_LIST and the name of the SAT file are passed into the function.

api_save_entity_list example
#include <stdio.h>
#include "acis.hxx"
#include "api.hxx"
#include "kernapi.hxx"
#include "lists.hxx"
#include "fileinfo.hxx"
 
void my_save_entity_list(
    ENTITY_LIST & elist,    // (in) List of entities to save
    const char * file_name  // (in) Name of SAT file
) {
  API_NOP_BEGIN
 
    // Set the units and product_id.
    FileInfo fileinfo;
    fileinfo.set_units (1.0);
    fileinfo.set_product_id ("Example Application");
    result = api_set_file_info((FileId | FileUnits), fileinfo);
    check_outcome(result); 
 
    // Also set the option to produce sequence numbers in the SAT file.
    result = api_set_int_option("sequence_save_files", 1);
    check_outcome(result);
 
    // Open a file for writing, save the list of entities, and close the file.
    FILE * save_file = fopen(file_name, "w");
    result = api_save_entity_list(save_file, TRUE, elist);
    fclose(save_file);
    check_outcome(result);
 
  API_NOP_END
}

The following snippet of code demonstrates how you can restore an ENTITY_LIST from a FILE. The name of the SAT file and the ENTITY_LIST are passed into the function.

api_restore_entity_list example
#include <stdio.h>
#include "acis.hxx"
#include "api.hxx"
#include "kernapi.hxx"
#include "lists.hxx"
 
void my_restore_entity_list(
    const char * file_name,  // (in) Name of SAT file
    ENTITY_LIST & elist      // (out) List of restored entities
) {
  API_BEGIN
 
    // Open a file for reading, restore the model from the file, and close the file.
    FILE * save_file = fopen(file_name, "r");
    result = api_restore_entity_list(save_file, TRUE, elist);
    fclose(save_file);
    check_outcome(result);
 
  API_END
}

See Also

Personal tools