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

Anyone get real fancy with part parameters and relations?

SOLVED
dunebuggyjay
Granite

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

Re: Anyone get real fancy with part parameters and relations?

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

Re: Anyone get real fancy with part parameters and relations?

Edit:

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

Re: Anyone get real fancy with part parameters and relations?

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

 


Steve Williams
Pro/E Version 15/16 (Circa 1995/1996)

Re: Anyone get real fancy with part parameters and relations?

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

Re: Anyone get real fancy with part parameters and relations?

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

Re: Anyone get real fancy with part parameters and relations?

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.

Re: Anyone get real fancy with part parameters and relations?

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.

Re: Anyone get real fancy with part parameters and relations?

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...

 

Announcements