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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

STOCK SIZE PARAMETER IN MODEL?

MORECREO
11-Garnet

STOCK SIZE PARAMETER IN MODEL?

Creo 7

This seems insane that its not easier than this.

I can not figure out how to get my parameter in my model to display my full stock size?

I have the following parameters: thickness / width / length

 

Then I have a relation: thickness=d12, width=d9, length=d10 (and these default to 2 decimal places)

 

So then I thought, the relation, (stock_size = thickness "x" width "x" length) would give me what I'm after.

Ex 1.50 x 2.50 x 3.50

Nope, further digging got me to the following equation:

 

STOCK_SIZE = itos(D12) + "." + itos( (D12 - floor(D12)) * 100 ) + " X " + itos(d9) + "." + itos( (d9- floor(d9)) * 100 ) + " X " + itos(d10) + "." + itos( (d10- floor(d10)) * 100 )

 

Which I arrived at because I needed this specific "itos" function to give me 2 decimal places. Now I get 2.50 x 3.50 x 4.50? (Not the 1.50 x 2.50 x 3.50 that it should be)

 

So all my values have increased by (1) somehow.

The itos function makes no sense to me but I suppose it works if I can find out what is causing it to increase all my values by (1)?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Here's a previous discussion that deals with this topic. The answer I gave is a bit more complicated, preventing weird results and taking into account all the possiblities of dimensional values.

https://community.ptc.com/t5/3D-Part-Assembly-Design/How-to-make-text-with-dimensions/m-p/492558 

View solution in original post

19 REPLIES 19

Lol, it's been a while since this classic issue showed up on the forum.

I am not sure, but your formulas for deriving the string representation of a number seem different from what I am used to.

This thread is my go-to for the hack needed:

Converting Real Numbers to Strings

The ITOS function will round numbers before giving you the results. So ITOS ( 1.50 ) = "2".

You need to use the floor function when generating the integer portion of your number i.e. ITOS ( floor ( D12 ) ).

Another danger of the ITOS function that has annoyed me for years is that ITOS ( 0 ) = "", or that a zero value doesn't yield the zero character, but an empty string.

Here's a previous discussion that deals with this topic. The answer I gave is a bit more complicated, preventing weird results and taking into account all the possiblities of dimensional values.

https://community.ptc.com/t5/3D-Part-Assembly-Design/How-to-make-text-with-dimensions/m-p/492558 

That seems like an insane way to get there. Very "Creo" like lol. However, that worked great. Thank you!

Yeah, it's been a constant complaint forever that there is not a "real2string" function. It makes what could be a one line callout into a block of code.

 

StephenW
23-Emerald II
(To:MORECREO)

https://community.ptc.com/t5/Creo-Parametric-Ideas/RTOS-function-in-relations/idi-p/469120

Please vote on the product enhancement request from 2014...you know it's way older but this is the one with the most votes and isn't archived.

Wow, I'd never seen that idea.

The coding for such a function would be pretty simple. It's the kind of problem one gets for a beginner level programming class.

 

This same idea has more votes:

https://community.ptc.com/t5/Creo-Parametric-Ideas/Real-to-String-in-Relations/idc-p/844600#M18461

and from the last comment on this idea thread, it looks like they will consider incorporating the donated code 😅 into Creo 11?

KenFarley
21-Topaz I
(To:pausob)

Now if only they would fix the ITOS (0) = "" nonsense. If I had programmed a function to convert an integer to a string and didn't properly handle zero, the grade would not have been very good. My guess is that whoever wrote it has a conditional that uses something like IF number > 0 process it, otherwise return nothing. And it's just been left that way since the beginning.

Interesting, never knew that ITOS(0) = "".   In a way, it kind of makes sense... Do you think the original code would have been approved if the programmer made ITOS(0) return the string "zero" 🤣

As another aside though.  I do wonder if the implemented RTOS() function will allow to specify the number of digits and the rounding "rule".  I suppose once you get into the details, it can become rather complicated - see the extensive Wikipedia article on rounding)

KenFarley
21-Topaz I
(To:pausob)

