×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Extract String at first comma BACK from pos 25?

Extract String at first comma BACK from pos 25?

Extract String at first comma BACK from pos 25?

(OP)
Hello gentlemen, I have a question about parsing strings so that I can properly format the DWG title in the new formats I'm working on.

We use your typical ASME Y14.100 drawing title scheme: Text, Text, Text, Text, Text
Our DWG titles are limited to 50 characters (legacy software of course) which perhaps simplifies things a bit because we know the absolute limit to the title.
I have a parameter "TITLE" which historically has been used to contain the entire dwg title.
I also have two other parameters DWG_TITLE1 & DWG_TITLE2 to accept the output of my relation.

My thought is to run a relation that checks the TITLE parameter for string_length, and if greater than 25, at the 25th position, go BACK to the previous comma and extract everything from that point to the end of the string.... Put that output into DWG_TITLE1 and the rest into DWG_TITLE2.

Now, I have almost zero prior experience with these relations beyond x+y=z but I've managed a little progress using Google. So far, I've got:

IF string_length(TITLE) > 25

DWGTITLE1 = extract(TITLE,1,search(TITLE, ","))+extract(TITLE,search(TITLE, ","),string_length(TITLE)-search(TITLE, ","))
DWGTITLE2 = extract(TITLE,string_length(DWGTITLE1),search(extract(TITLE,25,string_length(TITLE)),",")-1)


And basically I'm not having any luck... I was hoping for something like:

TITLE = PLATE, L-ARM, CONVEYOR, RECEIVING, PANEL, BODYWELD
DWGTITLE1 = PLATE, L-ARM, CONVEYOR,
DWGTITLE2 = RECEIVING, PANEL, BODYWELD

But what I'm getting is something illogical. Before I spend too much time on this I was hoping some of you relation pro's could make sure I'm headed in the right direction? I'm not sure how to get Creo to start looking for commas AT a certain position or how to go in a particular direction (from pos25 --> pos1). Also, I suppose one other requirement is that it extracts one character AFTER the first comma back from pos 25. And now that I'm typing this, I suppose I'll also need it to delete the first space after that comma.

Boy, this is quite an issue we're left to deal with... It;s astonishing to me that a simple, workable text wrap hasn't yet been incorporated into Creo 4 (M080),

Any help is greatly appreciated!

Hallec

I'm not a vegetarian because I dislike meat... I'm a vegetarian because I HATE PLANTS!!

Replies continue below

Recommended for you

RE: Extract String at first comma BACK from pos 25?

Lacking loops and arrays, this isn't something that Creo relations can do, and therefore cannot be processed entirely within Creo.

My first take would be to reverse the operation and make title1 and title2 the driving parameters and make title = title1 +", "+title2 within an IF statement =>

title = title1
IF exists(title2)
title = title1 + ", " + title2
ENDIF

If that won't work for you, if allowed, I'd use AutoIT and make a couple of mapkeys to decrease the effort to manipulate the Creo interface. Alternates include using VBA from Excel or Word to run the mapkey using "Sendkeys" https://docs.microsoft.com/en-us/office/vba/langua...

Final alternate is to create a mapkey that sends the data out using a @SYSTEM statement. For that you'll need to know MS CMD language to create a CMD script to run to handle the text manipulations. Example #SYSTEM use: https://community.ptc.com/t5/System-Administration...

RE: Extract String at first comma BACK from pos 25?

Not very elegant since as 3DDave says, Creo does not have looping or array code.
I tested it with both of the Title strings to get different lengths and these seem to work.
I will NOT guarantee it will work with any string thrown at it.
I did stop after extracting the first 4 words, since I figured with 5 letters per word and 2 additional characters ', ' that would hit your 25 limit.
Have fun with it, play with it, it may serve your needs for years.


