I'm trying to make a macro to save each sheet of my drawings in DXF and PDF. So far, I can save all the sheets in the right format or activate it by fiddling with the Solidworks options.
Nevertheless, I would like to be able to change the name directly without renaming each file (so boring!) Brief. To do that, I'd like to be able to tell my macro to open a sheet, save it and then move on to the next one. I know I have to put a meter on it.... But how do I tell him to take the sheet1 then 2, etc.
And, little bonus question. Is there a summary of all the Solidworks specific commands somewhere?
Thank you very much Lucas P for your quick and provided answers.
At least, now, I'm armored with examples (fortunately my English is not so far behind me!)
Yes, I saw your similar macro. I was inspired by it a lot for mine by adapting it to my needs.
On the other hand, from what I understand in what you send me, I am obliged to know the names of the sheets. If it's not a problem for my short stories, I don't really manage what my predecessors did.
So, I was hoping to be able to find something like in excel where you can put "Sheet1" to designate them rather than their names.
I'm going to fiddle around a bit and come back and post the whole code if it works
I have a macro that goes smoothly ... but where nothing happens. I don't really understand why and where it gets stuck. If anyone has an idea?
Sub Save() Dim swapp As SldWorks.SldWorks Dim swdoc As SldWorks.ModelDoc2 Dim Swdraw As SldWorks.ModelDoc Dim swSheet As SldWorks.Sheet Dim vSheetNames As Variant Dim Nbfeuille As Variant Set swapp = Application.SldWorks Set swdoc = swapp. ActiveDoc Set Swdraw = swdoc Set swSheet = Swdraw.GetCurrentSheet 'Confirmation message ret = MsgBox("do you want to convert this drawing to DXF and PDF?", vbOKCancel + vbExclamation + vbMsgBoxSetForeground + vbSystemModal, "Laser Conversion") If ret = vbCancel Then End Registration new name Do newname = InputBox("Please specify the new name:", "blabla", newname) If StrPtr(newname) = 0 Then MsgBox "procedure cancelled" Exit Sub End If 'Checking Forbidden Character Windows Do While InStr(newname, "/") > 0 Or InStr(newname, "*") > 0 Or InStr(newname, "?") > 0 Or InStr(newname, "<") > 0 Or InStr(newnam, ">") > 0 Or InStr(newnam, "!") > 0 newname = InputBox("Please note that the name contains at least one of the forbidden characters \/:*?""<>!" & vbNewLine & vbNewLine & "Please specify the new name:", "save-under by LPR", newname) Loop Loop While newname = " " 'Registration Dossier Do FilePath = InputBox("Specify the path", "record folder", FilePath) If StrPtr(FilePath) = 0 Then MsgBox "procedure cancelled" Exit Sub End If 'Adding the \ to the end of the folder name If Right(FilePath, 1) <> "\" Then FilePath = FilePath & "\" If Dir$(FilePath) <> "" Then EXISTS = 1 Else: MsgBox "the directory doesn't exist, please create it" Debug.Print Dir$(FilePath) End If Loop While EXISTS <> 1 'Indicates the number of sheets Nbfeuille = swdoc. GetSheetCount For i = 0 To Nbfeuille swdoc. SheetPrevious Next i 'move to the next sheet if < to the total number For i = 0 To varSheetCount - 1 If i <> 0 Then swmodel. SheetNext End If Recording in DXF and PDF swdoc. SaveAs (FilePath + newname + "_" + i + ".dxf") swdoc. SaveAs (FilePath + newname + "_" + i + ".pdf") Next i End Sub