Jump to content

Pro Engineer/Repeat Region Relation Example: Replacing characters in parameters

From Wikibooks, open books for an open world

Simplified for readability, base on from http://communities.ptc.com/message/240198#240198 (external link), which follows this.

/***************************************************************************************************
NAME = FILE_NAME
OLD = "_"
NEW = " "

/* This does three substitutions of NEW for OLD. Relations don't loop, so manual loop unrolling is required. 

if Search(NAME, OLD)!=0

NAME=extract(NAME,1,Search(NAME, OLD)-1)+NEW+extract(NAME,Search(NAME, OLD)+1,String_length(NAME)-Search(NAME, OLD))

if Search(NAME, OLD)!=0

NAME=extract(NAME,1,Search(NAME, OLD)-1)+NEW+extract(NAME,Search(NAME, OLD)+1,String_length(NAME)-Search(NAME, OLD))

if Search(NAME, OLD)!=0

NAME=extract(NAME,1,Search(NAME, OLD)-1)+NEW+extract(NAME,Search(NAME, OLD)+1,String_length(NAME)-Search(NAME, OLD))

endif
endif
endif

from http://communities.ptc.com/message/240198#240198 (external link)

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

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