Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
I am using Windchill PDMLink Release 12.0 and Datecode with CPS 12.0.0.0
What is the best way to programmatically retrieve part instance structure by oid such as OR:wt.part.WTProductInstance2:XXXX?
Solved! Go to Solution.
Thanks for the insights. Here is the code that can retrieve the structure of a part instance:
try {
ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.part.WTPart:1988914855");
WTPart part = (WTPart)PersistenceHelper.manager.refresh(oid);
System.out.println("My part: " + part.getName());
WTPartMaster master = part.getMaster();
QueryResult qr = ConfigurationHelper.service.getAllInstances(master);
if (qr != null) {
while (qr.hasMoreElements()) {
WTProductInstance2 instance = (WTProductInstance2) qr.nextElement();
System.out.println("Instance name: " + instance.getNumber());
QueryResult qr2 = ConfigurationHelper.service.getAllMappedInstances(instance);
while (qr2.hasMoreElements()) {
WTProductInstance2 instance2 = (WTProductInstance2) qr2.nextElement();
System.out.println("Instance2 name: " + instance2.getNumber());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
Hi @SH_9602401
I don't think there is such an API can do that, I have searched the PTC knowledge base
Hi @SH_9602401
Try to use something like this >
WTProductInstance2 retValue = null;
NmOid bsOid = NmOid.newNmOid("OR:wt.part.WTProductInstance2:XXXX");
Object persObject = bsOid.getReferencedIterationObject();
if (persObject.getClass().equals(WTProductInstance2.class))
{
retValue = (WTProductInstance2) persObject;
}
sure simple condition
if (persObject instanceof WTProductInstance2)
{
retValue = (WTProductInstance2) persObject;
}
PetrH
Hi @HelesicPetr
Thank you very much for your response. But retValue shows the part instance itself. Is there a way to get structure from the object?
Best,
Susan H
Hi @SH_9602401
First you need to get the WTProductInstance2 from OID and then use general method to retrieve the structure.
But Iam not sure if you can get structure directly from WTProductInstance2 or you need to get WTPart from WTProductInstance2 and then get the structure.
ConfigSpec localConfigSpec = ConfigHelper.service.getConfigSpecFor(parentWTPart);
QueryResult qr = WTPartHelper.service.getUsesWTParts(parentWTPart, localConfigSpec);
PetrH
Thanks for the insights. Here is the code that can retrieve the structure of a part instance:
try {
ObjectIdentifier oid = ObjectIdentifier.newObjectIdentifier("wt.part.WTPart:1988914855");
WTPart part = (WTPart)PersistenceHelper.manager.refresh(oid);
System.out.println("My part: " + part.getName());
WTPartMaster master = part.getMaster();
QueryResult qr = ConfigurationHelper.service.getAllInstances(master);
if (qr != null) {
while (qr.hasMoreElements()) {
WTProductInstance2 instance = (WTProductInstance2) qr.nextElement();
System.out.println("Instance name: " + instance.getNumber());
QueryResult qr2 = ConfigurationHelper.service.getAllMappedInstances(instance);
while (qr2.hasMoreElements()) {
WTProductInstance2 instance2 = (WTProductInstance2) qr2.nextElement();
System.out.println("Instance2 name: " + instance2.getNumber());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}