Hide Table of Contents

SolidWorks

Get Persistent IDs Example (VB.NET)

This example shows how to get the persistent 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. 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.
'
' 3. Ensure that the latest SolidWorks.Interop.swdocumentmgr.dll
'    interop assembly is loaded in the project (right-click
'    the project in Project Explorer, select Add Reference,
'    select the interop assembly from the .NET tab or browse
'    for the DLL in <SolidWorks_install_dir>\api\redist).
' 4. Substitute your license key for "your_license_key" in the code.
' 5. Substitute your new file for sDocFileName in the code.
'
' Postconditions: Inspect the Immediate Window.
'----------------------------------------------------------------------------

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

        ' substitute the name of drawing document that does

        sDocFileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\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 Persistent 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) 2011 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.