Stripping last 3 digits out of the file name
Stripping last 3 digits out of the file name
(OP)
Using custom properties or linked properties in a drawing sheet, does anyone know of a way to take a file name, ex. (1234-014-D002.slddwg, 1234-014-D003.slddwg, 1234-014-D004.slddwg) and strip out the 002, 003, 004 to create a sheet number?






RE: Stripping last 3 digits out of the file name
Just to clarify...
You have 3 drawings: 1234-014-D002.slddrw, 1234-014-D003.slddrw, and 1234-014-D004.slddrw
You want to somehow merge them into 1 drawing called:
1234-014.slddrw, which has 3 sheets (D002, D003, and D004)
Is this correct? If so, the only way I know how would be an API solution.
RE: Stripping last 3 digits out of the file name
Matt
CAD Engineer/ECN Analyst
Silicon Valley, CA
sw.fcsuper.com
Co-moderator of Solidworks Yahoo! Group
RE: Stripping last 3 digits out of the file name
First create a custom property called filename, in that property, assign it a value of $PRP:"SW-File Name". Then create a custom property called drawing_number. Now create a design table and let it "auto-create".
Within the design table, you will need to be feeding the drawing_number cell by manipulating the filename cell. You will probably have something like =LEFT(A2,(LEN(A2)-3)) Where A2 is replaced by the actual cell number from the filename cell. To translate what the excel jargon is doing: The LEN(A2) is counting the number of characters in the A2 cell. LEFT is keeping only the number of cells requested, n this case, LEN(A2) minus 3.
I think you can make this technique work. Good Luck.
-Shaggy
RE: Stripping last 3 digits out of the file name
RE: Stripping last 3 digits out of the file name
http
specifically his PartNoProperty macro. This macro was written by Lenny for me to perform a task similar to what you are in need of. I needed a macro that would grab the file name and strip of the .sldxxx and create a custom property called SP:PART_NR to be populated by the stripped down filename. The macro will do this for selected files in a directory. With a little code manipulation, you can get this to do exactly what you want.
-Shaggy
RE: Stripping last 3 digits out of the file name
RE: Stripping last 3 digits out of the file name
CODE
and replace it with this:
CODE
The going's on of the above code is this (working from inside out):
Document.GetTitle is getting the file name of the active file.
The UCase is changing whatever it got to all uppercase.
The NewParseString is looking through the filename and until it finds .SLD. When it finds it, it chops off the .SLD and anything after it.
The Right and the ,3 is grabbing just the 3 right most characters.
It is then assigning this result as the variable ModelName.
ModelName is used later in the macro to fill in the custom property.
You can access this code from within solidworks by going to Tools>Macro>Edit and then selecting the macro PartNoProperty.swp Then within the VBeditor go to forms and hit the "+" to expand the tree. Right click the "FormPartNoProp" and select view code.
were you able to update the text file to change the custom property from SP:PART_NR to <a name of your choosing>?
-Shaggy
RE: Stripping last 3 digits out of the file name
ModelName = RIGHT(NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0),3)
What does the 0, 0) mean? maybe I can change this to look from left to right.
RE: Stripping last 3 digits out of the file name
ModelName = Mid(NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0), 11, 3)
It works, but I'm not sure if it is technicaly correct.
RE: Stripping last 3 digits out of the file name
-Shaggy