/*TITLE = 'PLATE, L-ARM, CONVEYOR, RECEIVING, PANEL, BODYWELD'
TITLE = 'BRACKET, CONVEYOR, PANEL, RECEIVING, BODYWELD'

len=string_length(title)
text1=extract(title,1,search(TITLE, ",")-1)
len1=string_length(text1)
tt1=extract(title,len1+3,len-len1-2)
text2=extract(tt1,1,search(tt1, ",")-1)
len2=string_length(text2)
tt2=extract(title,len1+len2+5,len-len1-len2-4)
text3=extract(tt2,1,search(tt2, ",")-1)
len3=string_length(text3)
tt3=extract(title,len1+len2+len3+7,len-len1-len2-len3-6)
text4=extract(tt3,1,search(tt3, ",")-1)
len4=string_length(text4)

if (len1+3+len2+3+len3) >25
maxlen1=len1+3+len2+3+len3
else
maxlen2=len1+3+len2+3+len3+3+len4
endif

If maxlen1 < 25
DWGTITLE1 = extract(title,1,len1+2+len2+2+len3)
DWGTITLE2=extract(title,len1+3+len2+3+len3+2,len-len1-2-len2-2-len3-3)
else
DWGTITLE1 = extract(title,1,len1+2+len2)
DWGTITLE2=extract(title,len1+3+len2+2,len-len1-2-len2-2)
endif

"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli

RE: Extract String at first comma BACK from pos 25?

(OP)
Holy... Hey looslib, that's great!! Thank you for putting that down for me. I may need to tweak it here or there, but after initial testing it looks like that works!

I owe you a beer.

I'm not a vegetarian because I dislike meat... I'm a vegetarian because I HATE PLANTS!!

RE: Extract String at first comma BACK from pos 25?

(OP)
Hey, so I just have one final question... If I wanted to ensure that the comma at the end of the line break was always included (e.g. BRACKET, CONVEYOR, <2ND LINE> PANEL,...) how would I go about doing that? Currently what happens is that the comma at the end of line 1 gets removed. I went through and tried changing some of the values for text1, text2, etc., but now I get the comma and the first two letters of the first word on the second line are being truncated.

This is great and it gives me a really good starting point. Thanks again.

I'm not a vegetarian because I dislike meat... I'm a vegetarian because I HATE PLANTS!!

RE: Extract String at first comma BACK from pos 25?

Change these lines:
DWGTITLE1 = extract(title,1,len1+2+len2+2+len3+1)
DWGTITLE1 = extract(title,1,len1+2+len2+1)
That will grab the comma that already exists 1 character beyond the word lengths.

The other method would be to add just the comma:
DWGTITLE1 = extract(title,1,len1+2+len2+2+len3+',')
DWGTITLE1 = extract(title,1,len1+2+len2+',')

"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli

RE: Extract String at first comma BACK from pos 25?

(OP)
I think I figured it out...

I tweaked some of the extract strings and changed the position or length values. It works!

I may need to add a LEN4 as well as a DWGTITLE3 IF/THEN scenario but otherwise this works great!

I'm not a vegetarian because I dislike meat... I'm a vegetarian because I HATE PLANTS!!

RE: Extract String at first comma BACK from pos 25?

(OP)
I need some additional help on this... This works for the most part, but there are a couple of additional conditions that I need to incorporate and if anyone can help, I'd greatly appreciate it.

1) The end of each line, whether it be two or three lines (but not one line - which rarely will happen), needs to end with a comma, which will be a part of the TITLE parameter (so, it doesn't need to be added... It just needs to be not removed).
Light,_Utility,_Garage,
Site 2,_Northeast Installation,
C-Series 3

2) The space after the last comma on lines one and two (because there's never more than three lines) must be removed in order to maintain proper justification. It would also be acceptable (and maybe even preferable) to remove ALL spaces after commas.
Light,_Utility,_Garage,
Site 2,_Northeast Installation,
C-Series 3

OR
Light,Utility,Garage,
Site 2,Northeast Installation,
C-Series 3

I think that's it... Once those two variables are accounted for, this will be ready for testing within the department. Many thanks to all who have helped already.

Hallec

I'm not a vegetarian because I dislike meat... I'm a vegetarian because I HATE PLANTS!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close