I searched and I couldn't find a small macro that exports the current tab of a solidworks drawing in dxf format (for laser cutting) with the exact name of the current plan tab as the file name
look at this macro, try it and tell me if it's okay with you
Sub main()
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim montab As Variant Dim montab2 As Variant Dim montab3 As Variant Dim inintern As String Dim Name As String Dim Path As String Dim name As String Dim FilePath As String Dim PathSize As Long Dim PathNoExtension As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
path = PathNoExtension & ".dxf" 'format in which you want to save 'pathMEP = swModel.GetPathName 'FullFileName = Mid(MEPPATH, 1, Len(MEPPATH) - 7) 'Elements = Split(FullFileName, "\", -1) 'FullFileName = Elements(0)
'MessAlert = MsgBox("Do you accept this file?" + FullFileName, vbYesNo) 'If MessAlert = vbNo Then Exit Sub name = name & " - Sheet1" Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager Part.SaveAs2 path, 0, True, False Part.Save2 False Set Part = Nothing swApp.CloseDoc swModel.GetTitle 'Set swModel = Nothing: Set swApp = Nothing
I'm not a specialist so I was able to put the name of the document and the name of the sheet but no better.
Sub main()
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim montab As Variant Dim montab2 As Variant Dim montab3 As Variant Dim inintern As String Dim Name As String Dim Name2 As String Dim Path As String Dim name As String Dim FilePath As String Dim PathSize As Long Dim PathSizeTitle As Long Dim PathNoExtension As String Dim PathNoExtension2 As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc
path = PathNoExtension2 & name2 & ".dxf" 'format in which format you want to save 'pathMEP = swModel.GetPathName 'FullFileName = Mid(MEPPATH, 1, Len(MEPPATH) - 7) 'Elements = Split(FullFileName, "\", -1) 'FullFileName = Elements(0)
'MessAlert = MsgBox("Do you accept this file?" + FullFileName, vbYesNo) 'If MessAlert = vbNo Then Exit Sub 'name = name & " - Sheet1" Set Part = swApp.ActiveDoc Set SelMgr = Part.SelectionManager Part.SaveAs2 path, 0, True, False Part.Save2 False Set Part = Nothing 'swApp.CloseDoc swModel.GetTitle Set swModel = Nothing: Set swApp = Nothing
@gwygwy the proposed macro is far from clean in terms of code, duplicate, useless code... And moreover I don't see how you get the Name of the sheet. The only leaf name is typed in the mano "Leaf1"
To export the file with the name of the tab, see this topic to which I replied without knowing if the answer suited you or not.
Yes the code is not clean, I'm not a pro. I've modified an existing macro where there's still some code that doesn't serve any purpose, but I'm keeping it in case I need it in another macro.
And no, he's not hit as you say, there's a ' in front of the line. So this line is useless.
I recover with get.title, that's all I found. But if you have a macro that works for him, do it you seem to code well.
To retrieve the name of each sheet and export each sheet with the name of the sheet as the export name, you must create a loop on the sheets as on the macro provided in the link. If you're interested I invite you to watch, there's nothing too complicated, 2 years ago I had no knowledge of vba and it's by trial and error that I got into it.
For the macro I made one in the other topic but no answer @Fennec_Flegmatique seems to be absent to the subscribers!