Skip to main content
12-Amethyst
Oct 25, 2023 6:06 PM UTC
Solved

Programmatically retrieve part instance structure

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?

12-Amethyst
Nov 9, 2023 12:15 AM UTC

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

5 replies

Rocket_Max
17-Peridot
Oct 26, 2023 8:10 AM UTC

Hi @SH_9602401 

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

Translate
HelesicPetr
22-Sapphire II
Oct 26, 2023 8:42 AM UTC

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

 

Translate
12-Amethyst
Nov 7, 2023 11:28 PM UTC

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

Translate
HelesicPetr
22-Sapphire II
Nov 8, 2023 8:32 AM UTC

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

Translate