Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
"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.
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.
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
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>
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.
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.
@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...
Well, now you know that’s unnecessary.
Try it and see for yourself.
I did just that earlier and to see if Eclipse complained but no complaints!
Hi @RandyJones
It is just redundant thing and IDE never complains if you do not use some plugins for clear code.
For example SonarLint or Tabine AI Code Completition are useful in my case to keep your code more clear.
PetrH
@RandyJones , your IDE is not complaining because a String is a String. But it’s kind of like what @HelesicPetr mentioned in his example of casting. His example shows an object that’s already a String being cast to a String. This is a great example because it’s easy to understand that this is obviously unnecessary.
Why would you do that?
Answer: You wouldn’t.
The List thing is similar but different.
You are initializing a new object, a List. On the right side of the = sign you define the List as an ArrayList. This means your new List can do everything an ArrayList can do, and that’s all you really need to get out of the ArrayList. Stating ArrayList<String>() is not getting you ANYTHING more than ArrayList<>(). It’s still just an ArrayList. Both give you identical functionality.
The left side of = defines the object more granularly. You could just says List but saying List<String> now initialized the object to accept only String objects and when you read objects from the List everyone knows those objects must be a String.
So, it’s really the left sign of = that’s calling the shots regarding what can go in the list.
Same is true for HashMap. You wouldn’t write:
HashMap<String, WTPart> map = new HashMap<String, WTPart>();
You simple say, hey I need a HashMap with String keys and WTParts as values so I’ll write.
HashMap<String, WTPart> map = new HashMap<>():
Again, right side of = gives you the object’s functionality, that of a HashMap. The left side of = defines what can go into the HashMap.
Makes sense?
David