Hi All,
my requirement is to get Multilvel BOM from Windchill using API.
i have below code which gives me only the child parts from first node in assebly.
here is my code::
--------------------------------------
package ext.util.javaP;
import java.util.ArrayList;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.part.WTPart;
import wt.part.WTPartUsageLink;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.vc.VersionControlHelper;
import wt.vc.config.LatestConfigSpec;
import wt.vc.struct.IteratedUsageLink;
import wt.vc.struct.StructHelper;
public class StructureNavigator {
WTPart part;
ArrayList<WTPart> partList;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Inside the Main Method");
StructureNavigator navigator = new StructureNavigator(args[0]);
if(navigator.getPart()==null)
{
System.out.println("Assembly not found!!");
return;
}
System.out.println("In Naviagtor !!!");
ArrayList<WTPart> pList = navigator.getPartList();
System.out.println("pList size: "+pList.size());
for(int i=0;i<pList.size();i++)
{
WTPart current = (WTPart)pList.get(i);
if(current!=null){
System.out.println(current.getNumber());
}
}
}
public static ArrayList<WTPart> getWTPartList(String partNumber){
ArrayList<WTPart> parts=new ArrayList<WTPart>();
StructureNavigator navigator = new StructureNavigator(partNumber);
if(navigator.getPart()!=null){
System.out.println("Inside the if of naviagator.getpart() "+navigator.getPart());
parts=navigator.getPartList();
System.out.println("After parts ###### "+parts);
}
else{
System.out.println("#### Structure Navigator is empty #### ");
}
return parts;
}
public WTPart getPart()
{
System.out.println("Inside the getPart() Method::"+part);
return part;
}
public ArrayList<WTPart> getPartList()
{
System.out.println("Inside the ArrayList getPartList() Method" +partList);
return partList;
}
public StructureNavigator(String prt)
{
partList = new ArrayList<WTPart> ();
try{
QuerySpec qs = new QuerySpec(WTPart.class);
SearchCondition sc = new SearchCondition(WTPart.class, WTPart.NUMBER,
SearchCondition.EQUAL, prt.trim());
qs.appendWhere(sc);
QueryResult queryResult = PersistenceHelper.manager.find(qs);
if (queryResult == null) {
part = null;
}
else
{
if(queryResult.hasMoreElements())
{
part = (WTPart) queryResult.nextElement();
getPartStructure(part);
}
}
}catch(Exception e){e.printStackTrace();}
}
public void getPartStructure(WTPart parentPart) throws Exception {
//System.out.println("In getPartStructure!!"+parentPart.getNumber());
try{
//Get Part data
if(!partList.contains(parentPart))
{
partList.add(parentPart);
}
LatestConfigSpec lcs = new LatestConfigSpec();
QueryResult usesLinks = StructHelper.service.navigateUses(parentPart, false);
while(usesLinks.hasMoreElements()){
//FileWriter writer = new FileWriter(path, true);
WTPartUsageLink usageLink = (WTPartUsageLink) usesLinks.nextElement();
WTPart childPart = (WTPart) lcs.process(VersionControlHelper.service.allVersionsOf(((IteratedUsageLink)usageLink).getUses())).nextElement();
getPartStructure(childPart);
}
}catch(Exception e){
System.out.println("###########Exception while getting structure!!! ######## - in get part structure");
e.printStackTrace();
}
}
}
// END********************************************//
***************************
I Pass the run time Argument to this i.e my TOP Level Asm Number: 1234567.
it gives me output::
Inside the Main Method
Inside the getPart() Method::wt.part.WTPart:96042
#########Something here!!#######
Inside the ArrayList getPartList() Method[wt.part.WTPart:96042, wt.part.WTPart:96050, wt.part.WTPart:110026, wt.part.WTPart:110037]
pList size: 4
1234567
0000000021
0000000022
00000000023
***********************************************
Here is the my BOM Snap from Windchill.
Image may be NSFW.
Clik here to view.
and below is my Requirement
Image may be NSFW.
Clik here to view.
Please check my code and suggest the modifications so i can get my required BOM.
Thanks,
Vivek