Skip to main content
14-Alexandrite
December 4, 2020
Solved

Anyone get real fancy with part parameters and relations?

  • December 4, 2020
  • 3 replies
  • 3493 views

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

 

 

Best answer by BenLoosli

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)

 

3 replies

23-Emerald IV
December 4, 2020

Edit:

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

23-Emerald III
December 4, 2020

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

 

BenLoosli23-Emerald IIIAnswer
23-Emerald III
December 4, 2020

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)

 

14-Alexandrite
December 4, 2020

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
21-Topaz I
December 4, 2020

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.