Hide Table of Contents

Get the Current Name of the Configuration of a Suppressed Component Example (VB.NET)

This example shows how to obtain the current name of the configuration of a suppressed component.

' Preconditions:
' 1. Read the SolidWorks Document Manager API Getting Started topic
'    and ensure that the required DLLs have been registered.
' 2. Copy and paste this code into Module1.vb of a VB.NET console application
'    in Microsoft Visual Studio.
' 3. Add the SolidWorks.Interop.swdocumentmgr.dll reference
'    to the project:
'    a. Right-click the solution in Solution Explorer.
'    b. Select Add Reference.
'    c. Click the Browse tab.
'    d. Select:
'       install_dir\api\redist\CLR2\SolidWorks.Interop.swdocumentmgr.dll
' 4. Also add the following references to the project:
'    System
'    System.Core
'    System.Data
'    System.Data.DataSetExtensions
'    System.Xml
'    System.Xml.Linq
' 5. Substitute your_license_code with your SolidWorks
'    Document Manager license key.
' 6. Substitute assembly_with_suppressed_comps with the path to an assembly
'    that contains one or more suppressed components.
' 7. Open an Output window.
' Postconditions: Inspect the Output window for configuration information.

' NOTE: This console application was developed using
' Microsoft Visual Studio 2008. If you use another version of
' Microsoft Visual Studio, you may need to add more references to get
' this program to compile and open an Immediate window to view output.


Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports SolidWorks.Interop.swdocumentmgr
Imports System.Diagnostics
Imports System.Collections
Imports System.IO

Module Module1

Sub Main(ByVal args As String())
'Specify your license key
        Const sLicenseKey As String = "your_license_code"
        Const sDocFileName As String = "assembly_with_suppressed_comps"

        Dim swClassFact As SwDMClassFactory = Nothing
        Dim swDocMgr As SwDMApplication3 = Nothing
        Dim swDoc As SwDMDocument15 = Nothing
        Dim swDoc2 As SwDMDocument15 = Nothing
        Dim nRetVal As SwDmDocumentOpenError = 0
Dim dmSearchOpt As SwDMSearchOption
Dim dmExtRefOption As SwDMExternalReferenceOption
Dim numExtRefs As Long

        swClassFact = New SwDMClassFactory()
        swDocMgr =
DirectCast(swClassFact.GetApplication(sLicenseKey), SwDMApplication3)
        swDoc =
DirectCast(swDocMgr.GetDocument(sDocFileName, GetDocType(sDocFileName), False, nRetVal), SwDMDocument15)
        Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone = nRetVal)

"File = " + swDoc.FullName)

        dmExtRefOption = swDocMgr.GetExternalReferenceOptionObject
        dmSearchOpt = swDocMgr.GetSearchOptionObject

        dmExtRefOption.SearchOption = dmSearchOpt
        dmExtRefOption.Configuration =
        dmExtRefOption.NeedSuppress = True
        numExtRefs = swDoc.GetExternalFeatureReferences(dmExtRefOption)

Dim arrExtRefs As Array = DirectCast(dmExtRefOption.ExternalReferences, Array)

Dim config As SwDMConfiguration12
Dim configMgr As SwDMConfigurationMgr = swDoc.ConfigurationManager
        config =
DirectCast(configMgr.GetConfigurationByName(configMgr.GetActiveConfigurationName()), SwDMConfiguration12)
Dim comps As Object = config.GetComponents()
Dim arrComps As Array = DirectCast(comps, Array)

For Each swComp As SwDMComponent8 In arrComps
"Component Name: " + swComp.Name2)
"Component Configuration Name: " + swComp.ConfigurationName)
"Component Configuration ID: " + swComp.ConfigurationID.ToString)

Dim ComponentPathName As String = swComp.PathName
'Check validity of the Component's path name.  It might be out of date if the path changed after
            'the component was suppressed.
            If Not File.Exists(ComponentPathName) Then
                'If that file cannot be found, look for an external reference with the same name
                ComponentPathName = FindExtRefPath(swComp.PathName, arrExtRefs)
End If

            swDoc2 = DirectCast(swDocMgr.GetDocument(ComponentPathName, GetDocType(ComponentPathName), False, nRetVal), SwDMDocument15)
Dim config2 As SwDMConfiguration12
Dim configMgr2 As SwDMConfigurationMgr = swDoc2.ConfigurationManager
Dim confignames As String() = DirectCast(configMgr2.GetConfigurationNames(), String())
Dim arrConfigNames As New ArrayList(confignames)

' If the configuration name for the component doesn't match an
            ' existing config name in the reference part, go find the updated config name
            ' from the part.
            If Not arrConfigNames.Contains(swComp.ConfigurationName) Then

                For Each configName As String In arrConfigNames
                    config2 =
DirectCast(configMgr2.GetConfigurationByName(configName), SwDMConfiguration12)
If config2.GetID() = swComp.ConfigurationID Then
                        Debug.Print("Reference Part Configuration Name: " + config2.Name2)
End If
            End If

    End Sub
    Private Function FindExtRefPath(ByVal name As String, ByVal arrComps As Array) As String
        Dim ExtrefPathName As String = name
Dim nameParts As String() = name.Split("\"c)
Dim justName As String = nameParts.GetValue(nameParts.GetUpperBound(0)).ToString()

Dim i As Integer = arrComps.GetLowerBound(0)
Dim found As [Boolean] = False
        While (i <= arrComps.GetUpperBound(0)) AndAlso Not found
Dim extref As String = (arrComps.GetValue(i)).ToString()
Dim extrefParts As String() = extref.Split("\"c)
Dim justextrefName As String = extrefParts.GetValue(extrefParts.GetUpperBound(0)).ToString()
If justextrefName = justName Then
                found = True
                ExtrefPathName = extref
End If
            i += 1
End While

        Return ExtrefPathName
End Function
    Private Function GetDocType(ByVal name As String) As SwDmDocumentType
Dim nDocType As SwDmDocumentType = SwDmDocumentType.swDmDocumentUnknown
If name.EndsWith("SLDPRT") Then
            nDocType = SwDmDocumentType.swDmDocumentPart
ElseIf name.EndsWith("SLDASM") Then
            nDocType = SwDmDocumentType.swDmDocumentAssembly
End If

        Return nDocType
End Function



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

Subject:   Feedback on Help Topics
Page:   Get the Current Name of the Configuration of a Suppressed Component Example (VB.NET)
*   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:


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

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.