cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

MultiLevel BOM Report

vuchekar
9-Granite

MultiLevel BOM Report

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.

BOM+In+Windchill.jpg

and below is my Requirement

BOM+Requirement.jpg

Please check my code and suggest the modifications so i can get my required BOM.

Thanks,

Vivek

4 REPLIES 4
KD
4-Participant
4-Participant
(To:vuchekar)

HI Vivek,

Give the second argument true instead of false .QueryResult usesLinks = StructHelper.service.navigateUses(parentPart, false);

May be it will work.

saitha
1-Newbie
(To:KD)

Hi vivek,

I am running your same code in eclipse .but only one part is displaying.sub parts are not displaying.Could you please help me what is the mistake in d code .I need to rtrive all the sub parts of part means all assembly.

Regards,

Sandeep

KD
4-Participant
4-Participant
(To:saitha)

Hi Sandeep,

Use this code

public static void getChildParts(WTPart parentPart) throws WTException

{

@SuppressWarnings("deprecation")

QueryResult queryResult= WTPartHelper.service.getUsesWTParts(parentPart, new LatestConfigSpec());

while(queryResult.hasMoreElements())

{

WTPart part=null;

Persistable[] persistable=(Persistable[])queryResult.nextElement();

part=(WTPart)persistable[1];

WTPartUsageLink partLink=(WTPartUsageLink)persistable[0];

System.out.println("ParentPart :-" + parentPart.getName() + " ChildPart :- " + part.getName());

getChildParts(part);

}

}

Regards,

Kaushik

Thank you its working

Top Tags