|
|
Part Name Extraction for DXF Macro
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: Part Name Extraction for DXF Macro - comp.cad.solidworks ...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. Save as DWG macro - comp.cad.solidworksPart Name Extraction for DXF Macro - comp.cad.solidworks ... 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. Way to extract custom properties out of a SW file via VBA? - comp ...Part Name Extraction for DXF Macro - comp.cad.solidworks ... Way to extract custom properties out of a SW file via VBA? - comp ..... GetCustomProperty("","Property Name ... SolidWorks To DXF/DWG Mapping, not used much? - comp.cad ...Part Name Extraction for DXF Macro - comp.cad.solidworks ... InStrRev(name, "-") - 1) or re-download the updated macro. Part names ... dwg Files) 2D to 3D Conversion ... emacs lisp tutorial: list & vectors - comp.emacsPart Name Extraction for DXF Macro - comp.cad.solidworks ... 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. Bash: strip file path and file extension from a file name in a ...Part Name Extraction for DXF Macro - comp.cad.solidworks ... 'INPUT: string, the file name including path 'RETURN: string, file name ... Bash: strip file path and file ... extract BOM data to Excel - comp.cad.solidworksI have done this with a macro.In a nutshell the macro reads every single instance ... It works because I name configurations with the part name. The reason I do it this way ... Convert Solidworks Assembly Drawing to AutoCAD layout - comp.cad ...... name = Left(name, InStrRev(name, "-") - 1) or re-download the updated macro. Part names ... pdf to dxf ,dwg - comp.cad.solidworks... drawing to wmf ... pdf to dxf ,dwg ... Wildfire 4.0 DXF output - comp.cad.pro-engineerPart Name Extraction for DXF Macro - comp.cad.solidworks ... Wildfire 4.0 DXF output - comp.cad.pro-engineer... our engineers have upgraded to Wildfire 4.0 and the DXF ... Req help : macro to save current read-only model to "Work" area ...Part Name Extraction for DXF Macro - comp.cad.solidworks ... API / Macro Help - comp.cad.solidworks I recorded a macro to save our drawing files as DWG ... Part Name Extraction for DXF Macro - comp.cad.solidworks ...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. Part Name Extraction for DXF Macro - solidworks - Mofeel Groupssolidworks, Part Name Extraction for DXF Macro . comp.cad.solidworks - SolidWorks 7/27/2012 4:55:25 PM
|
|
|
|
|
|
|
|
|