cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

windchill Api to update Family table attribute

prasad_RR
4-Participant

windchill Api to update Family table attribute

Hello Team,

 

I am writing a WRS where we can pass attribute internal name and attribute value and cad oid , and it will update that attribute of given Cad object (with iteration changed).

For stand alone CAD , i succeed in achieving the requirement.However i am stuck with Family table object.

eg: if OID is of Generic or instance. 

 

I am using below code snippet.

Please suggest what i am doing wrong here:

 

if(epm.isTopGeneric())
{
epmGeneric=epm;
System.out.println("******************Its a generic CAD*********************");
instanceDetailsMap=(Map<EPMDocument, WTHashSet>) getInstanceDetails(epm);
}
else {
System.out.println("*****************Its a Instance CAD *******************");
QueryResult ft_qr2 =EPMStructureHelper.service.navigateGenericToIteration( epm, null, true, null);
epm = (EPMDocument) ft_qr2.nextElement();//Generic Part
System.out.println("************ Fetched Generic from Instance ***********"+epm.getIdentity());
instanceDetailsMap = (Map<EPMDocument, WTHashSet>) getInstanceDetails(epm);
System.out.println("Collect all Instance for a given Instance by getting Generic first");
 
}
try {
Map<EPMDocument, Object> cadDocLMDMap = prepareCadDocLMDMap(instanceDetailsMap);
Map<EPMDocument, Object> ftStatusMap = prepareFTStatusMap(instanceDetailsMap.values());
 
WTHashSet collection = instanceDetailsMap.get(epm);
System.out.println("instanceSet size : " + collection.size());
collection.add(epm);
 
 
workspace = EPMWorkspaceHelper.manager.addToWorkspace(workspace, collection);
System.out.println("-------------Creating and Adding Objects to  Workspace-------------");
EPMDocConfigSpec configSpec = new EPMDocConfigSpec();
configSpec.setLatestActive();
 
if (WorkInProgressHelper.isCheckedOut(epm)) {
System.out.println(epm.getNumber() + "----CAD Document is Already checked Out . ");
}
else {
List<EPMDocument> checkOutDrawings = new ArrayList<EPMDocument>();
List<EPMDocument> objectsToCheckOut = new ArrayList<EPMDocument>();
 
System.out.println("------Family Table Objects are checkedOUT----");
WTSet objectsInWorkspace = EPMWorkspaceHelper.manager.getObjectsInWorkspace(workspace, EPMDocument.class);
int count=collectFamilyInstances(epm);
System.out.println("=======NO OF Objects in Family Table is =========="+count);
List<EPMDocument> epmDocList = new ArrayList<>();
epmDocList.addAll(objectsInWorkspace);
checkout(epmDocList, workspace);
System.out.println("---------All workspace Objects are CheckedOUT----------");
HashMap<String, Object> ibaMap = new HashMap<>();
WTKeyedHashMap epmAttributeMap = new WTKeyedHashMap();
for (Iterator i_objects = objectsInWorkspace.persistableIterator(); i_objects.hasNext();) {
Workable epmInWorkspace = (Workable) i_objects.next();
epm = (EPMDocument) epmInWorkspace;
if(epm.isGeneric()) {
epmGeneric = (EPMDocument) PersistenceHelper.manager.refresh(epm);
 
}
 
objectsToCheckOut.add(epm);
checkOutDrawings.add(epm);
 
if (dataType.contains("Integer"))
{
int attrValue=Integer.parseInt(attrVal);
ibaMap.put(attribute, attrValue);
}
else if(dataType.contains("Boolean"))
{
boolean attrValue=Boolean.parseBoolean(attrVal);
ibaMap.put(attribute, attrValue);
}else if(dataType.contains("Double"))
{
double attrValue=Double.parseDouble(attrVal);
ibaMap.put(attribute, attrValue);
}
else if(dataType.contains("Long"))
{
long attrValue=Long.parseLong(attrVal);
ibaMap.put(attribute, attrValue);
}
else if(dataType.contains("Float"))
{
float attrValue=Float.parseFloat(attrVal);
ibaMap.put(attribute, attrValue);
}
if (dataType.contains("String"))
{
String attrValue=attrVal;
ibaMap.put(attribute, attrValue);
}
 
}
 
System.out.println("update Generic CADDocument :: CAD Document : " + epmGeneric.getNumber());
System.out.println("Generic is checkedout========"+WorkInProgressHelper.isCheckedOut(epmGeneric));
if (!ibaMap.isEmpty() && epmGeneric !=null) {
epmAttributeMap.put(epmGeneric, ibaMap);
System.out.println("before set att api epmAttributeMap:   " +epmGeneric.getNumber() );
EPMWorkspaceHelper.manager.setAttributes(workspace, epmAttributeMap);
PersistenceHelper.manager.refresh(epmGeneric);
System.out.println("After set att api epmAttributeMap: " +epmGeneric.getNumber() );
 
}
 
List<Object> objectsToCheckIn = new ArrayList<Object>();
objectsToCheckIn.addAll(checkOutDrawings);
checkin(objectsToCheckIn, checkInComment, workspace);
System.out.println("Objects are checkedIn-------");
 
 
//destroyWorkspace(workspace);
if ( workspace != null) {
System.out.println("-----Going to delete workspace----------");
workspace = EPMWorkspaceHelper.manager.removeFromWorkspace(workspace, CollectionsHelper.singletonWTList(epm));
PersistenceHelper.manager.delete(workspace);
System.out.println("-----workspace Deleted----------");
}
updateFTStatus(ftStatusMap);
updateLMD(cadDocLMDMap);
System.out.println("Family Table Status and Last Modified Date Updated ");
System.out.println(" Transaction Details which is getting committed--------"+Transaction.getCurrentTransaction());
trx.commit();
trx = null;
 
System.out.println("EXIT : UpdateEPMDocServices.updateFT");
}
} catch (WTException e) {
e.printStackTrace();
System.out.println("WTException occurred while updating Attribute of generic document---"+e);
}
 
