2 Replies Latest reply on Sep 29, 2014 6:46 PM by Yong Ning

    How to save as eDrawomg with API?

    Yong Ning

      00.jpg

       

       

      01.jpg

          • Re: How to save as eDrawomg with API?
            Yong Ning

            Thanks your tips

            2010 SolidWorks API Help - Open File Example (VBA)

            http://help.solidworks.com/2010/English/api/sldworksapi/Open_File_Example_VB.htm

             

            swApp.SetUserPreferenceIntegerValue swEdrawingsSaveAsSelectionOption, swEdrawingSaveAll

             

            swUserPreferenceIntegerValue_e→swEdrawingsSaveAsSelectionOption→

            swEdrawingSaveAsOption_e

              *********a***    swEdrawingSaveActive \\Publish the active configuration or sheet when saving as an eDrawings

              *********b***    swEdrawingSaveAll \\Publish all configurations or sheets when saving as an eDrawings

              *********c***    swEdrawingSaveSelected \\Publish sheets or configurations specified by swEmodelSelectionList when saving as an eDrawings

             

             

            *****************

            swModel.Extension.SaveAs sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings

             

             

            ***********************************************

            ''

            Private Sub SaveEdrawing()

              ''

              Dim T: T = Timer

              Dim Path, FileName, Filter

              Dim sFileName As String, nErrors As Long, nWarnings As Long

              ''

              Dim fileConfig As String, fileDispName As String, fileOptions As Long

              ''

              Dim swApp As SldWorks.SldWorks, swModel As ModelDoc2

              ''

                Set swApp = GetObject(, "SldWorks.Application")

                Filter = "SolidWorks Files (*.sldprt, *.sldasm, *.slddrw)|*.sldprt,*.sldasm,*.slddrw|Filter name (*.fil)|*.fil|All Files (*.*)|*.*|"

                FileName = swApp.GetOpenFileName("File to Attach", "", Filter, fileOptions, fileConfig, fileDispName)

                Set swModel = SwOpenFile(swApp, FileName)

                ''

                sFileName = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6)

                ' Get type of model document and set edrawing extension

                If swModel.GetType = swDocPART Then

                   sFileName = sFileName & "eprt"

                ElseIf swModel.GetType = swDocASSEMBLY Then

                   sFileName = sFileName & "easm"

                ElseIf swModel.GetType = swDocDRAWING Then

                   sFileName = sFileName & "edrw"

                Else

                   Exit Sub

                End If

                swApp.SetUserPreferenceIntegerValue swEdrawingsSaveAsSelectionOption, swEdrawingSaveAll

                Debug.Print swModel.GetTitle

                Stop

                swModel.Extension.SaveAs sFileName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, nErrors, nWarnings

                Stop

                swModel.SaveAs

              Timing T

            End Sub

            ************************

             

            Private Sub ll()

              Dim SwDraw As DrawingDoc

                Set SwDraw = Application.SldWorks.ActiveDoc

                Dim Path: Path = SwDraw.GetPathName

                Path = Left(Path, InStrRev(Path, "\"))

              Dim PathName

                PathName = Path & "aa" & ".SldDrw"

                SwDraw.SaveAs2 PathName, 0, False, False

                PathName = Path & "aa" & ".PDF"

                SwDraw.SaveAs2 PathName, 0, True, False

             

            End Sub