Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hello, maybe somene can help me, on our test environment we are pushing PRO_MP_MASS from Creo into Windchill with success but it come in as 15 character floating point notation, so a washer with a mass of 0.01 from Creo shows as 1.0 E-2
There are 2 objectives for this data, 1) export to excel to perform mass roll-ups, 2) Use it for Creo View colour coded searching of CAD mass against actual or predicted mass
For the 1st objective the floating point notation is OK becuase we can manipluate it in Excel, for the second objective it isnt possible to perform colour coded search in Creo View unless mass is shown as 3 decimal places.
So is it possible to create a calculated attribute which can convert the floating point attribute linked PRO_MP_MASS into a 3 decimal place result?
I know we can make a different parameter in Creo and use relations to push 3 decimal place value to Windchill, but this relies on having some automation to add the parameter when updating parts and there is a chance it found be deleted by the user.
If there are any suggestions to meet the 2 objectives I would be more than welcome to a new solution or even a different product.
Thanks!
Solved! Go to Solution.
@khimani_mohiki Thanks for your response. I figured out a way with a calculated attribute.
Let's say we have the Attribute WEIGHT synchronised from the PRO_MP_MASS
You can create a calculated attribute called e.g. WEIGHT_ROUNDED. The unit must be the same as on the WEIGHT attribute!
The formula for this attribute would be: execute("ch.bmr.core.businessfield.RoundNumberWithUnits",WEIGHT)
The Java Code for this looks like:
package ch.bmr.core.businessfield;
import com.ptc.core.businessfield.server.businessObject.BusinessAlgorithm;
import com.ptc.core.businessfield.server.businessObject.BusinessAlgorithmContext;
import lombok.extern.slf4j.Slf4j;
import wt.units.FloatingPointWithUnits;
import wt.units.Unit;
import wt.units.UnitFormatException;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* @version 2021-09-29
*/
@Slf4j
public class RoundNumberWithUnits implements BusinessAlgorithm {
@Override
public FloatingPointWithUnits execute(BusinessAlgorithmContext businessAlgorithmContext,
Object[] objects) {
FloatingPointWithUnits result = null;
if(objects[0]!= null) {
if (objects[0] instanceof FloatingPointWithUnits) {
FloatingPointWithUnits number = (FloatingPointWithUnits) objects[0];
try {
double v = BigDecimal.valueOf(number.doubleValue()).setScale(3, RoundingMode.HALF_UP).doubleValue();
Unit value = new Unit(v, 3, number.getUnits());
result = new FloatingPointWithUnits(value);
} catch (UnitFormatException e) {
log.error("ERROR-529544: ", e);
}
}
}
return result;
}
@Override
public FloatingPointWithUnits getSampleValue() {
return null;
}
}
Unfortunately the calculated attribute can't be shown in the workspace. But on all other places (info page, tables) the value is being shown correctly.
We're hiding the original WEIGHT attribute and are only showing the calculated one.
Example of the WEIGHT and WEIGHT_ROUNDED attribute on the info page.
@khimani_mohiki Have you ever solved that topic? Could you share your experience? Thanks
yes, in a round-about way. In that particular company we changed the units for mass in Windchill from Kilograms to Grams, in this way a part with mass of 0.01kg from Creo would show 10.00000000 Grams in Windchill, we couldnt avoid the trailing zeros for a real number but I think there is a property for it somewhere
@khimani_mohiki Thanks for your response. I figured out a way with a calculated attribute.
Let's say we have the Attribute WEIGHT synchronised from the PRO_MP_MASS
You can create a calculated attribute called e.g. WEIGHT_ROUNDED. The unit must be the same as on the WEIGHT attribute!
The formula for this attribute would be: execute("ch.bmr.core.businessfield.RoundNumberWithUnits",WEIGHT)
The Java Code for this looks like:
package ch.bmr.core.businessfield;
import com.ptc.core.businessfield.server.businessObject.BusinessAlgorithm;
import com.ptc.core.businessfield.server.businessObject.BusinessAlgorithmContext;
import lombok.extern.slf4j.Slf4j;
import wt.units.FloatingPointWithUnits;
import wt.units.Unit;
import wt.units.UnitFormatException;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* @version 2021-09-29
*/
@Slf4j
public class RoundNumberWithUnits implements BusinessAlgorithm {
@Override
public FloatingPointWithUnits execute(BusinessAlgorithmContext businessAlgorithmContext,
Object[] objects) {
FloatingPointWithUnits result = null;
if(objects[0]!= null) {
if (objects[0] instanceof FloatingPointWithUnits) {
FloatingPointWithUnits number = (FloatingPointWithUnits) objects[0];
try {
double v = BigDecimal.valueOf(number.doubleValue()).setScale(3, RoundingMode.HALF_UP).doubleValue();
Unit value = new Unit(v, 3, number.getUnits());
result = new FloatingPointWithUnits(value);
} catch (UnitFormatException e) {
log.error("ERROR-529544: ", e);
}
}
}
return result;
}
@Override
public FloatingPointWithUnits getSampleValue() {
return null;
}
}
Unfortunately the calculated attribute can't be shown in the workspace. But on all other places (info page, tables) the value is being shown correctly.
We're hiding the original WEIGHT attribute and are only showing the calculated one.
Example of the WEIGHT and WEIGHT_ROUNDED attribute on the info page.