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

Anyone get real fancy with part parameters and relations?

dunebuggyjay
12-Amethyst

Anyone get real fancy with part parameters and relations?

Hi guys, 

 

Lets say i have a part file called: N12345-2000.prt

 

It is stored as a parameter called rel_model_name

 

I would like to take this parameter, and remove the first 7 characters of the name. 

 

So I could now have this new parameter (lets call it "detail") which would just be 2000 in my parameters.

 

Is this possible? 

 

Thanks,

Jay

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

If it is always 7 characters before your substring, it is easy.

Detail = extract (rel_model_name,8,11)

If the number of characters varies, then you get into using the fndstr function to search the rel_model_name for your '-', which will return the start position for the extract command.

stpos = fndstr(rel_model_name,'-')

detail = extract(rel_model_name, fndstr+1,fndstr+5) assuming the detail part is always 4 characters.

If that changes, too, then there is the strlen function to get the total length.

endpos = strlen(rel_model_name)

detail = extract(rel_model_name, fndstr+1,endpos)

 

View solution in original post

7 REPLIES 7
TomU
23-Emerald IV
(To:dunebuggyjay)

Edit:

Sorry, I misread your question.  Yes, as @StephenW explained, this is pretty straight forward to do.

StephenW
23-Emerald II
(To:dunebuggyjay)

In the relations, use the Extract command to get what you want from the existing parameter.

I think this post has some good examples.

https://community.ptc.com/t5/Part-Modeling/EXTRACT-relations-function/m-p/577971

 

If it is always 7 characters before your substring, it is easy.

Detail = extract (rel_model_name,8,11)

If the number of characters varies, then you get into using the fndstr function to search the rel_model_name for your '-', which will return the start position for the extract command.

stpos = fndstr(rel_model_name,'-')

detail = extract(rel_model_name, fndstr+1,fndstr+5) assuming the detail part is always 4 characters.

If that changes, too, then there is the strlen function to get the total length.

endpos = strlen(rel_model_name)

detail = extract(rel_model_name, fndstr+1,endpos)

 

Yes! this is exactly what I needed. 

 

I added a simple line:

detail = extract(rel_model_name,8,4) to get what i needed in the detail field.

 

Thanks for all the help guys!

 

Jay

Chris3
20-Turquoise
(To:dunebuggyjay)

Be aware that if you try and extract more characters than are in the string (ie you have parts that don't follow the same naming scheme) it will return a Null and you will get nothing. For this reason you might want to check the length first.

KenFarley
21-Topaz I
(To:Chris3)

Seconded here. All it takes is someone not remembering and leaving out zeroes (i.e. using 007 instead of 0007) and you'll get nothing. You might even, if you really want to play with relations, add the leading zeroes to the result if they are needed.

BenLoosli
23-Emerald II
(To:BenLoosli)

I thought about what I wrote a little more and realized I mixed PTC Creo functions with some Unigraphics GRIP coding. I used UG for 20 years before being switched to Pro/Engineer. ☺

 

As was discovered, the extract command is start position and length of extraction. So that makes this the valid statement:

Detail = extract (rel_model_name,8,4)

 

Fndstr is a GRIP function, In Creo it is the Search function.

dashpos = search(rel_model_name, '-') will set dashpos to the location within the string. You may need to add 1 to that value to get the next character as the start position.

String_length(parameter) will return the total number of characters in the parameter.

For example if rel_model_name is 'This is a name', string_length(rel_model_name) would return 14. when set to a parameter it can be used in the conjunction  with other functions and parameters..

As Ken mentioned, If your string is less than what you have created the relation to look for, it will return an error.

 

Here is the link to a CS article that details the functions available in Creo.

Article - CS111494 - Detailed Information Regarding the Functions Available for Use in Relation (ptc.com)

 

Top Tags