Monday, October 7, 2013

Teamcenter: ITK BOM Clone Trick

I have searched this API usage in GTAC and the result was none. After writing many lines of code, found that one single API can rule out the change.
(Sometimes SMALL things can do BIG).
int Clone_init()
{
    tag_t tItem         = NULLTAG;
    tag_t tItemRev      = NULLTAG;
    tag_t tBomWindow    = NULLTAG;
    tag_t tBomLine      = NULLTAG;
    tag_t tNewProd      = NULLTAG;
    tag_t tRevRuleTag   = NULLTAG;
   
    //top line item holding the whole structure
    tItem = ITEM_find_item("000236");
    tItemRev = ITEM_find_rev("000236","A");
   
    ITK_CALL( BOM_create_window ( &tBomWindow ) );
    ITK_CALL ( BOM_set_window_pack_all (tBomWindow, true));
    ITK_CALL ( CFM_find ("Latest Working", &tRevRuleTag ));
    ITK_CALL ( BOM_set_window_config_rule (tBomWindow, tRevRuleTag ));
    ITK_CALL( BOM_set_window_top_line ( tBomWindow, tItem, tItemRev, NULLTAG, &tBomLine ));
    //This API is similar to File->New->Item from Template option.
    ITK_CALL( ME_create_product_from_template( "","A","Test Name","Test Desc",tItemRev,tRevRuleTag,tBomWindow,"Product.Template.Cloning",&tNewProd ));
    return 0;
}

THE RESULT: