Thursday 29 December 2016

Teamcenter ITK : Exapnd BOM with Revision Rule

Problem Statement :Print BOM recursively using BOM APIs
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "unidefs.h"
#include "mem.h"
#include "tc.h"
#include "tcfile.h"
#include "item.h"
#include "bom.h"
#include "cfm.h"
#include "workspaceobject.h"
#include "tc_string.h"
#include "tcfile.h"
#include "emh.h"
#include "tctype.h"

static void printrecursivebom (tag_t line,tag_t Parent, int depth,char *req_item);
extern int ITK_user_main( int argc, char **argv )
{
        char *Item_ID = ITK_ask_cli_argument("-Item_ID=");
 char **values = (char **) MEM_alloc(1 * sizeof(char *));
 char **attrs = (char **) MEM_alloc(1 * sizeof(char *));

 int ifail;
 int n_tags_found=0;

 tag_t item_tag=null_tag; 
 tag_t window=null_tag; 
 tag_t rule=null_tag; 
 tag_t top_line=null_tag;
 tag_t *tags_found = NULL;

       ifail =ITK_auto_login( );

  if(ifail==ITK_ok)
 {
   printf("\n\n\t Successfully Logged in With INFODBA");
 }
 else
 {
  printf("\n\n\t Login Failed");
 }
 values[0] = (char *)Item_ID;
 attrs[0] ="item_id";  

 ITEM_find_items_by_key_attributes(1,attrs,values, &n_tags_found, &tags_found); //Searching Item tag in Database
       printf("\n\n\tn_tags_found are  --->%d",n_tags_found);

 item_tag = tags_found[0]; //storing Item Tag in item_tag datatype
 MEM_free(tags_found);

 BOM_create_window (&window);  
 CFM_find( "Latest Working", &rule ); //Find Revision Rule 
 BOM_set_window_config_rule( window, rule );//Set Revision Rule 

//Sets a flag to say whether BOM lines are packed by default. By default 
all BOM lines are reported. //If this function is called to set the 
default packing true, then packable lines will be reported as one //BOM 
line.
 BOM_set_window_pack_all (window, true);

 BOM_set_window_top_line (window, item_tag, null_tag, null_tag, &top_line);

 printrecursivebom(top_line,NULLTAG,0,Item_ID);  

return ITK_ok;
}
static void printrecursivebom(tag_t line,tag_t Parent, int depth,char *req_item)
  {
 int n=0;
 int k=0;
 int *   attribute;

 tag_t  *children ;
 tag_t    value;
 
 char    a_name[WSO_name_size_c+1];

 depth ++;

        printf("\n\n\t\t Calling Recursive function to get childrens of Parent Assembly\n");   

  BOM_line_ask_child_lines (line, &n, &children);  
  printf("\n No:of Child Parts are -------->%d\n",n);
  printf("\nDepth value is -------->%d\n",depth);

  for (k = 0; k < n; k++)
  {
  //get the revision from bomline
                BOM_line_look_up_attribute  (  "bl_revision", &attribute  );
                BOM_line_ask_attribute_tag  (  children[k], attribute, &value  );
  WSOM_ask_name  (  value,  a_name);
  printf("\n\n\n ChildName is  :: %s\n",a_name); 
  printf("\n K value is -------->%d\n",k);


  printrecursivebom (children[k],line,depth,req_item);
 }
 printf("\n After Depth value is -------->%d\n",depth);
  }
Explanation : Important API 
ITEM_find_items_by_key_attributes(1,attrs,values, &n_tags_found, &tags_found); 
BOM_create_window (&window); 
CFM_find( "Latest Working", &rule );
BOM_set_window_config_rule( window, rule ); 

BOM_set_window_pack_all (window, true); 
BOM_set_window_top_line (window, item_tag, null_tag, null_tag, &top_line); 
BOM_line_ask_child_lines (line, &n, &children); BOM_line_look_up_attribute ( "bl_revision", &attribute ); BOM_line_ask_attribute_tag ( children[k], attribute, &value ); WSOM_ask_name ( value, a_name);

4 comments:

  1. Sir can you explain all settings of itk in detail why we do that settings there purpose n all.

    ReplyDelete
  2. Thank you very much Anil for taking time to give us fine details about RAC customization

    ReplyDelete
  3. any free course related to this of user guide book for all the question

    ReplyDelete