Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-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
Joined
Aug 5, 2010
Messages
24
Location
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
 
Code:
s = "Widget_DT_101.sldprt"
p = Right(Left(s, Len(s) - 7), 6) [COLOR=#4E9A06]'result = "DT_101"[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top