Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

TomMalinski

Mechanical
Aug 5, 2010
24
0
0
US
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
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top