Skip to main content
Mar 29, 2023 1:50 PM UTC
Question

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

"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.

 

 

 

 

 

10 replies

Mar 29, 2023 4:28 PM UTC

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.

Mar 29, 2023 4:36 PM UTC

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

Mar 29, 2023 11:45 PM UTC

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

 

Apr 4, 2023 3:34 PM UTC

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.

Apr 4, 2023 5:32 PM UTC

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.

 

Apr 4, 2023 7:15 PM UTC

@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