×
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!
  • Students Click Here

*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

Jobs

Extract part of a File Name into a custom property using equations with embedded code

Extract part of a File Name into a custom property using equations with embedded code

Extract part of a File Name into a custom property using equations with embedded code

(OP)
Hopefully this is simple for someone who knows VB code.
I am trying to use an equation with embedded code to extract the last 6 characters of a part filename (ignoring the extension) and passing them to a custom property in my part model named "DetailNo" My typical file name would be "Widget_DT_101.sldprt" I need the "DT_101" passed to the "DetailNo" property

I found sample code and copied it into an equation using a downloaded "EquationTools" macro. this was recommended because of potential syntax errors reported in the equation editor when embedding code directly.

The code below works fine. However, it passes the entire file name to the custom property.
I am looking for some help to update it so it simply extracts the last 6 characters regardless of how long the file name is. Or, maybe there is a better way !!

Attached is a sample part file with the equation containing the code. Open the file and check out the properties "DetailNo" I just want the "DT_101"
I also attached the macro to edit the equation

CODE
"FileNameDetailNo"= part.Extension.CustomPropertyManager("").Set("D" & "e" & "t" & "a" & "i" & "l" & "N" & "o", Right(Replace(part.GetTitle, ".sldprt", "", 1, , 1), Len(Replace(part.GetTitle, ".sldprt", "", 1, , 1)) - InStrRev(Replace(part.GetTitle, ".sldprt", "", 1, -1, 1), ".")))

Any help is greatly appreciated
Tom Malinski

RE: Extract part of a File Name into a custom property using equations with embedded code

CODE

s = "Widget_DT_101.sldprt"
p = Right(Left(s, Len(s) - 7), 6) 'result = "DT_101" 

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!


Resources