STOCK SIZE PARAMETER IN MODEL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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)?
Solved! Go to Solution.
- Labels:
-
General
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
That seems like an insane way to get there. Very "Creo" like lol. However, that worked great. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I would expect ITOS (0) to yield "0" (a string with the zero character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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 )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Ken, right on the money again! That seems to be working so far. Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Remove the FLOOR that is after the ITOS in all 3 to get what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks @pausob. I thought I had seen a better idea than the one I posted but it didn't come up in my search!
