Skip to main content
1-Visitor
May 8, 2020
Question

API to get multilevel Where used part?

  • May 8, 2020
  • 2 replies
  • 3804 views

HI,

I want a API to get all levels of where used part, I am using the below API to get where used StructHelper.service.navigateUsedBy(part.getMaster(),true); 

but this gives only 1st level parts. I want all levels as shown in Where Used tab in windchill.

For now I am giving recursive call to the function to get all levels, but this is taking long time, processing time is too high, Is there any better way to do so?

 

@SuppressWarnings("unchecked")
 private   ArrayList<Object> getPartStructure(WTPart part,ArrayList<Object> objectList)
 {
  try
  {  
   ArrayList<WTPart> set=new ArrayList<>();
   QueryResult resultWhere=StructHelper.service.navigateUsedBy(part.getMaster(),true);  
   
   while (resultWhere.hasMoreElements())
   {
    Object object = (Object) resultWhere.nextElement();  
    if(object instanceof WTPart)
    { 
     WTPart prt=(WTPart) object;
     //prt=(WTPart) VersionControlHelper.service.allIterationsOf(prt.getMaster()).nextElement();     
     if(!set.contains(prt))
     {
      set.add(prt);
      if(prt.isEndItem())
      {
       String vehicleFamily=getIBAValue(prt,"VEHICLE_FAMILY");
       if(vehicleFamily!=null && !vehicleFamily.equals(""))
       {
        HashSet<String>familyList=(HashSet<String>)objectList.get(0);
        familyList.add(vehicleFamily);
       }
       else
       {
        HashSet<String>UndisclosedFamilyList=(HashSet<String>)objectList.get(1);
        UndisclosedFamilyList.add(prt.getNumber());
       }
      }else{
      getPartStructure(prt,objectList);
      }
     }
    }
   }   
  }catch (Exception ex)
  {
   ex.printStackTrace();
  }
  return objectList;
 }

2 replies

1-Visitor
May 8, 2020

Hello,

 

You should take a look at wt.part.MultilevelWhereUsedVisitor.

You could also try to see the table builder of the OOTB table

 

 

1-Visitor
May 9, 2020

Thank you @Florent_274366  for reply. I checked MultilevelWhereUsedVisitor and ottb table builder , but it is not understandable. I have a solution has I shared in above post, but I want something with fast response . Actually My requirement is to find the End Part.

5-Regular Member
May 8, 2020

This may be useful:

 

Windchill APIs to obtain "WTPart" structure in Windchill PDMLink

https://www.ptc.com/en/support/article/CS49806

 

You may want to open a Support case, as our Customization engineers have experience with this.

 

Mike Chatel