I would expect ITOS (0) to yield "0" (a string with the zero character.

I spoke to soon I guess. I'm am now running into rounding errors with this method. 

 

Ex....  a stock size of .375 x 2.375 x 3.375 will display as .37 x 2.37 x 3.37? 

 

Is there an easy fix for that?

BenLoosli
23-Emerald II
(To:MORECREO)

My guess is you are multiplying your value by 100, which is good for 2 decimal places. For 3 decimal places you need to adjust the formula to multiply by 1000.

Thanks for the reply. I am wanting 2 decimal places, its just not rounding appropriately. If my model stock sizes are .375 x 2.375 x 3.375, then I want my bom to list .38 x 2.38 x 3.38.

 

Instead it gives me .37 x 2.37 x 3.37.

 

Code I'm using is...

 

numdigits = 2
STOCK_SIZE = ""
IF D8 < 1.0
STOCK_SIZE = STOCK_SIZE+ "0."
ELSE
STOCK_SIZE = STOCK_SIZE + ITOS ( floor ( D8 ) ) + "."
ENDIF
STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( floor ( 10^numdigits * ( 1 + D8 - floor ( D8 ) ) ) ), 2, 2 )
STOCK_SIZE = STOCK_SIZE+ " X "

 

IF D9 < 1.0
STOCK_SIZE = STOCK_SIZE + "0."
ELSE
STOCK_SIZE = STOCK_SIZE+ ITOS ( floor ( D9 ) ) + "."
ENDIF
STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( floor ( 10^numdigits * ( 1 + D9 - floor ( D9 ) ) ) ), 2, 2 )
STOCK_SIZE = STOCK_SIZE + " X "

 

IF D10 < 1.0
STOCK_SIZE = STOCK_SIZE + "0."
ELSE
STOCK_SIZE = STOCK_SIZE + ITOS ( floor ( D10) ) + "."
ENDIF
STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( floor ( 10^numdigits * ( 1 + D10 - floor ( D10 ) ) ) ), 2, 2 )

The ITOS function will inherently round for you, so you could simplify your equation to not use the floor function. For example, the last line of your code could instead be:

 

STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( 10^numdigits * ( 1 + D10 - floor ( D10 ) ) ), 2, 2 )

 

 

 

Ken, right on the money again! That seems to be working so far. Thank you so much!

BenLoosli
23-Emerald II
(To:MORECREO)

The problem is in your numdigits and then the extracts, you are only asking for 2 digits.

 

Try this code, it includes Ken's suggestion for the last line.

Change numdigits to how many decimal places you want and it will work.

I had to change the D#'s to match my test model.

 

numdigits = 3
STOCK_SIZE = ""
IF D6 < 1.0
STOCK_SIZE = STOCK_SIZE+ "0."
ELSE
STOCK_SIZE = STOCK_SIZE + ITOS ( floor ( D6 ) ) + "."
ENDIF
STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( floor ( 10^numdigits * ( 1 + D6 - floor ( D6 ) ) ) ), 2, numdigits)
STOCK_SIZE = STOCK_SIZE+ " X "

IF D7 < 1.0
STOCK_SIZE = STOCK_SIZE + "0."
ELSE
STOCK_SIZE = STOCK_SIZE+ ITOS ( floor ( D7 ) ) + "."
ENDIF
STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( floor ( 10^numdigits * ( 1 + D7 - floor ( D7 ) ) ) ), 2, numdigits)
STOCK_SIZE = STOCK_SIZE + " X "

IF D8 < 1.0
STOCK_SIZE = STOCK_SIZE + "0."
ELSE
STOCK_SIZE = STOCK_SIZE + ITOS ( floor ( D8) ) + "."
ENDIF
STOCK_SIZE = STOCK_SIZE + EXTRACT ( ITOS ( 10^numdigits * ( 1 + D8 - floor ( D8 ) ) ), 2, numdigits)

 

BenLoosli
23-Emerald II
(To:BenLoosli)

Remove the FLOOR that is after the ITOS in all 3 to get what you want.

StephenW
23-Emerald II
(To:pausob)

Thanks @pausob. I thought I had seen a better idea than the one I posted but it didn't come up in my search!

Top Tags