Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Have parameter that is 914klm5ft12or3467 that is a string
i want to filter numbers and put in a parameter that is REAL like 9145123467
Any suggestions?
exactly how does the parameter evaluate?
this parameter evaluates some extracted values from tables "extract(TABLE_1,1,3)", "extract(TABLE_1,3,6)"
in old files case evaluates the modelname parameter (that is a string) and compose with extracts the "NUMBERCAD" parameter that drivers the numbering in pdm
in othe case i have to extract only numbers to acquire gps coordinates or absolute coordinates (that are comma separated values)
all those things are acquired as strings and shall be filtered and turned in to numbers
Are the occurences of numbers in that string random? Is the string's length also random?
I can only see this in an extensive -IF- clause that evaluates each entry in the string as a valid "numeric" string that represents a number and next, determine the length of the full number string... and create variables, again based on an extensive -IF- to determine the value of each string"number".
Something like:
(capture every character as a variable)
(evaluate every variable purging alpha characters)
...
if A=="1"
AN=1
endif
if A=="2"
AN=2
endif
...
(Determine the string length)...
(multiply each variable by 10,100, 1000, 10000, 100000, etc...)
(add all the variable together)
Would I want to write this? NOPE!
We need a simple function that will parce a value from a text string by purging non-numeric characters.
As for the OP's request, I would reverse the requirements by making the string from the values rather than making the value from the string.
NUMBERCAD=rel_model_name
than from this parameter "NUMBERCAD" that is a string (because model_name is a string) try to filter and get only numbers.
in creo relation there in no way to extract FROM a string TO a number, but is only possible to do the opposite with this command "extract(PARAMETER,3,6)" (extract from third value of parameter 3 following values)
also i should reverse the requirements but you can't drive new file name in creo and you can't put filters on creation
Indeed, not directly. But you can query each character in a string and see if it is a string equivalent to a number. If the query returns true, you assign a number to a new variable and multiply it according to the position in number string.
in case of user fantasy he puts all the caracters on the keyboard as many he is inspired to do
but i care only for numbers so the filename and number should be real numbers
in case of acquire gps coordinates in other parameters is the same, or coordinates from a fem analisys
Hi
Using the jlink(java)/weblink(java script)/VBA(vb) toolkits provided with Creo it should be a fairly simple task.
The must elegant solution would be to use the regular expressions API.
Unfortunately you can not call regex functions from within Creo relations (what a shame), but they are supported in most programing languages.
Here is how the code might look like in VB.NET
Imports System.Text.RegularExpressions
Dim mystr As String = "914klm5ft12or3467"
MsgBox(Regex.Replace(mystr, "[^\d]", ""))
Hello,
So then, length of the string remains as an issue. One of two issues actually. You can use string_length relation function to find out how long is the string.
If the length of the part name varies too much, and you can't tell what could be the possible maximum length of the string in characters, then I can't really think of any solution. But if you can set the cap number that matches your longest string length then you might be able to get the numbers after it goes through all relations. While adding dummy numbers or characters to each of your strings so they always match the preset length.
Imagine you will for example have to test 48 characters in total, and you will be testing them all in such a way that Antonius has suggested above. Some will and some won't be numbers, now how to go around with the concatenation of the numbers into a new string? That's the question.
I'll stop trying to pull you into the problem right here, cause it might be too huge. Converting a string number into a real number is another one, but it might just be a piece of cake compared to the first one.
Jakub, you would use a counter as you were parsing numeric characters. Every time you get a hit, you add 1 to the counter. At the end of the string, you know how many number characters you accumulated. At that time you know what the multiplyer needs to be for every single numeric value.
Good idea. Now to figure out how to do the concatenation of numbers. This code if ever made will be long like forever.
I won't tackle this one. But it is a good discussion none the less.
It does add to the argument that the functions in Creo are seriously lacking by today's standards.
Yeap, I won't bother writing the whole code for this either, but I thought about this for few more mins, and it really might not be that hard after all.
First of all, there can be only up to 31 chars in a partname. That means the counter would only require 31 If statements, each with a little long condition to check if the character is any of the ten numbers.
Could really use a For loop statement there.
Then also, I figured out that during the concatenation of the first string to separate all number characters, it's possible to pass in empty values. See the folowing picture.
But the number of numeric characters can be in theory 31 as well. So that makes 31 new If statements while each of these need to be converted to a real value, that makes 10 another If statements under each of these 30 Ifs. So, that's another 161 If statements. These could give you the information about position of the character in this new numeric string, which would make it easier to convert it to a real number at the end. You could actually do the conversion within these 31 If statements.
Umm, does that mean it would take about 200 If statements in total? While normally it could take just 3 functions, where each function would contain just one For loop. It sounds too silly.
Well, on the other hand if you can write this for just 3 characters long string, and make it work, then for a 31 characters long string it's all just a matter of copying, and pasting.
A few minutes thinking huh
I like the concatinated_string. Forgot about that.
But you wouldn't need 31 if's... you only need 10 if's to parse numbers and the rest fall under "else".
You just have to be careful with 0 (zero) because in some cases is returns an empty string (I forget which cases).
I really think would need this many Ifs, 10 for each of 31 chars. Of course these 10 Ifs would be relevant only to the character containing a number, but you would still need to define them also for characters not containing letters.
This comes from few mins of dumb thinking. That means I could be wrong.
The example you wrote up above there in one of your posts should work fine with zeros.
I'd base it on something like this:
/*Without comments
digitlist = "0123456789"
value = 0
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-0,1)-1
value = value+digit_found
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-1,1)-1
value = value+digit_found*10
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-2,1)-1
value = value+digit_found*100
digit_found = search(digitlist,extract(rel_model_name(),len(rel_model_name)-3,1)-1
value = value+digit_found*1000
d0=value
This was to clip numbers at the ends of parameters. In your case I would have the logic start with the first one and use
IF digit_found <> 0
value = value*10 + digit_found.
ENDIF
Then wrap the digit_found ... and IF digit_found ... in an
IF len(parameter)> whatever_step
digit_found ...
IF digit_found...
value = ...
ENDIF
ENDIF
Repeat for whatever_step = 1 to whatever the maximum number of characters you expect.
Since it's an integer, ITOS() should work OK if you need a string.
This was exactly what I was looking for. In my case, I wanted to convert the last 3 characters (string) from our part name to a number.
I have shortened the code just a little bit more:
DIGITS = "0123456789"
TEMP = 0
TEMP = TEMP+(SEARCH(DIGITS,EXTRACT(REL_MODEL_NAME,STRING_LENGTH(REL_MODEL_NAME)-0,1))-1)*1
TEMP = TEMP+(SEARCH(DIGITS,EXTRACT(REL_MODEL_NAME,STRING_LENGTH(REL_MODEL_NAME)-1,1))-1)*10
TEMP = TEMP+(SEARCH(DIGITS,EXTRACT(REL_MODEL_NAME,STRING_LENGTH(REL_MODEL_NAME)-2,1))-1)*100
You can extend this for as long as you like.
Just one warning, there is no error checking!
Keep in mind that you're going to get a negative 1 any time this encounters something other than a number (anything not present in DIGITS.)
That's true, but that will never happen with the partnumber scheme we are using 🙂