All,
Currently when using Windchill API for creating a part and BOM at the same time it is a 2 step process. First we create the part and store it, then if we want to modify the BOM we have to c/o the part and add the Part usage link. Creating the part will result in A.1 and updating the part usage link will result in A.2. Does anyone know a way to create the part and the usage link at the same time resulting in A.1 version?
Here is a sample version of the code:
import java.util.Vector;
import wt.part.*;
import wt.fc.PersistenceHelper;
import wt.folder.FolderHelper;
import wt.folder.Folder;
import wt.occurrence.*;
import wt.part.Quantity;
import wt.part.WTPartUsageLink;
import wt.part.PartUsesOccurrence;
import wt.occurrence.OccurrenceHelper;
public class OccurrenceExample
{
public static void main(String args[])
{
try {
// Get location for both parts
Folder location=FolderHelper.service.getFolder("/Parts");
// Create and persist wagon
WTPart wagon=WTPart.newWTPart("WAGON123","WAGON123");
FolderHelper.assignLocation(wagon,location);
wagon=(WTPart)PersistenceHelper.manager.save(wagon);
// Create and persist wheel
WTPart wheel=WTPart.newWTPart("WHEEL123","WHEEL123");
FolderHelper.assignLocation(wheel,location);
wheel=(WTPart)PersistenceHelper.manager.save(wheel);
// Checkout wagon
wagon=(WTPart)wt.vc.wip.WorkInProgressHelper.service.checkout(wagon,wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder(),(String) null).getWorkingCopy();
// Get Quantity for wheels
Quantity quantity=Quantity.newQuantity(4,wt.part.QuantityUnit.EA);
// Create UsageLink, set quantity and persist
WTPartUsageLink wtpu=WTPartUsageLink.newWTPartUsageLink(wagon,(WTPartMaster) wheel.getMaster());
wtpu.setQuantity(quantity);
wtpu=(WTPartUsageLink) PersistenceHelper.manager.save(wtpu);
// Check wagon back in
wagon=(WTPart)wt.vc.wip.WorkInProgressHelper.service.checkin(wagon,(String) null);
// Create FR, FL, BR, BL occurrences and persist them
PartUsesOccurrence fr=PartUsesOccurrence.newPartUsesOccurrence(wtpu);
fr.setName("Front Right");
OccurrenceHelper.service.saveUsesOccurrenceAndData(fr, (Vector) null);
PartUsesOccurrence fl=PartUsesOccurrence.newPartUsesOccurrence(wtpu);
fl.setName("Front Left");
OccurrenceHelper.service.saveUsesOccurrenceAndData(fl, (Vector) null);
PartUsesOccurrence br=PartUsesOccurrence.newPartUsesOccurrence(wtpu);
br.setName("Back Right");
OccurrenceHelper.service.saveUsesOccurrenceAndData(br, (Vector) null);
PartUsesOccurrence bl=PartUsesOccurrence.newPartUsesOccurrence(wtpu);
bl.setName("Back Left");
OccurrenceHelper.service.saveUsesOccurrenceAndData(bl, (Vector) null);
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}