Part Name Extraction for DXF Macro

  • Follow


I need some help in a bad way.  I have a macro that will save a part as
a DXF if certain conditions are true.   My problem is the way that this
macro sets the file name.  I have to save my part in a certain folder
in order this macro to work which is not the way I need it to work.  I
need a way to take this parth

D:\Storage\DBWorks\TestPart.SLDPRT

and extract this

TestPart.SLDPRT  -  or just this  -  Testpart.

I need to be able to do this automatically, no matter what directory
the part is located in.

Will one you you guys help me out.  I am no expert by any strech of the
imaginatyion.  My macro is posted below.  It will not work in your
version of solidworks because you do not have the add-in, I even
covered up my library name so as to not revela too much,but I am sure
someone will still be able to help me out.



Declare Sub ExportDXFFile Lib "???????" (ByVal fname As String, ByVal
tname As String)

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()

    Dim FileName                As String
    Dim FileNameNoExt           As String
    Dim DrwPathName             As String
    Dim DxfPathName             As String
    Dim Nested                  As String

    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc

    ModelPathName = swModel.GetPathName

    'parts can only be stored in this location -
D:\Storage\DBWorks\TestPart.SLDPRT
    'the -19 removes the file path and just leaves the file name
    'will not work in another directory unless the -19 is changed
    FileName = Right(ModelPathName, Len(ModelPathName) - 19)

    'takes the file name TestPart.SLDPRT and removes the extension and
    'just leaves - TestPart.
    FileNameNoExt = Left(FileName, Len(FileName) - 6)

    'establishes the path and the file name for the dxf
    DxfPathName = "C:\Documents and Settings\DHales\Desktop\" +
FileNameNoExt + "dxf"

    'exportdxffile is part of the library that i have as an add-in
    'this is the location of the drawing template used to insert the
flat pattern of the part 1:1
    'and then save the dxf
    ExportDXFFile DxfPathName,
"Y:\DBWORKS_SERVER\PAR\FlatPattern_FullScale.DRWDOT"

End Sub

0
Reply inthepickle (16) 3/16/2006 8:45:25 PM

There is a reverse InStr function that can work nicely for parseing
filenames.

0
Reply TOP 3/16/2006 9:04:32 PM


can you give me the specific code to extract a file name from a path?

0
Reply inthepickle 3/16/2006 9:22:37 PM

Look up InStr in the API help for VBA. Then look at related items.
Search for the \ and then the .. It is pretty simple once you find the
function.

0
Reply TOP 3/16/2006 9:50:25 PM

-------------------------------------------
Function GetActiveDocName()
  Dim FilePathName As String
  FilePathName = CurrentDoc.GetPathName ' This is the whole string-including 
the path
  If Not FilePathName = "" Then GetActiveDocName = StripName(FilePathName)
End Function
-------------------------------------------
'Recursive function to strip the file name from the path of the current 
part.
'INPUT: string, the file name including path
'RETURN: string, file name only
Function StripName(FName As String) As String
  If Not (Right(FName, 1) = "\") Then
      StripName = StripName(Left(FName, Len(FName) - 1)) & Right(FName, 1)
  Else
    FilePath = Left(FName, Len(FName) - 1) ' Grab the full path while we 
have it separated
    StripName = ""
  End If
End Function
-------------------------------------------
  WT

"inthepickle" <inthepickle@gmail.com> wrote in message 
news:1142544157.118279.247720@j52g2000cwj.googlegroups.com...
> can you give me the specific code to extract a file name from a path?
> 


*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
0
Reply Wayne 3/16/2006 9:52:47 PM

Here's another way...

PathAndFile = "D:\Storage\DBWorks\TestPart.SLDPRT"
'(you set this somehow)

If Dir(PathAndFile) <> "" Then
   JustTheFileName = Dir(PathAndFile )
   PathAndFileNameWithNoExtension = Left(PathAndFile , (Len(PathAndFile
) - 7))
   JustThePath = Left(PathAndFile , (Len(PathAndFile ) -
len(JustTheFileName)))
EndIf



In your example, here are the results:
JustTheFileName  = "TestPart.SLDPRT"
PathAndFileNameWithNoExtension = "D:\Storage\DBWorks\TestPart"
JustThePath = "D:\Storage\DBWorks\TestPart"

0
Reply Fye 3/17/2006 4:31:01 AM

>      StripName = StripName(Left(FName, Len(FName) - 1)) & Right(FName, 1)

Haha :-D OK, recursion works of course but IMO it is like killing flies with 
a sledgehammer in this case. How abot this

Dim fullPath As String
fullPath = model..GetPathName

Dim slashPosition As Integer
slashPosition = InStrRev(fullPath, "\") 'Gets the position of last \

Dim fileName as String
fileName = Right(fullPath, Len(fullPath) - slashPosition)

-h- 


0
Reply Heikki 3/17/2006 7:08:36 AM

6 Replies
348 Views

(page loaded in 0.102 seconds)

Similiar Articles:













7/27/2012 4:55:25 PM


Reply: