Skip to main content
12-Amethyst
April 23, 2024
Solved

Part Relation to get Mass Parameter to 3 decimal places

  • April 23, 2024
  • 7 replies
  • 4870 views

Hi

 

We have a crazy relation in our start part that converts the system generated PRO_MP_MASS in a Text Parameter with 3 decimal places, which can then be used to set the weight property within our PLM system, Teamcenter.  Im not a fan of this relation as its about 27 lines long.  I once found a new relation, shown below, on a website, but cant for the life of me remember where.  Trouble is, when Ive come to try it out, its not giving the correct answer, compared to the generated mass property.  Dec_P is set as a parameter to 3

 

RN = FLOOR((PRO_MP_MASS+(5/10^(DEC_P+1))),DEC_P)
IF FLOOR(RN) == 0
MASS = "0."+ITOS((RN-FLOOR(RN))*10^(DEC_P))
ELSE
MASS = ITOS(FLOOR(RN))+"."+ITOS((RN-FLOOR(RN))*10^(DEC_P))
ENDIF

 

 

Best answer by stu-aspinall

This one from Ken seems to work well

 

RN = FLOOR((PRO_MP_MASS+(5/10^(DEC_P+1))),DEC_P)
IF RN < 1.0
MASS = "0."
ELSE
MASS = ITOS ( FLOOR ( RN ) ) + "."
ENDIF
MASS = MASS + EXTRACT ( ITOS ( 10^DEC_P * ( 1 + RN - FLOOR ( RN ) ) ), 2, 3 )

 

Stu

7 replies

23-Emerald IV
April 23, 2024
RPN
18-Opal
April 28, 2024

"Sunday bloody Sunday" 🙂

 

This is working for negative numbers and denominators (-,0,+) as well. Dependent on your needs, it can be simplified.

 

 

dval=1.399e-06
nd=7

Output would be -> 0.0000014

 

 

dval=-116.654
nd=0
 /* Debug Variable
dlen=-1
 /* get the postive rounded value
rval=floor(abs(dval)*pow(10,nd)+0.5)/pow(10,nd)
 /* multiply by 10 power of the abs value
sval = itos(rval*pow(10,abs(nd)))

 /* first string len
slen =floor(string_length(sval))

if (dval < 1)
 /* only for Debug
 dlen=slen
 /* Check if we need to prepend set new sval
 sval= extract("0000000000",1,abs(nd) +1 -slen ) + sval
 /* set new slen
 slen =string_length(sval)

endif 

 /* only if you are okay with a dot at the end and no trailing number
if (nd > 0) 
 sdval=extract(sval,1,slen-nd) + '.' + extract(sval,slen-abs(nd)+1,nd*nd/nd) 
else
 sdval=extract(sval,1,slen-abs(nd)) 
endif

/* Final change for negative numbers
if (dval<0)
sdval='-'+ sdval
endif

 

 

 

 

doc00514.png

 

 

 

 

doc00515.pngdoc00516.pngdoc00517.png

MikeBennett
16-Pearl
April 23, 2024

Hi @stu-aspinall,

 

Can you elaborate on how the relation is not giving the correct answer?  Is it off by a factor, rounding error, etc.? Any errors in the relation?

I used your relation and DEC_P = 3 with a 1x1x1 inch legacy steel cube and the result was 0.283 and a 10x10x10 with result 282.771 which match the calculated mass properties.

 

Thanks,

Michael

12-Amethyst
April 24, 2024

Hi Mike

I have one with a bar, dia 20mm x 100mm, with a density of 1.399e-06 kg/mm3, where the mass prop analysis gives 4.398e-02 Kg.  Mass gives as 0.44, whereas RN reports back as 0.044

Stu

MikeBennett
16-Pearl
April 25, 2024

Hi @stu-aspinall,

 

Using the Evaluate Expression tool [=?] in the relations to break the MASS= line into smaller portions of math

(RN-FLOOR(RN)) = 0.044

10^(DEC_P) = 1000

0.044*1000 =44

 

"0." + "44" = "0.44"

 

It looks like the relations are not accounting for the leading zeros between RN and 10^DEC_P.  This makes me wonder what the original 27 line relation was doing and if those additional lines were considering this.

 

As @BenLoosli calls out, Creo 11.0's RTOS command looks like it will be a game-changer for both these relation sets.
https://support.ptc.com/help/creo/creo_pma/r11.0/usascii/index.html#page/whats_new_pma/fund_real_to_string.html 

13-Aquamarine
April 23, 2024

Perhaps something like this for 3 decimal places:

mass = floor(PRO_MP_MASS*1000+0.5)/1000

 

Edit:  Sorry, I misunderstood the question. 

23-Emerald III
April 23, 2024

Please explain why it isn't working.

It worked fine when I copied it into a test file.

pro_mp_mass = 9.914639

RN = 9.915 (real number)

Mass = 9.915 (string)

 

12-Amethyst
April 24, 2024

Hi

 

I have one with a bar, dia 20mm x 100mm, with a density of 1.399e-06 kg/mm3, where the mass prop analysis gives 4.398e-02 Kg.  Mass gives as 0.44, whereas RN reports back as 0.044

 

Stu

KenFarley
21-Topaz II
April 23, 2024

The ITOS function returns "" or an empty string, when the value presented to it is zero. It does not give you leading zeros. Two cases where what you are looking for will not be provided. My method for this is, using your variables:

IF RN < 1.0
 MASS = "0."
ELSE
 MASS = ITOS ( FLOOR ( RN ) ) + "."
ENDIF
MASS = MASS + EXTRACT ( ITOS ( 10^DEC_P * ( 1 + RN - FLOOR ( RN ) ) ), 2, 3 )

What I'm doing is building the part of the number that is before the decimal place, then using a bit of digit shifting to extract the desired number  of places after the decimal.

12-Amethyst
April 24, 2024

Hi Ken

I have one with a bar, dia 20mm x 100mm, with a density of 1.399e-06 kg/mm3, where the mass prop analysis gives 4.398e-02 Kg.  Mass gives as 0.44, whereas RN reports back as 0.044000

Adding your extra bit to the end of the original relation, makes the two parameters match.

I'll do a few more tests today/tomorrow.

 

Thanks

 

Stu

12-Amethyst
April 24, 2024

Morning Ken

 

So the relation should look like this

 

RN = FLOOR((PRO_MP_MASS+(5/10^(DEC_P+1))),DEC_P)
IF RN < 1.0
MASS = "0."
ELSE
MASS = ITOS ( FLOOR ( RN ) ) + "."
ENDIF
MASS = MASS + EXTRACT ( ITOS ( 10^DEC_P * ( 1 + RN - FLOOR ( RN ) ) ), 2, 3 )

 

Stu

23-Emerald III
April 24, 2024

With Creo 11, this will be easier as PTC has finally added a RtoS (Real to String) function in relations.

mass = rtos(pro_mp_mass,3) will give 3 decimal places to the string parameter named mass.

12-Amethyst
April 26, 2024

Unfortunately Ben, our IT have a rule of thumb of latest version minus 1, so with us currently on 7 (guess they need new batteries in their calculator) we wont get to Creo 11 until probably 2030...lol

 

Stu 

23-Emerald III
April 26, 2024

That is a long relation for what can be easier to calculate.

I hear you on being behind a bit. I am not as bad as your IT, I usually start doing installs at the 5th release, so Creo 11.0.5.0 or Windchill 13.0.2.5. Let someone else bleed from the cutting edge!

RPN
18-Opal
April 26, 2024

And this can’t be fixed with OOTB functionality using [.≠] where ≠ is the number of decimal places?

In C format .2f on a double value. This was working in ProE as well if I remember correctly 😉

 

CS56347

 

  • This number is controlled by config.pro option param_dec_places (valid values 0-14) 
  • When parameters are called out on drawings (in tables or notes), they display with 3 decimal places
    • There is no way to change this default
  • The number of decimal places can be manually controlled using the syntax [.#] where # is the desired number of decimal places to display
    • For example, parameter TEST has a stored value of 10.123456
    • A drawing note with syntax &TEST will display as 10.123
    • If we change the syntax to &TEST[.5] the note will display as 10.12346 (the stored value is still 10.123456, only the displayed value is rounded)
  • This syntax can be used in modeling mode as well to alter notes or standard hole notes

    • Select the hole note in modeling mode > Right Click > Properties
    • Edit the note text by adding the [.#] at the end of the hole note parameter whose decimal places needs to be changed
    • This applies to cosmetic threads or any feature parameter: &THREADS_PER_INCH:FID_259[.0]
  • This syntax can also be used in repeat region tables (for example, &mbr.param.value[.0])

    • Individual cells cannot be controlled
    • If a 2D family table repeat region is in use, drawing option model_digits_in_region must be set to no
  • To remove the leading zero set the following
    • Set Detail Option lead_trail_zeros_scope to all
    • This will allow parameter to follow the lead_trail_zeros setting