Hi Guys
When using Solidworks Task Scheduler, does anyone know how to include the revision number of the drawing to the file name when I export drawings to DXF or DWG files?
Kind Regards Dee
Hi Guys
When using Solidworks Task Scheduler, does anyone know how to include the revision number of the drawing to the file name when I export drawings to DXF or DWG files?
Kind Regards Dee
Not sure if this is possible with TS but yes can be easily done with a macro. There are many up here on this forums. If you need I can find one for you.
Hi Guys
I do have the Macro to convert a file to dxf which will have the revision in it's file name but I want to do a batch export to dxf using task scheduler or maybe another macro?
Cheers Dee
Hi Deepak
That works great, is there a way I can select which file I want to export? I have alot of drawings and I only want to export DXF's for sheet metal components?
Cheers Dee
Well macro can be made to find if the drawing is of sheet metal part or not.
Alternatively hide the drawings you don't want to convert or move them out of folder and then run the macro.
Do you want me to make that macro which will save first sheet as PDf and Second as DXF using he revision value condition you've set??
Well, i like you to help me. If you make it for me that would be great. If you help me make it that would be nice to! ;-) The macro below saves the first sheet as .pdf. That works fine. But it also saves all sheets to .dxf. I only want to save the second sheet as .dxf if there is a second sheet. Can't get it done...
I solved my problem. When you open a drawing in solidworks and chose to 'save as' you can select .dxf. When you do so you get File Export options. I set the option for 'only save active sheet'. Problem solved!
Thanks any way. Maybe you can tell me how to do it programily?
Hi Robin, I've the code ready but it is failing when there is no second sheet available. So trying to figure out what to do there.
Hello Deepak, you can count the sheets from GetSheetNames.
vSheetName = swDrawDoc.GetSheetNames
For i = 0 To UBound(vSheetName)
Next i
i = i - 1
Then i is the number of sheets, NOT the sheet index. If i >= 2 then you can run the dxf create code
Hope this helps you out and looking forward to your code.
I can't get it together to save only one sheet for DXF. Can you hlep me?
I now have this:
Option Explicit Private Const BIF_RETURNONLYFSDIRS As Long = &H1 Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2 Private Const BIF_RETURNFSANCESTORS As Long = &H8 Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000 Private Const BIF_BROWSEFORPRINTER As Long = &H2000 Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000 Private Const MAX_PATH As Long = 260 Function BrowseFolder(Optional Caption As String, _ Optional InitialFolder As String) As String Dim SH As Shell32.Shell Dim F As Shell32.Folder Set SH = New Shell32.Shell Set F = SH.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, InitialFolder) If Not F Is Nothing Then BrowseFolder = F.Items.Item.Path End If End Function Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swDrawDoc As SldWorks.DrawingDoc Dim swCustPrpMgr As SldWorks.CustomPropertyManager Dim swModelDocExt As SldWorks.ModelDocExtension Dim swExportPDFData As SldWorks.ExportPdfData Dim boolstatus As Boolean Dim sFileName As String Dim filename As String Dim filename2 As String Dim lErrors As Long Dim lWarnings As Long Dim longstatus As Long Dim longwarnings As Long Dim Path As String Dim Value As String Dim vSheetName As Variant Dim i As Integer Set swApp = Application.SldWorks Path = BrowseFolder() If Path = "" Then MsgBox "Please select the path and try again" End Else Path = Path & "\" End If sFileName = Dir(Path & "*.slddrw") Do Until sFileName = "" Set swModel = swApp.OpenDoc6(Path & sFileName, swDocDRAWING, swOpenDocOptions_Silent, "", longstatus, longwarnings) Set swModel = swApp.ActiveDoc Set swDrawDoc = swModel Set swModelDocExt = swModel.Extension Set swCustPrpMgr = swModel.Extension.CustomPropertyManager("") swCustPrpMgr.Get3 "REVISION", False, "", Value If Value = "" Then filename = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".PDF" filename2 = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".DXF" ElseIf Value = "-" Then filename = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".PDF" filename2 = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & ".DXF" Else filename = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & Value & ".PDF" filename2 = Left(swModel.GetPathName, Len(swModel.GetPathName) - 7) & Value & ".DXF" End If Set swApp = Application.SldWorks swApp.Visible = True Set swModel = swApp.ActiveDoc Set swDrawDoc = swModel Set swModelDocExt = swModel.Extension Set swExportPDFData = swApp.GetExportFileData(swExportDataFileType_e.swExportPDFData) vSheetName = swDrawDoc.GetSheetNames If swExportPDFData Is Nothing Then MsgBox "Nothing" boolstatus = swExportPDFData.SetSheets(swExportData_ExportSpecifiedSheets, vSheetName(0)) boolstatus = swModelDocExt.SaveAs(filename, 0, 0, swExportPDFData, lErrors, lWarnings) For i = 0 To UBound(vSheetName) MsgBox "i = " & i Next i i = i - 1 MsgBox "final i = " & i boolstatus = swDrawDoc.ActivateSheet(vSheetName(i)) boolstatus = swModel.SaveAs4(filename2, swSaveAsCurrentVersion, swSaveAsOptions_Silent, lErrors, lWarnings) Debug.Assert boolstatus swApp.CloseDoc swModel.GetTitle Set swModel = Nothing sFileName = Dir Loop End Sub
OK give this macro a try.