Skip to main content
10-Marble
January 24, 2024
Solved

Is it possible to automatically call a Java function each time when an object is edited?

  • January 24, 2024
  • 4 replies
  • 1988 views

Hi, I just added a new property called "price" to WTPart. I want to know that, when adding children to a parent WTPart, are there ways to calculate and update the total price of a parent WTPart automatically, by adding the prices of its children WTPart together? 

 

For example, A is the final product, B ($5) and C ($10) are children of A. First I create A, leave the price blank. Then I add C to A as a child, I would like to see the "price" property of A automatically updated to $10. Then add B to A as a child, the price of A is updated to $15.

 

I'm using Windchill 12.1, just wondering if it's possible. I'm new to customization of windchill but have some experiences in Java programming, so if yes, could you please also tell me what are the steps I should do? 

 

Thank you!

Best answer by avillanueva

Another option is a listener which can pick up on check in events for Parts. It can do whatever you want. I have a few running. They are well documented in the customers guide.

4 replies

16-Pearl
January 31, 2024

Hi @TS_10782016,

 

Write a datautility on price attribute of parent part.

Add a logic to traverse the part structure, calculate the price value of all child parts and return the total value.

In the below article you will find how to resgiter the data utlity.

https://www.ptc.com/en/support/article/CS368786?source=search

Also, There is a attribute called calculated attribute.

The above use case should also be able to acheive from calculated attribute.

avillanueva
23-Emerald I
23-Emerald I
January 31, 2024

This sounds like a case for a calculated attribute:

https://www.ptc.com/en/support/article/CS361192?source=search

Maybe a customization is needed. I am not sure of when its invoke but the scenario you are describing is that the parent attribute can keep changing without the parent object being iterated. 

avillanueva
23-Emerald I
23-Emerald I
January 31, 2024

Another option is a listener which can pick up on check in events for Parts. It can do whatever you want. I have a few running. They are well documented in the customers guide.

10-Marble
February 1, 2024

Hi Avillanueva,

I just finished the customization using listener and it works well! Thank you

7-Bedrock
September 30, 2024

Thats the exact example they have in the help for "Using a BusinessAlgorithm in a Calculated Attribute".   In that example, all you do is define an attribute that hold the value of the individual object (say "Price") and a calculated attribute that holes the totals (say "Total Price") with the calculated field filled in as: 

execute("FloatCarambolaAttributeSumBusinessAlgorithm","Price")

https://support.ptc.com/help/windchill/r12.1.2.0/en/index.html#page/Windchill_Help_Center/customization/WCCG_BusLogicCust_TypeManager_CalculatedAttribute_SampleCode.html