Hide Table of Contents

SOLIDWORKS Document Manager API Help

Get Sheet IDs Example (C#)

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
//    have been registered.
// 2. Open SOLIDWORKS and copy the code below to a C# 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 directory).
// 5. Substitute your license key for your_license_key
//    in the code.
//
// Postconditions: Inspect the Immediate Window for the sheet IDs.
//---------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using SolidWorks.Interop.swdocumentmgr;

using System;

using System.Diagnostics;

 

    partial class SolidWorksMacro

    {

        public void Main()

        {

            SwDMClassFactory swClassFact = default(SwDMClassFactory);

            SwDMApplication swDocMgr = default(SwDMApplication);

            SwDMDocument14 swDoc = default(SwDMDocument14);

            string sDocFileName = null;

            SwDmDocumentType nDocType = default(SwDmDocumentType);

            SwDmDocumentOpenError nRetVal = default(SwDmDocumentOpenError);

            string sLicenseKey = null;

 

            // 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 2018\\samples\\tutorial\\advdrawings\\foodprocessor.slddrw";

 

            nDocType = SwDmDocumentType.swDmDocumentDrawing;

            swClassFact = new SwDMClassFactory();

            swDocMgr = swClassFact.GetApplication(sLicenseKey);

            swDoc = (SwDMDocument14)swDocMgr.GetDocument(sDocFileName, nDocType, true, out nRetVal);

            if ((swDoc == null))

            {

                System.Windows.Forms.MessageBox.Show("Unable to open document. Correct path to file or register Document Manager DLL.");

            }

            SwDMSheet3 Sheet = default(SwDMSheet3);

            object[] Sheets = null;

            int i = 0;

            Sheets = (Object[])swDoc.GetSheets();

            for (i = 0; i <= Sheets.GetUpperBound(0); i++)

            {

                Sheet = (SwDMSheet3)Sheets[i];

                Debug.Print(Sheet.Name + " ID: " + Sheet.GetID());

            }

            swDoc.CloseDoc();

        }

        public SldWorks swApp;

    }

 



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 (C#)
*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) 2024 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.