In ITK we have several APIs to clone an existing structure. If you are working on client-side, here is an example to clone a structure.
private void BOMClone
(TCComponentItem oldItem,
TCComponentItem newItem,
TCSession session) throws TCException
{
// TODO Auto-generated method stub
TCComponentBOMWindow oldBomWindow = null;
TCComponentBOMWindow newBomWindow = null;
try {
TCComponentRevisionRuleType ruleType = (TCComponentRevisionRuleType) session
.getTypeComponent("RevisionRule");
TCComponentRevisionRule defRule = ruleType.getDefaultRule();
TCComponentBOMWindowType bomType = (TCComponentBOMWindowType) session
.getTypeComponent("BOMWindow");
oldBomWindow = bomType.create(defRule);
oldBomWindow.setWindowTopLine(oldItem, null, null, null);
TCComponentBOMLine oldBomTopLine = oldBomWindow.getTopBOMLine();
AIFComponentContext[] oldBomContext = oldBomTopLine.getChildren();
TCComponentItemRevision[] childItems = new TCComponentItemRevision[oldBomContext.length];
for ( int i=0; i < oldBomContext.length; i++ )
{
if ( oldBomContext[i].getComponent() instanceof TCComponentBOMLine )
{
TCComponentBOMLine childBomLine = new TCComponentBOMLine();
childBomLine =(TCComponentBOMLine) oldBomContext[i].getComponent();
childItems[i] = (TCComponentItemRevision) childBomLine.getItemRevision();
}
}
newBomWindow = bomType.create(defRule);
newBomWindow.setWindowTopLine(newItem, null, null, null);
TCComponentBOMLine newBomTopLine = newBomWindow.getTopBOMLine();
newBomTopLine.add(null, childItems);
newBomWindow.save();
newBomWindow.close();
oldBomWindow.close();
}
catch (TCException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
No comments:
Post a Comment