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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

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

ukrishnan-3
9-Granite

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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDT
12-Amethyst
12-Amethyst
(To:ukrishnan-3)

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.

View solution in original post

9 REPLIES 9
TDT
12-Amethyst
12-Amethyst
(To:ukrishnan-3)

Hi @ukrishnan-3,

 

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

while creation of the object?

ukrishnan-3
9-Granite
(To:TDT)

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

TDT
12-Amethyst
12-Amethyst
(To:ukrishnan-3)

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.

ukrishnan-3
9-Granite
(To:TDT)

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. 

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.

@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

 

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.  

sir please help us for doing this.

@ukrishnan-3 

 

Send me an email from your work email account to windchill.developer@yahoo.com  

 

Im sure we can workout how I can help you to get this working per your spec.

 

BTW, I don’t supply code to people  anonymously. I need to know who you are. Too many “consultants” have used my code in the past, pawning it off as their own. They get paid but the guy who actually  wrote it gets nothing. Just doesn’t seem right to me.  

 

David

Top Tags