Skip to main content
11-Garnet
March 15, 2024
Solved

How do you assign an object's name as an attribute value?

  • March 15, 2024
  • 3 replies
  • 2473 views

We want to assign the object name 'TAFE_S325.5_46HP' to attribute values. We have 3 attributes: 'customer', 'emission', and 'engine'. We assign 'TAFE' to 'customer', 'S325.5' to 'emission', and '46HP' to 'engine' without underscores in the object name.

Best answer by TDT

Hi @ukrishnan-3,

 

write a utility to get all eligible objects, store in a list.

Iterate the list, using Persistable Adapter API you can update the attributes values one by one in loop.

3 replies

16-Pearl
March 15, 2024

Hi @ukrishnan-3,

 

when do you want to assign these values to the attributes?

while creation of the object?

11-Garnet
March 15, 2024

We are currently creating three attributes for an existing object, and then assigning the object's name to one of these attributes.

TDT16-PearlAnswer
16-Pearl
March 15, 2024

Hi @ukrishnan-3,

 

write a utility to get all eligible objects, store in a list.

Iterate the list, using Persistable Adapter API you can update the attributes values one by one in loop.

17-Peridot
March 15, 2024

you should be able to do this with Object Initialization Rules, but i don't have all the details handy. take a look at the PTC support site for this topic and you should find an example.

18-Opal
March 16, 2024

@ukrishnan-3 

How does this look?

Notice the attributes were updated WITHOUT iterating the object, this test was done on a WTPart but this can work on an EPMDocument or any object type.

 

In addition to code used to create the result below, if Name is going to be used to set the value of the three attributes, 'customer', 'emissions' and 'engine', I would consider automating the update of those attributes in the event the object is renamed. Or visa versa, update Name if any of the attributes are updated.  Or maybe make the three attributes read only.

 

Before

d_graham_0-1710629175233.png

 

After

d_graham_1-1710629175197.png

 

David

 

11-Garnet
March 17, 2024

Your answer is exactly the same as our requirement . please explain me how to do this ways to do in windchill.

 

Label nameComponent = new Label("");
nameComponent.setColumnName(AttributeDataUtilityHelper.getColumnName(component_id, datum, mc));
nameComponent.setId(component_id);
wt.doc.WTDocument part = (wt.doc.WTDocument) datum;
String fullName = part.getName();
String[] parts = fullName.split("_");
String customer = parts.length > 0 ? parts[0] : "";
String emission = parts.length > 1 ? parts[1] : "";
String engine = parts.length > 2 ? parts[2] : "";

PersistableAdapter pa = new PersistableAdapter(fullName, null, null, null);
pa.load("customer","emission","engine");
pa.set("customer", customer);
pa.set("emission", emission);
pa.set("engine", engine);

pa.apply();.I wrote this code, however the value does not update to attribute. please correct this.