Created
November 25, 2010 14:31
-
-
Save davidtolsma/715464 to your computer and use it in GitHub Desktop.
Teamcenter ITK utility to create an xml file output of a specific item type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iman.h> | |
#include <sample_err.h> | |
#include <pom.h> | |
#include <item.h> | |
#include <aom.h> | |
#include <aom_prop.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pom.h> | |
#include <qry.h> | |
#include <iman_date.h> | |
#include <cfm.h> | |
#include <imantype.h> | |
int getItemsXML(char *outputFileName, int *rows, void ***items) { | |
char *select_attrs[2] = {"item_id", "puid"}; | |
char *vals[1] = {"EMDItem"}; | |
char itemRevisionName[ITEM_name_size_c + 1] = ""; | |
char itemRevisionID[ITEM_id_size_c + 1] = ""; | |
char itemType[ITEM_type_size_c+1] = ""; | |
tag_t tag_uom = NULLTAG; | |
tag_t *revisions = NULL; | |
int columns = 0; | |
int ii; | |
int irows = 0; | |
int itemRevisionCount = 0; | |
int rev = 0; | |
int isReleased = 0; | |
int isNextReleased = 0; | |
int hasNXDatasets = 0; | |
FILE *out_file; | |
char *tag_string; | |
int prop_count; | |
char **prop_names; | |
CALL( POM_enquiry_create("enquiry") ); | |
CALL( POM_enquiry_add_select_attrs("enquiry", "Item", 2, select_attrs) ); | |
//CALL(POM_enquiry_set_tag_value("enquiry", "value", 1, &tag_uom, POM_enquiry_bind_value)); | |
CALL( POM_enquiry_set_string_value("enquiry", "value", 1, vals, POM_enquiry_const_value) ); | |
CALL( POM_enquiry_set_attr_expr("enquiry", "expression", "Item", "object_type", POM_enquiry_equal , "value") ); | |
CALL( POM_enquiry_set_where_expr( "enquiry", "expression") ); | |
CALL( POM_enquiry_execute("enquiry", &irows, &columns, &items) ); | |
printf("working....\n"); | |
// Assign the output rows to the # of rows found | |
*rows = irows; | |
out_file=fopen(outputFileName, "w"); | |
fprintf(out_file, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); | |
fprintf(out_file, "<database>\n"); | |
//If there are any rows found | |
if (rows > 0) { | |
// For every Item found of type EMDItem | |
for (ii = 0; ii < irows; ii++) { | |
CALL( ITEM_ask_type( *((tag_t *)items[ii][1]) , itemType) ); | |
fprintf(out_file, " <item>\n"); | |
fprintf(out_file, " <itemType>"); | |
fprintf(out_file, "%s", itemType); | |
fprintf(out_file, "</itemType>\n"); | |
fprintf(out_file, " <id>"); | |
fprintf(out_file, "%s", ((char *)items[ii][0])); | |
fprintf(out_file, "</id>\n"); | |
fprintf(out_file, " <name></name>\n"); | |
fprintf(out_file, " </item>\n"); | |
} // End Revision loop | |
} // End Item loop | |
// } // End checking if results returned anything | |
fprintf(out_file, "</database>"); | |
fclose(out_file); | |
return 0; | |
} | |
int getItemsTXT(char *outputFileName, int *rows, void ***items) { | |
char *select_attrs[2] = {"item_id", "puid"}; | |
char *vals[1] = {"EMDItem"}; | |
char itemRevisionName[ITEM_name_size_c + 1] = ""; | |
char itemRevisionID[ITEM_id_size_c + 1] = ""; | |
char itemType[ITEM_type_size_c+1] = ""; | |
tag_t tag_uom = NULLTAG; | |
tag_t *revisions = NULL; | |
int columns = 0; | |
int ii; | |
int irows = 0; | |
int itemRevisionCount = 0; | |
int rev = 0; | |
int isReleased = 0; | |
int isNextReleased = 0; | |
int hasNXDatasets = 0; | |
FILE *out_file; | |
char *tag_string; | |
int prop_count; | |
char **prop_names; | |
CALL( POM_enquiry_create("enquiry") ); | |
CALL( POM_enquiry_add_select_attrs("enquiry", "Item", 2, select_attrs) ); | |
//CALL(POM_enquiry_set_tag_value("enquiry", "value", 1, &tag_uom, POM_enquiry_bind_value)); | |
CALL( POM_enquiry_set_string_value("enquiry", "value", 1, vals, POM_enquiry_const_value) ); | |
CALL( POM_enquiry_set_attr_expr("enquiry", "expression", "Item", "object_type", POM_enquiry_equal , "value") ); | |
CALL( POM_enquiry_set_where_expr( "enquiry", "expression") ); | |
CALL( POM_enquiry_execute("enquiry", &irows, &columns, &items) ); | |
printf("working....\n"); | |
// Assign the output rows to the # of rows found | |
*rows = irows; | |
out_file=fopen(outputFileName, "w"); | |
//If there are any rows found | |
if (rows > 0) { | |
// For every Item found of type EMDItem | |
for (ii = 0; ii < irows; ii++) { | |
fprintf(out_file, "%s\n", ((char *)items[ii][0])); | |
} // End Revision loop | |
} // End Item loop | |
// } // End checking if results returned anything | |
fclose(out_file); | |
return 0; | |
} | |
int ITK_user_main(int argc, char* argv[]) { | |
// Get required argument(s) from command line | |
char *itemType=ITK_ask_cli_argument("-itemType="); | |
char *outputFileName=ITK_ask_cli_argument("-outputFile="); | |
char *outputType=ITK_ask_cli_argument("-outputType="); | |
int rows = 0; | |
int status = 0; | |
char *message; | |
void ***items = NULL; | |
int ii=0; | |
char *tag_string; | |
if(outputFileName == NULL) { printf("missing required -outputFile=c:\\temp\\outputFile.txt"); return(0); } | |
if(outputType == NULL) { printf("missing required -outputType=TXT | XML"); return(0); } | |
ITK_initialize_text_services( 0 ); | |
status = ITK_auto_login(); | |
if ( status != ITK_ok ) { | |
printf("Login not successful\n"); | |
} | |
else { | |
printf("Login successful\n"); | |
ITK_set_journalling(FALSE); | |
if (!strcmp(outputType, "TXT")) { | |
getItemsTXT(outputFileName, &rows, items); | |
} | |
else if (!strcmp(outputType, "XML")) { | |
getItemsXML(outputFileName, &rows, items); | |
} | |
else { | |
printf("-outputType=%s is not a valid type", outputType); | |
} | |
} | |
ITK_exit_module(TRUE); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment