Hide Table of Contents

Save Rolled Backed Part as Parasolid File Example (VBA)

This example shows how to save a part in a rolled backed state as a Parasolid file.

 

NOTE: When a part is in a rolled back state, you cannot export the part to any other format until the model has been rolled forward. This example shows how to use various geometry-related and topology-related APIs to create a temporary part that you can then export to any other format, in this example, Parasolid.

 

'------------------------------------------------

'

' Preconditions:

'       (1) Part is open.

'       (2) Part is rolled back.

'

' Postconditions:

'       (1) Parasolid file is saved to the same directory,

'           overwriting any existing file of the same name.

'       (2) Parasolid file has same geometry as part in rolled back

'           state.

'

'-----------------------------------------------

Option Explicit

Public Enum swSaveAsVersion_e

    swSaveAsCurrentVersion = 0  '  Default

    swSaveAsFormatProE = 2      '  Save SolidWorks part as Pro/E format .prt/.asm

                                '  extension (not as SolidWorks .prt/.asm)

End Enum

Public Enum swSaveAsOptions_e

    swSaveAsOptions_Silent = &H1            '  Save document silently or not

    swSaveAsOptions_Copy = &H2              '  Save document as a copy or not

    swSaveAsOptions_SaveReferenced = &H4    '  Save referenced documents or not

                                            '  (drawings and parts only)

End Enum

Public Enum swFileSaveError_e

    swGenericSaveError = &H1

    swReadOnlySaveError = &H2

    swFileNameEmpty = &H4               '  Filename must not be empty

    swFileNameContainsAtSign = &H8      '  Filename cannot contain an at-sign (@)

                                        '  character

    swFileLockError = &H10

    swFileSaveFormatNotAvailable = &H20 '  Save As file type is not valid

    swFileSaveAsDoNotOverwrite = &H80   '  Do not overwrite an existing file

    swFileSaveAsInvalidFileExtension = &H100    '  File extension differs from

                                                '  SolidWorks document type

End Enum

Public Enum swFileSaveWarning_e

    swFileSaveWarning_RebuildError = &H1    '  File was saved with a rebuild error

End Enum

Public Enum swUserPreferenceIntegerValue_e

    swParasolidOutputVersion = 89

End Enum

Public Enum swUserPreferenceStringValue_e

    swFileSaveAsCoordinateSystem = 16

End Enum

Public Enum swParasolidOutputVersion_e

    swParasolidOutputVersion_latest = 0

    swParasolidOutputVersion_80 = 1

    swParasolidOutputVersion_90 = 2

    swParasolidOutputVersion_91 = 3

    swParasolidOutputVersion_100 = 4

    swParasolidOutputVersion_110 = 5

    swParasolidOutputVersion_111 = 6

    swParasolidOutputVersion_120 = 7

    swParasolidOutputVersion_121 = 8

End Enum

Public Enum swBodyType_e

    swSolidBody = 0

    swSheetBody = 1

    swWireBody = 2

    swMinimumBody = 3

    swGeneralBody = 4

    swEmptyBody = 5

End Enum

Public Enum swCreateFeatureBodyOpts_e

    swCreateFeatureBodyCheck = &H1

    swCreateFeatureBodySimplify = &H2

End Enum

Public Enum swMessageBoxIcon_e

    swMbWarning = 1

    swMbInformation = 2

    swMbQuestion = 3

    swMbStop = 4

End Enum

Public Enum swMessageBoxBtn_e

    swMbAbortRetryIgnore = 1

    swMbOk = 2

    swMbOkCancel = 3

    swMbRetryCancel = 4

    swMbYesNo = 5

    swMbYesNoCancel = 6

End Enum

Public Enum swMessageBoxResult_e

    swMbHitAbort = 1

    swMbHitIgnore = 2

    swMbHitNo = 3

    swMbHitOk = 4

    swMbHitRetry = 5

    swMbHitYes = 6

    swMbHitCancel = 7

End Enum

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swPart                  As SldWorks.PartDoc

    Dim swNewPart               As SldWorks.PartDoc

    Dim swNewModel              As SldWorks.ModelDoc2

    Dim sNewModelName           As String

    Dim vBodyArr                As Variant

    Dim vBody                   As Variant

    Dim swBody                  As SldWorks.body2

    Dim swCopyBody              As SldWorks.body2

    Dim swFeat                  As SldWorks.feature

    Dim sPathName               As String

    Dim nOldVal                 As Long

    Dim nErrors                 As Long

    Dim nWarnings               As Long

    Dim nRetval                 As Long

    Dim i                       As Long

    Dim bRet                    As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

    Set swNewPart = swApp.NewPart

    Set swNewModel = swNewPart

    

    sNewModelName = swNewModel.GetTitle

    

    ' Current Parasolid settings

    Debug.Print "ParasolidOutputVersion     = " + Str(swApp.GetUserPreferenceIntegerValue(swParasolidOutputVersion))

    

    Debug.Print "SaveAsCoordinateSystem     = " + swModel.GetUserPreferenceStringValue(swFileSaveAsCoordinateSystem)

    

    ' Strip off SolidWorks file extension (sldxxx)

    ' and add Parasolid extension (x_b)

    sPathName = swModel.GetPathName

    sPathName = Left(sPathName, Len(sPathName) - 6)

    sPathName = sPathName + "x_t"

        

    ' Store existing Parasolid export version and change to v10.0

    nOldVal = swApp.GetUserPreferenceIntegerValue(swParasolidOutputVersion)

    bRet = swApp.SetUserPreferenceIntegerValue(swParasolidOutputVersion, swParasolidOutputVersion_100)

    

    ' Create temporary part with bodies from existing part

    For i = 0 To 5

        vBodyArr = swPart.GetBodies2(i, False)

        If Not IsEmpty(vBodyArr) Then

            For Each vBody In vBodyArr

                Set swBody = vBody

                Set swCopyBody = swBody.Copy

                Set swFeat = swNewPart.CreateFeatureFromBody3(swCopyBody, False, _

                                swCreateFeatureBodyCheck + swCreateFeatureBodySimplify)

            Next vBody

        End If

    Next i

    

    ' Export temporary part to Parasolid

    bRet = swNewModel.SaveAs4(sPathName, _

            swSaveAsCurrentVersion, _

            swSaveAsOptions_Silent, _

            nErrors, _

            nWarnings)

    If bRet = False Then

        nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)

    End If

    

    ' Get rid of temporary file

    swApp.QuitDoc sNewModelName

    ' Restore old Parasolid export version

    bRet = swApp.SetUserPreferenceIntegerValue(swParasolidOutputVersion, nOldVal)

End Sub

'----------------------------------------------



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Save Roll Backed Part as Parasolid File Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2013 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.