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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

replace a string content through relations

Nash
2-Explorer

replace a string content through relations

Hi everyone,

I need your help to replace a string content with the help of relations.

Ex. If the file name is "Bracket_Housing" then i need the description to be "Bracket Housing".

I use description=rel_model_name() in relation but the output in descriotion with "_" symbol is odd.

My component description is always the file name but without the "_".

I want to eleminate the "_" in the description.

ACCEPTED SOLUTION

Accepted Solutions
Gucio
15-Moonstone
(To:Nash)

Hi,

you can use simply relation

/*****************************************************************************************************************************

POSITION=Search(FILE_NAME, "_")

LENGTH=String_length(FILE_NAME)

NAME=extract(FILE_NAME,1,POSITION-1)+" "+extract(FILE_NAME,POSITION+1,LENGTH-POSITION)

/*****************************************************************************************************************************

So if you define in a FILE_NAME parameter "MY_PART" as a value - you will receive "MY PART" as a value of NAME parameter.

problem begins when your FILE_NAMA contains more than one "_", because Creo relations don't use loop . In that case you have to write relations that will check is there are more "_".

In below example, I assume that FILE_NAME=FIRST_SECOND_THIRD_DESCRIPTION (3x"_")

EXAMPLE:

/*****************************************************************************************************************************

if Search(FILE_NAME, "_")!=0

NAME=extract(FILE_NAME,1,Search(FILE_NAME, "_")-1)+" "+extract(FILE_NAME,Search(FILE_NAME, "_")+1,String_length(FILE_NAME)-Search(FILE_NAME, "_"))

if Search(NAME, "_")!=0

NAME=extract(NAME,1,Search(NAME, "_")-1)+" "+extract(NAME,Search(NAME, "_")+1,String_length(NAME)-Search(NAME, "_"))

if Search(NAME, "_")!=0

NAME=extract(NAME,1,Search(NAME, "_")-1)+" "+extract(NAME,Search(NAME, "_")+1,String_length(NAME)-Search(NAME, "_"))

endif

endif

endif

/*****************************************************************************************************************************

If value of your FILE_NAME parameter contains more than 3 "_" - add additional line that will replace "_" to " "

/****************************************************************************************************************************

if Search(NAME, "_")!=0

NAME=extract(NAME,1,Search(NAME, "_")-1)+" "+extract(NAME,Search(NAME, "_")+1,String_length(NAME)-Search(NAME, "_"))

endif

/*****************************************************************************************************************************

regards

gucio

Krzysztof

View solution in original post

3 REPLIES 3
Gucio
15-Moonstone
(To:Nash)

Hi,

you can use simply relation

/*****************************************************************************************************************************

POSITION=Search(FILE_NAME, "_")

LENGTH=String_length(FILE_NAME)

NAME=extract(FILE_NAME,1,POSITION-1)+" "+extract(FILE_NAME,POSITION+1,LENGTH-POSITION)

/*****************************************************************************************************************************

So if you define in a FILE_NAME parameter "MY_PART" as a value - you will receive "MY PART" as a value of NAME parameter.

problem begins when your FILE_NAMA contains more than one "_", because Creo relations don't use loop . In that case you have to write relations that will check is there are more "_".

In below example, I assume that FILE_NAME=FIRST_SECOND_THIRD_DESCRIPTION (3x"_")

EXAMPLE:

/*****************************************************************************************************************************

if Search(FILE_NAME, "_")!=0

NAME=extract(FILE_NAME,1,Search(FILE_NAME, "_")-1)+" "+extract(FILE_NAME,Search(FILE_NAME, "_")+1,String_length(FILE_NAME)-Search(FILE_NAME, "_"))

if Search(NAME, "_")!=0

NAME=extract(NAME,1,Search(NAME, "_")-1)+" "+extract(NAME,Search(NAME, "_")+1,String_length(NAME)-Search(NAME, "_"))

if Search(NAME, "_")!=0

NAME=extract(NAME,1,Search(NAME, "_")-1)+" "+extract(NAME,Search(NAME, "_")+1,String_length(NAME)-Search(NAME, "_"))

endif

endif

endif

/*****************************************************************************************************************************

If value of your FILE_NAME parameter contains more than 3 "_" - add additional line that will replace "_" to " "

/****************************************************************************************************************************

if Search(NAME, "_")!=0

NAME=extract(NAME,1,Search(NAME, "_")-1)+" "+extract(NAME,Search(NAME, "_")+1,String_length(NAME)-Search(NAME, "_"))

endif

/*****************************************************************************************************************************

regards

gucio

Krzysztof
Nash
2-Explorer
(To:Gucio)

thanks .

but what does

if search(Name,"_")!=0

signify

Gucio
15-Moonstone
(To:Nash)

Becaues FILE_NAME is immutable, NAME parameter must be created. This relation check if in NAME parameter character "_" occurs. if YES (!=0) rest of relation is executed

regards

gucio

Krzysztof
Announcements
Business Continuity with Creo: Learn more about it here.

Top Tags