Hi,
I am modifying an existing macro to save a drawing as a pdf document in specific file location with the revision in the filename. The macro now does both of these things however the filename is not correct. The pdf should be named with the same name as the drawing, instead it is saved with the same name as the drawing plus the sheet name, e.g. SG828456DML - Sheet1_A00 instead of SG828456DML_A00 (SG828456DML is the name of the drawing and _A00 is the revision).
Public Sub main()
Dim swDoc As ModelDoc2 = Nothing
Dim longstatus As Integer = 0
swDoc = CType(swApp.ActiveDoc, ModelDoc2)
Dim FilePath As String = ""
Dim FileRevision As String = ""
Dim NewFilePath1 As String = ""
Dim NewFilePath2 As String = ""
FilePath = swDoc.GetTitle
FileRevision = swDoc.GetCustomInfoValue("", "Révision")
NewFilePath2 = (FilePath & "_" & FileRevision)
NewFilePath1 = Path.ChangeExtension("S:\\Wide\\Gattlen\\FRE\\In approval process\\" & NewFilePath2, ".PDF")
longstatus = swDoc.SaveAs3(NewFilePath1, 0, 0)
MsgBox("Saved " & NewFilePath1, MsgBoxStyle.Information)
End Sub
Cheers,
Fraser
SolidworksApi macros
Try these codes
<p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim sFileName As String</p><p>Dim FileRevision As String</p><p>Const FilePath As String = "S:\Wide\Gattlen\FRE\In approval process\"</p><p>Sub main()</p><p> </p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc </p><p></p><p>FileRevision = swModel.GetCustomInfoValue("", "Révision")</p><p>sFileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)</p><p>sFileName = Left(sFileName, InStrRev(sFileName, ".") - 1) </p><p></p><p>sFileName = FilePath & sFileName & "_" & FileRevision & ".PDF"</p><p></p><p>swModel.SaveAs3 sFileName, 0, 0 </p><p>MsgBox "Saved " sFileName, vbOKOnly</p><p> </p><p>End Sub</p>You are using VB.NET so you can just call
instead of