Error Message:
===========================================================================
0:52,057 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.out wcadmin - ---------All workspace Objects are CheckedOUT----------
2023-08-06 19:20:52,062 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.out wcadmin - update Generic CADDocument :: CAD Document : REFERENCES
2023-08-06 19:20:52,063 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.out wcadmin - Generic is checkedout========true
2023-08-06 19:20:52,063 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.out wcadmin - before set att api epmAttributeMap: REFERENCES
2023-08-06 19:20:52,129 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - (wt.query.queryResource/9) wt.query.QueryException: Value array is empty for Search Condition.
2023-08-06 19:20:52,129 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.query.SearchCondition.<init>(SearchCondition.java:1929)
2023-08-06 19:20:52,130 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.query.SearchCondition.<init>(SearchCondition.java:1881)
2023-08-06 19:20:52,130 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.epm.workspaces.WorkspaceAttributeManager.getFTAttributeColumns(WorkspaceAttributeManager.java:1317)
2023-08-06 19:20:52,131 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.epm.workspaces.WorkspaceAttributeManager.getFamilyTablesInfo(WorkspaceAttributeManager.java:1112)
2023-08-06 19:20:52,131 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.epm.workspaces.WorkspaceAttributeManager.setAttributes(WorkspaceAttributeManager.java:230)
2023-08-06 19:20:52,131 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.epm.workspaces.EPMStandardWorkspaceManager.setAttributes(EPMStandardWorkspaceManager.java:812)
2023-08-06 19:20:52,131 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2023-08-06 19:20:52,133 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2023-08-06 19:20:52,133 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2023-08-06 19:20:52,133 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at java.base/java.lang.reflect.Method.invoke(Method.java:566)
2023-08-06 19:20:52,133 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at wt.services.ServiceFactory$ServerInvocationHandler.invoke(ServiceFactory.java:399)
2023-08-06 19:20:52,133 INFO [ajp-nio-127.0.0.1-8010-exec-6] wt.system.err wcadmin - at com.sun.proxy.$Proxy124.setAttributes(Unknown Source)

 

 

3 REPLIES 3
HelesicPetr
22-Sapphire I
(To:prasad_RR)

Hi @prasad_RR 

You did nothing wrong. You just do not need that you need to change the family table object to normal object.

This change is not saved but you can update the attributes. 

 

I use following code to disable generic or instance. After that change I update attributes. 

boolean docIsInstance = epm.isInstance();
boolean docIsGeneric = epm.isGeneric();
if (docIsInstance)
{
	try
	{
		epm.setInstance(false);
	} catch (WTPropertyVetoException e1)
	{
		logger.error(String.format("Family instance could not be disabled  %s", epm.getNumber()));
		e1.printStackTrace();
	}
}
if (docIsGeneric)
{
	try
	{
		epm.setGeneric(false);
	} catch (WTPropertyVetoException e1)
	{
		logger.error(String.format("Family Generic could not be disabled  %s", epm.getNumber()));
		e1.printStackTrace();
	}
}

 If you do not use logger for logging errors change it to System.out.

 

Hope this can help

 

PetrH

prasad_RR
4-Participant
(To:HelesicPetr)

Thanks  @HelesicPetr 

 

This will not impact Family objects link?

After attribute update , Object will behave similar to what it was before ?

 

HelesicPetr
22-Sapphire I
(To:prasad_RR)

Hi @prasad_RR 

No it does not impact FT Link.

In my case I update just IBA attributes of EPMDocument so the epm.Instance and  epm.Generic are not saved in database.

This is just temporary change and do not involve system.

 

I definitely advice you to test it, but I've used it for many many many years without any issue. 

 

PetrH

Top Tags