Hide Table of Contents

SOLIDWORKS

Get Sheet IDs Example (VB.NET)

This example shows how to get the IDs of drawing sheets.

'---------------------------------------------------------------------------
' Preconditions:
' 1. Read the SOLIDWORKS Document Manager API
'    Help Getting Started topic and ensure that
'    the required DLLs are registered.
' 2. Open SOLIDWORKS and copy the code below to a VB.NET macro.
' 3. Convert the drawing document specified
'    in sDocFileName to the latest supported
'    version by opening and saving it to another name
'    in SOLIDWORKS.
'
'    NOTE:  Because this document is used elsewhere, do not
'    save any changes when closing it.
'
' 4. Ensure that the latest SolidWorks.Interop.swdocumentmgr.dll
'    interop assembly is loaded in the project. (Right-click
'    the project in Project Explorer, click Add Reference,
'    click the interop assembly in the .NET tab, or browse
'    for the DLL in install_dir\api\redist\CLR2.)
' 5. Substitute your license key for your_license_key in the code.
'
' Postconditions: Inspect the Immediate Window for the sheet IDs.
'----------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports SolidWorks.Interop.swdocumentmgr

Imports System

Imports System.Diagnostics

Partial Class SolidWorksMacro

    Sub main()

        Dim swClassFact As SwDMClassFactory

        Dim swDocMgr As SwDMApplication

        Dim swDoc As SwDMDocument14

        Dim sDocFileName As String

        Dim nDocType As SwDmDocumentType

        Dim nRetVal As SwDmDocumentOpenError

        Dim sLicenseKey As String

 

        ' Specify your license key

        sLicenseKey = "your_license_key"

 

        ' If this drawing document doesn't exist on your system,

        ' then substitute the name of drawing document that does

        sDocFileName = "C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2017\tutorial\advdrawings\foodprocessor.slddrw"

        nDocType = SwDmDocumentType.swDmDocumentDrawing

        swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")

        swDocMgr = swClassFact.GetApplication(sLicenseKey)

        swDoc = swDocMgr.GetDocument(sDocFileName, nDocType, True, nRetVal)

        If (swDoc Is Nothing) Then

            MsgBox("Unable to open document. Correct path to file or register Document Manager DLL.")

        End If

        Dim Sheet As SwDMSheet3

        Dim Sheets As Object

        Dim i As Long

        Sheets = swDoc.GetSheets

        For i = 0 To UBound(Sheets)

            Sheet = Sheets(i)

            Debug.Print(Sheet.Name & " ID: " & Sheet.GetID)

        Next

        swDoc.CloseDoc()

    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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get IDs 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) 2017 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.