Skip to main content
12-Amethyst
October 25, 2023
Solved

Programmatically retrieve part instance structure

  • October 25, 2023
  • 2 replies
  • 1912 views

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?

Best answer by SH_9602401

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();
}

2 replies

17-Peridot
October 26, 2023

Hi @SH_9602401 

I don't think there is such an API can do that, I have searched the PTC knowledge base

HelesicPetr
22-Sapphire II
22-Sapphire II
October 26, 2023

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

 

12-Amethyst
November 7, 2023

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

HelesicPetr
22-Sapphire II
22-Sapphire II
November 8, 2023

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