Examples
//// File: clean_lines.cxx
//// This program opens a HyperMesh model file, deletes all free lines
//// from the model and saves the model without lines in the same file.
#include <stdio.h>
#include <stdlib.h>
#include "hm_extapi.h"
int main(int argc, char** argv)
{
HM_ExtAPI* hm_api = Open_HM_ExtAPI();
if(argc < 2)
{
printf("Usage: clean_lines <hmfile_name>\n");
exit(0);
}
if(!hm_api)
{
printf("Cannot open HM session: check HyperWorks installation\n");
exit(1);
}
if(!hm_api->LoadModel(argv[1]))
printf("Cannot load: %s\n", argv[1]);
else
{
hm_api->RunHMTclString("*createmark lines 1 all");
hm_api->RunHMTclString("*deletemark lines 1");
hm_api->SaveModel(argv[1]);
printf("done\n");
}
Close_HM_ExtAPI(hm_api);
return 0;
}
An
example command line of how to build this program using Visual Studio on win32 would
be:
cl -I<altair_home>/hm/include <altair_home>/hm/lib/win32/hm_extapi.lib clean_lines.cxx
This
example demonstrates how to use the error codes contained in
hm_extapi_error.h:
#include <stdio.h>
#include <stdlib.h>
#include "hm_extapi.h"
#include "hm_extapi_error.h"
…
if(!hm_api->ImportModel(HM_ExtAPI::AUTO, argv[1]))
{
int err_code = hm_api->GetLastErrorCode();
if(err_code == HM_EXTAPI_ERR_FILE_NOT_FOUND)
fprintf(stderr, "File %s not found\n", argv[1]);
else if(err_code == HM_EXTAPI_ERR_UNRECOGNIZED_FILE_FORMAT)
fprintf(stderr, "%s: unexpected file format\n", argv[1]);
else
fprintf(stderr, "Error importing file %s\n", argv[1]);
exit(1);
}
// else: continue processing with successfully imported model
…
There are additionally several other example applications available in <altair_home>/hm/examples/hm_extapi/. Each example includes a readme.txt file, the source code, Visual Studio project files for building on win32/win64, makefiles for building on linux32/linux64, and sample files for using the application.