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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

How to update the Softtype attribute and OOTB attribute of WTDocument

ptc-3953915
1-Visitor

How to update the Softtype attribute and OOTB attribute of WTDocument

Hi can any one help me how I can update the WTDocument attributes I have some softtype also. currently I am using Update-Objects to update the objects I am looking for Windchill API

9 REPLIES 9

public static void updateAttributesValues(Persistable object, String[] attributeNames, Object[] attributeValues) throws WTException

{

if(attributeNames.length != attributeValues.length)

{

throw new WTException("The length of attribute names array is not the same as the length of attribute values array");

}

LWCNormalizedObject lwcNormalizedObject = new LWCNormalizedObject(object, null, null, new UpdateOperationIdentifier());

lwcNormalizedObject.load(attributeNames);

for(int i=0; i<attributeNames.length; i++)

{

lwcNormalizedObject.set(attributeNames[i], attributeValues[i]);

}

lwcNormalizedObject.apply();

}

By the way, LWCNormalizedObject is depricated in PDMLink 10.2.

WindchillJavadoc 10.2:

LWCNormalizedObject is deprecated and is planned to be removed in the next release. Use PersistableAdapter instead.

Hello Bjoern,

I am not able to search the PersistableAdapter class I am using Windchill 10.0 M010 can you tell me the package and if possible can you share code with me ?

The class is:

com.ptc.core.lwc.server.PersistableAdapter

The examples are the same:

CREATE

PersistableAdapter obj = new PersistableAdapter("com.acme.AcmePart",null,null);

obj.load("name","number");

obj.set("name","my name");

obj.set("number","12345");

obj.persist();


RETRIEVE

PersistableAdapter obj = new PersistableAdapter(my_persistable,null,null,null);

obj.load("name","number");

Object nameValue = obj.get("name");

Object numberValue = obj.get("number");


UPDATE

PersistableAdapter obj = new PersistableAdapter(my_persistable,null,Locale.US,new UpdateOperationIdentifier());

obj.load("attributeA","attribtueB");

obj.set("attributeA",Boolean.TRUE);

obj.set("attribtueB","PURPLE");

obj.apply();

...

PersistenceHelper.manager.modify(my_persistable);

KD
12-Amethyst
12-Amethyst
(To:ptc-3953915)

In 10.0 and 10.1 there is LWCNormalizedObject.

In 10.2 the whole class in deprecated.

akumar-2
1-Visitor
(To:KD)

Hi,

I wanted to update attribute on Document softtype. I found some solutions, however they are not working because I couldnt found required APIs in Windchill. I am using windchill 9.1

com.ptc.core.lwc.server.PersistableAdapter

com.ptc.core.lwc.server.LWCNormalizedObject

if anyone found solution or any other way in 9.1, then Plz let me know...!

KD
12-Amethyst
12-Amethyst
(To:akumar-2)

Hi Anurag,

Try below code.

/**

* This method will update the IBA value without changing the iteration of

* the given Persistable object.

*

* @param iba

* The object of {@link IBAHolder}

*

* @param attrName

* Name of the IBA

*

* @param value

* Value of the IBA

*

* @exception WTException

* throws {@link WTException}

*

* @exception WTPropertyVetoException

* throws {@link WTPropertyVetoException}

*

* @exception RemoteException

* throws {@link RemoteException}

*/

public static void updateValues(IBAHolder iba, String attrName, Object value)

throws WTException, WTPropertyVetoException, RemoteException {

final IBAHolder ibaHolder = IBAValueHelper.service

.refreshAttributeContainer((IBAHolder) iba, null, null, null);

// From part retrieving corresponding IBAHolder

final DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaHolder

.getAttributeContainer();

final AttributeDefDefaultView addview = IBADefinitionHelper.service

.getAttributeDefDefaultViewByPath(attrName);

final AbstractValueView abstractValueView[] = defaultattributecontainer

.getAttributeValues(addview);

final StringDefView sd = (StringDefView) addview;

final StringValueDefaultView svdobj = new StringValueDefaultView(sd,

(String) value);

// Putting StringValueDefaultView into AbstractValueView

defaultattributecontainer

.addAttributeValue(((AbstractValueView) (svdobj)));

// Updating the attribute container

StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(

ibaHolder, null, null, null);

}

With Regards,

Kaushik

akumar-2
1-Visitor
(To:KD)

Hi,

Thanks for quick reply!

I tried to modify WTDocument, but its giving error

wt.vc.wip.WorkInProgressException: The object is not checked out and cannot be modified.

above error coming when below statement execute

PersistenceHelper.manager.modify(wtDoc);

what could be reason?

KD
12-Amethyst
12-Amethyst
(To:akumar-2)

Hi Anurag,

The error is saying to check out the WTDocument.

Without that it cant modify the WTDocument.

Regards,

Kaushik

Announcements


Top Tags