Hide Table of Contents

Get Display State Settings Example (VB.NET)

This example shows how to get display modes, transparency states, and visibility states of components.

' Preconditions: Open an assembly that contains a minimum of three top-level
' components and two display states, "DS_1" and "DS_2".
' Postconditions: Inspect the Immediate Window for the display modes,
' transparency states, and visibility states of all three components
' in both DS_1 and DS_2.
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Diagnostics

Partial Public Class SolidWorksMacro
Private swDoc As ModelDoc2 = Nothing
    Private swExt As ModelDocExtension = Nothing
    Private swDSS As DisplayStateSetting = Nothing
    Private varStatus As Object
    Private varTStatus As Object
    Private varVStatus As Object
    Private statusArray As Array
Private statusTArray As Array
Private statusVArray As Array
Const maxEntMode As Integer = 3

Public Sub Main()
        swDoc =
DirectCast(swApp.ActiveDoc, ModelDoc2)
        swExt = swDoc.Extension
Dim docType As Integer = swDoc.[GetType]()
If docType = CInt(swDocumentTypes_e.swDocASSEMBLY) Then


            varStatus = swExt.DisplayMode(swDSS)
            statusArray =
DirectCast(varStatus, Array)

            varTStatus = swExt.Transparency(swDSS)
            statusTArray =
DirectCast(varTStatus, Array)

            varVStatus = swExt.Visibility(swDSS)
            statusVArray =
DirectCast(varVStatus, Array)


End If
    End Sub

    Public Sub CreateDisplayStateSetting()
        swDSS = swExt.GetDisplayStateSetting(
        swDSS.Option =

Dim specDSNames As String() = New String(1) {}
        specDSNames(0) =
        specDSNames(1) = "DS_2"
        Dim varSpecDSNames As Object = specDSNames
        swDSS.Names = varSpecDSNames

Dim swADoc As AssemblyDoc
        swADoc =
DirectCast(swDoc, AssemblyDoc)
Dim compCnt As Integer = swADoc.GetComponentCount(True)
Dim listComp As Component2() = New Component2(maxEntMode - 1) {}
If compCnt >= maxEntMode Then
            Dim varComp As Object() = DirectCast(swADoc.GetComponents(True), Object())
            listComp(0) =
DirectCast(varComp(0), Component2)
            listComp(1) =
DirectCast(varComp(1), Component2)
            listComp(2) =
DirectCast(varComp(2), Component2)
            swDSS.Entities = listComp
End If

    End Sub

    Public Sub WriteOutput()
Dim entCount As Integer = swDSS.GetEntityCount()
Dim listComp As Object() = DirectCast(swDSS.Entities, Object())
Dim allCtr As Integer = 0
For entctr As Integer = 0 To entCount - 1
Dim swComp As Component2 = DirectCast(listComp(entctr), Component2)
Dim dsNameCount As Integer = swDSS.GetNameCount()
Dim dsNames As Object() = DirectCast(swDSS.Names, Object())

For namectr As Integer = 0 To dsNameCount - 1
"   " & DirectCast(dsNames(namectr), String))
Dim status As Integer = CInt(statusArray.GetValue(allCtr))
Dim statusT As Integer = CInt(statusTArray.GetValue(allCtr))
Dim statusV As Integer = CInt(statusVArray.GetValue(allCtr))
                allCtr += 1
    End Sub
    Public Sub WriteMode(ByVal status As Integer)
Select Case status
Case CInt(swDisplayMode_e.swDisplayModeDEFAULT)
"       swDisplayModeDEFAULT")
Exit Select
            Case CInt(swDisplayMode_e.swHIDDEN)
"       swHIDDEN")
Exit Select
            Case CInt(swDisplayMode_e.swHIDDEN_GREYED)
"       swHIDDEN_GREYED")
Exit Select
            Case CInt(swDisplayMode_e.swSHADED)
"       swSHADED")
Exit Select
            Case CInt(swDisplayMode_e.swSHADED_EDGES)
"       swSHADED_EDGES")
Exit Select
            Case CInt(swDisplayMode_e.swWIREFRAME)
"       swWIREFRAME")
Exit Select
            Case CInt(swDisplayMode_e.swDisplayModeUNKNOWN)
"       Error:swDisplayModeUNKNOWN")
Exit Select

            Case CInt(swDisplayMode_e.swFACETED_WIREFRAME)
                Debug.Print ("       swFACETED_WIREFRAME")
                Exit Select

            Case CInt(swDisplayMode_e.swFACETED_HIDDEN_GREYED)
                Debug.Print ("       swFACETED_HIDDEN_GREYED")
                Exit Select

            Case CInt(swDisplayMode_e.swFACETED_HIDDEN)
                Debug.Print ("       swFACETED_HIDDEN")
Exit Select
        End Select
    End Sub
    Public Sub WriteTransparency(ByVal status As Integer)
Select Case status
Case CInt(swTransparencyState_e.swTransparencyStateTransparent)
"       swTransparencyStateTransparent")
Exit Select
            Case CInt(swTransparencyState_e.swTransparencyStateNonTransparent)
"       swTransparencyStateNonTransparent")
Exit Select
            Case CInt(swTransparencyState_e.swTransparencyStateUnknown)
"       ERROR : swTransparencyStateUnknown")
Exit Select
        End Select
    End Sub
    Public Sub WriteVisibility(ByVal status As Integer)
Select Case status
Case CInt(swVisibilityState_e.swVisibilityStateHide)
"       swVisibilityStateHide")
Exit Select
            Case CInt(swVisibilityState_e.swVisibilityStateShown)
"       swVisibilityStateShown")
Exit Select
            Case CInt(swVisibilityState_e.swVisibilityStateUnknown)
"       ERROR : swVisibilityStateUnknown")
Exit Select
        End Select
    End Sub

    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

Subject:   Feedback on Help Topics
Page:   Get Display State Settings 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) 2015 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.