Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Stripping last 3 digits out of the file name 1

Status
Not open for further replies.

sirbartoo

Mechanical
Sep 8, 2005
53
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?
 
Replies continue below

Recommended for you

Hello,

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.
 
You should be able to do this through a design table using excel functionality. It will have to be done in the context of a part or assembly though. Not actually in the drawing file

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

 
TO CLARIFY, I HAVE A PACKAGE OF ~100 DETAIL SHEETS. ALL SHEETS ARE IN SEPERATE FILES. (EX. 1234-123-D005.SLDDWG). I WOULD LIKE TO SET UP A PROPERTY THAT WILL LOOK AT THE "005" IN THE FILE NAME AND PLACE IT IN THE BORDER AUTOMATICLY. USING A DESIGN TABLE IN A PART FILE IS NOT THE DIRECTION I WOULD LIKE TO GO. I WOULD LIKE ALL THE INFO TO BE IN THE DRAWING FILE, NOT THE PART FILE. SOMETIMES I HAVE CONFIGS IN MY PARTS AND ONE PART FILE MAY HAVE 2 DIFFERENT DRAWING FILES IN THE SAME PACKAGE.
 
What you are looking for can be easily handled with a macro. One caveat is that it will populate all 100 of your existing drawings in one swoop. Have a look at Lenny Kikstra's site:

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
 
I GOT THE PROGRAM TO ADD THE CUSTOM PROPERTY, I JUST CAN'T GET IT TO GIVE ME JUST THE LAST 3 DIGITS. I AM A MECHANICAL ENGINEER, THIS MAY BE A LITTLE ABOVE MY HEAD. ARE THERE JUST A FEW VARIABLES I SHOULD CHANGE?
 
Find this line of code in the macro:
Code:
      ModelName = NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0)

and replace it with this:
Code:
      ModelName = RIGHT(NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0),3)

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
 
Shaggy, we're almost there. Everything works, but.... in a drawing sheet, when you look at the top of the screen, it will read "somefilename - sheet1". the program is picking up the SHEET1 for some reason. The only place I will be running this macro is in a drawing. My file name is "3571-500-D002.slddrw". The macro gives me ET1 in the new custom property, which is the end of SHEET1, which must be associated to the file name in some way. I do not use multiple sheets in a drawing file.

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.
 
I found a string that seems to work.

ModelName = Mid(NewParseString(UCase(Document.GetTitle), ".SLD", 0, 0), 11, 3)

It works, but I'm not sure if it is technicaly correct.
 
I think that whatever works... is good enough. The mid function appears to start at whatever character you decide. In your case 11 and grab the characters in the next 3 spaces. As long as all of your filenames are the same format, it will work for you.

-Shaggy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor