Hide Table of Contents

Create SpeedPak for Subassemblies Example (VBA)

This example shows how to:

  • create SpeedPak configurations for subassemblies.
  • switch between the SpeedPak configuration and the parent configuration of the SpeedPak configuration.
'-------------------------------------------------------------------
' Preconditions:
'  1. Verify that the specified assembly to open exists.
'  2. Open the Immediate window.
'
' Postconditions:
'  1. Opens the specified assembly.
'  2. Deletes the Coordinate System1 feature to avoid errors.
'  3. Selects the arm1 and arm2 subassemblies.
'  4. Checks to see if either component has a SpeedPak configuration.
'  5. Creates graphics-only SpeedPak for each selected component.
'  6. At Stop, examine the FeatureManager design tree to verify that the
'     icons for arm1 and arm2 indicate SpeedPak, then press F5.
'  7. Switches SpeedPak to each selected component's parent configuration.
'  8. At Stop, examine the FeatureManager design tree to verify that
'     SpeedPak switched to the parent configuration of arm1 and
'     arm2, then press F5.
'  9. Switches each component back to SpeedPak.
' 10. Examine the Immediate window and FeatureManager design tree to verify
'     that arm1 and arm2 are SpeedPak.
'
' NOTE: Because the assembly is used elsewhere, do not save changes.
'--------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swAssembly As SldWorks.AssemblyDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComponent As SldWorks.Component2
Dim status As Boolean
Dim errors As Long
Dim warnings As Long
Dim fileName As String
Dim selComponents(1) As Object
Dim i As Long
Dim count As Long
Dim speedPakExists As Boolean
Sub main()
    Set swApp = Application.SldWorks
    fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\wrench.sldasm"
    Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
    Set swAssembly = swModel
    Set swModelDocExt = swModel.Extension
    Set swSelMgr = swModel.SelectionManager    
    'Select and delete Coordinate System1 to avoid errors
    status = swModelDocExt.SelectByID2("Coordinate System1", "COORDSYS", 0, 0, 0, False, 0, Nothing, 0)
    swModel.EditDelete    
    'Select the two subassemblies for which to create SpeedPak configurations
    status = swModelDocExt.SelectByID2("arm1-1@wrench", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    Set selComponents(0) = swSelMgr.GetSelectedObject6(1, -1)
    status = swModelDocExt.SelectByID2("arm2-1@wrench", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
    Set selComponents(1) = swSelMgr.GetSelectedObject6(2, -1)
    count = swSelMgr.GetSelectedObjectCount2(-1)    
    'Get whether any of the selected components already
    'have SpeedPak configurations
     For i = 0 To count - 1
        Set swComponent = selComponents(i)
        speedPakExists = swComponent.IsSpeedPak
        If (speedPakExists) Then
             Debug.Print ("SpeedPak already exists for component(" & i & ")")
        End If
    Next    
    'Create graphics-only SpeedPak for the selected components
    status = swAssembly.CreateSpeedPak(2)
    Debug.Print ("SpeedPak created for selected components? " & status)  
  
    Stop
    'Examine the FeatureManager design tree to verify that the
    'icons for arm1 and arm2 indicate SpeedPak, then press F5        
    'Switch SpeedPak to the parent configurations of each selected components
    status = swModelDocExt.SelectByID2("arm1-1@wrench", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    status = swModelDocExt.SelectByID2("arm2-1@wrench", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
    status = swAssembly.SetSpeedPakToParent
    Debug.Print ("SpeedPak switched to the parent configuration of each selected component? " & status)    
    Stop
    'Examine the FeatureManager design tree to verify 
    'that SpeedPak switched to the parent configurations of arm1 and
    'arm2    
    'Switch the selected components to SpeedPak
    status = swModelDocExt.SelectByID2("arm1-1@wrench", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    status = swModelDocExt.SelectByID2("arm2-1@wrench", "COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
    status = swAssembly.UseSpeedPak
    Debug.Print ("Switched the selected components to SpeedPak? " & status)    
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:   Create SpeedPak for Subassemblies 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) 2021 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.