Skip to main content
14-Alexandrite
Dec 4, 2020 1:54 PM UTC
Solved

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

 

 

BenLoosliAnswer
23-Emerald III
Dec 4, 2020 2:16 PM UTC

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)

 

7 replies

TomU
23-Emerald IV
Dec 4, 2020 2:01 PM UTC

Edit:

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

Translate
StephenW
23-Emerald III
Dec 4, 2020 2:03 PM UTC

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

 

Translate
BenLoosli23-Emerald IIIAnswer
23-Emerald III
Dec 4, 2020 2:16 PM UTC

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)

 

Translate
14-Alexandrite
Dec 4, 2020 2:22 PM UTC

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

Translate
Chris3
21-Topaz I
Dec 4, 2020 4:01 PM UTC

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.

Translate