Cancel
Showing results for 
Search instead for 
Did you mean: 

uploading a datset using itk

Pioneer
Pioneer

How to upload a dataset using itk

1 REPLY 1

Re: uploading a datset using itk

Valued Contributor
Valued Contributor

for your information:

 

http://teamcenter-open-gate.blogspot.ca/2016/12/teamcenter-itk-dataset-upload.html


extern int ITK_user_main( int argc, char **argv )
{

char *file1 = NULL;
char *LineRead1 = NULL;
FILE *fp1;
char mystring1 [10000];
char *RqmtID = NULL;
tag_t my_dataset = NULLTAG;
char * new_name1 = NULL;
char * new_name2 = NULL;
char **list;
int ifail;
int n_items =0;
int backVal = 0;
int count= 0;

IMF_file_t fileDescriptor ;
tag_t datasettype_tag= NULLTAG;
tag_t default_tool_tag;
tag_t newfile = NULLTAG;
tag_t newFileTag = NULLTAG;
tag_t imannewFileTag = NULLTAG;
AE_reference_type_t reference_type;
IMF_file_t filedescriptor;

//ITK_initialize_text_services : Initializes the Teamcenter text services. This is necessary to get the correct
//error strings when you use EMH_get_error_string, or by certain other Teamcenter functions that make use of text services, like
//forms
//Paramter The value is not used anymore
ITK_initialize_text_services( ITK_BATCH_TEXT_MODE );
ifail = ITK_auto_login ();

new_name1=(char*)MEM_alloc(sizeof(char)*120);
new_name2=(char*)MEM_alloc(sizeof(char)*120);

LineRead1=malloc(30000);

file1=ITK_ask_cli_argument("-i=");
printf("\n Input file1 is--> %s \n ",file1);
fp1=fopen(file1,"r");

//Find the dataset type object for specified type->MSExcel
AE_find_datasettype ("MSExcel",&datasettype_tag);

//Get the defualt tool object for the dataset type
AE_ask_datasettype_def_tool(datasettype_tag,&default_tool_tag);

if(fp1==NULL)
{
printf("\n Error in opening the file1 \n");
}
else
{
printf("\n File1 is successfully opened \n");
while(fgets(mystring1,200000,fp1) !=NULL)
{
if(mystring1)
{
strcpy(LineRead1,mystring1);
printf("\n mystring1 %s ",mystring1);
printf("\n LineRead1 %s ",LineRead1);
}

RqmtID=strtok(LineRead1,"\n");
printf("\n RqmtID %s ",RqmtID );
printf("\n Req item%s\n",RqmtID);fflush(stdout);
strcpy(new_name1,RqmtID);
printf("\n new_name1 %s\n",new_name1);fflush(stdout);
backVal = trim(new_name1);
printf("\n new_name1: %s\n",new_name1);fflush(stdout);
strcpy(new_name2,new_name1);
strcat(new_name2,".xls");
printf("\n new_name2: %s\n",new_name2);fflush(stdout);
//Get the dataset with defined criteria
CALLAPI(AE_find_all_datasets(new_name1,&n_items,&item_tags));
if (n_items >= 1)
{
printf("\nDataset is already avaialbe\n");fflush(stdout);
}
else
{

printf("\n 44444444444444444444444 \n");fflush(stdout);
//Create Dataset of specified type(datasettype_tag) and with other attibutes
CALLAPI(AE_create_dataset_with_id(datasettype_tag, new_name1,"Loading Bulk Dataset", 0, 0, &tDataset));
printf("\n 5555555555555555 \n");fflush(stdout);

//Set dataset format
CALLAPI(AE_set_dataset_format(tDataset,"BINARY_REF"));

//Set the tool(tool with which this dataset to be open) for Specified dataset
CALLAPI(AE_set_dataset_tool(tDataset,default_tool_tag));

//Get the references for the dataset
//In which we insert the actual datset file
CALLAPI(AE_ask_datasettype_refs(datasettype_tag,&count,&list));

//Import the file in Teamcenter
if ( IMF_import_file ("/home/req83/Deliverable.xls",NULL,SS_BINARY,&imannewFileTag,&filedescriptor) !=ITK_ok ) PrintErrorStack();

//Set the original name property for file
if ( IMF_set_original_file_name(imannewFileTag,new_name2) !=ITK_ok ) PrintErrorStack();

//Save the uploaded file
save_object(imannewFileTag);

//Add the imported file into dataset as named reference
if (AE_add_dataset_named_ref(tDataset,list[0],SS_BINARY,imannewFileTag) !=ITK_ok ) PrintErrorStack();
//if ( AE_import_named_ref (tDataset,"excel","/home/req83/Deliverable.xls",new_name2,SS_BINARY) !=ITK_ok ) PrintErrorStack();

//Save the dataset
save_object(tDataset);
printf("\nDataset is created\n");fflush(stdout);
}
}
fclose (fp1);
}
return ( ITK_ok );
}