Skip to main content
5-Regular Member
March 29, 2023
Question

How do i get WTPart top level part type and all its subtypes through API.

  • March 29, 2023
  • 4 replies
  • 4796 views

"wt.part.WTPart

wt.part.WTPart|com.ptc.ElectricalPart

wt.part.WTPart|wt.part.Placeholder

wt.part.WTPart|com.ptc.windchill.mpml.resource.MPMResource

wt.part.WTPart|com.ptc.windchill.mpml.resource.MPMResource|com.ptc.windchill.mpml.resource.MPMOperationAssignableResource"

 

Any guidance will be helpful.

Thanks, In advance.

 

 

 

 

 

4 replies

avillanueva
23-Emerald I
23-Emerald I
March 29, 2023

I've used this but its been deprecated:

TypeAdminHelper.service.getTypeNodeRoots(TypeManager.getDefaultLocale());

That gets you the roots, top levels. It returns an array of TypeDefinitionNodeView and from there you can use this to get its children:

children = TypeAdminHelper.service.getTypeNodeChildren(node, TypeManager.getDefaultLocale());

which also returns and array at TypeDefinitionNodeView.

You will need to recurse until you get to the end.

18-Opal
March 29, 2023

What is the end game, meaning what are you going to do with the code once you have all WTPart subtypes, just curious.

 

That asked, I know how to do this, but are you looking to simple get the String values you show in your post or the actual type objects?

 

 

David

18-Opal
March 29, 2023

Seems to work.

 

Running code in Windchill shell.

 

Code return HashMap with key the full path to the type and value is type objects.

Print out is <full path> <object type internal name>

d_graham_0-1680133363947.png

 

5-Regular Member
April 4, 2023

This is what is have done to get the info.

 

List<String> listType = new ArrayList<String>();
listType.add("wt.part.WTPart");
ClassAttribute caType = new ClassAttribute(WTTypeDefinitionMaster.class, WTTypeDefinitionMaster.INT_HID);
ConstantExpression ceType = new ConstantExpression("wt.part.WTPart|%");
//ceType.setUseEscape(true);
SearchCondition searchConditionType = new SearchCondition(caType, SearchCondition.LIKE, ceType);
QuerySpec groupQuery = new QuerySpec(com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinitionMaster.class);
groupQuery.appendWhere(searchConditionType, new int[] { 0, 1 });
QueryResult results = PersistenceHelper.manager.find(groupQuery);

while (results.hasMoreElements()) {
WTTypeDefinitionMaster grp = (com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinitionMaster) results
.nextElement();
//System.out.println(">>>"+grp.getIntHid());
listType.add(grp.getIntHid());
}
System.out.println(listType);

 

Thanks for the help.

18-Opal
April 4, 2023

I read your code. That’s not actually going to get you the type. It will get you the type def master, but not the actual type.

So, I’d say you’re 1/2 way there. 👍

 

Also, and this is very minor, but 

List<String> listType = new ArrayList<String>();

this code is redundant.

 

Best to write as below:

List<String> listType = new ArrayList<>();

this code is not redundant.

 

20-Turquoise
April 4, 2023

@d_graham wrote:

Also, and this is very minor, but 

List<String> listType = new ArrayList<String>();

this code is redundant.

 

Best to write as below:

List<String> listType = new ArrayList<>();

this code is not redundant.

 


I have always done it the "redundant" way...

https://www.w3schools.com/java/java_arraylist.asp