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 method to create a temporary part that you can then export to any other format, in this example, Parasolid.

'------------------------------------------------------------------
' Preconditions:
' 1. Open public_documents\samples\tutorial\api\box.sldprt.
' 2. Drag the rollback bar to just below Boss-Extrude1.
' 3. Open the Immediate window.
'
' Postconditions:
' 1. Saves the Parasolid file to the same folder as the part,
'    overwriting any existing file of the same name; the
'    Parasolid file has same geometry as the part in the rolled back
'    state.
' 2. Examine the Immediate window.
' 3. Open public_documents\samples\tutorial\api\box.x_t.
'
' NOTE: Because the part is used elsewhere, do not save changes.
'-----------------------------------------------------------------
Option Explicit
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
    
    Debug.Print "Parasolid settings:"
    ' Current Parasolid settings
    Debug.Print "  Current:"
    Debug.Print "    swUserPreferenceIntegerValue_e.ParasolidOutputVersion (0 = swParasolidOutputVersion_e.swParasolidOutputVersion_latest) = " + Str(swApp.GetUserPreferenceIntegerValue(swParasolidOutputVersion))
    Debug.Print "    swUserPreferenceStringValue_e.SaveAsCoordinateSystem (empty string signifies that the default coordinate system that does not require a transform) = " + 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)
    Debug.Print "  Modified: "
    Debug.Print "    swUserPreferenceIntegerValue_e.ParasolidOutputVersion (4 = swParasolidOutputVersion_e.swParasolidOutputVersion_100) = " + Str(swApp.GetUserPreferenceIntegerValue(swParasolidOutputVersion))
    ' 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)
    Debug.Print "  Restored:"
    Debug.Print "    swUserPreferenceIntegerValue_e.ParasolidOutputVersion (0 = swParasolidOutputVersion_e.swParasolidOutputVersion_latest) = " + Str(swApp.GetUserPreferenceIntegerValue(swParasolidOutputVersion))
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) 2018 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.