Hide Table of Contents

Create SpeedPak for Subassemblies Example (VB.NET)

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.
'--------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Imports System.Diagnostics
 
Partial Class SolidWorksMacro
 
    Dim swModel As ModelDoc2
    Dim swModelDocExt As ModelDocExtension
    Dim swAssembly As AssemblyDoc
    Dim swSelMgr As SelectionMgr
    Dim swComponent As Component2
    Dim status As Boolean
    Dim errors As Integer
    Dim warnings As Integer
    Dim fileName As String
    Dim selComponents(1) As Object
    Dim i As Integer
    Dim count As Integer
    Dim speedPakExists As Boolean
 
    Sub main()
 
        fileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\wrench.sldasm"
        swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swAssembly = swModel
        swModelDocExt = swModel.Extension
        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)
        selComponents(0) = swSelMgr.GetSelectedObject6(1, -1)
        status = swModelDocExt.SelectByID2("arm2-1@wrench""COMPONENT", 0, 0, 0, True, 0, Nothing, 0)
        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
            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
 
 
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
 
 
End Class

 



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 (VB.NET)
*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.