Hide Table of Contents

Open And Save Document to 3DEXPERIENCE Example (C#)

This example shows how to open and save a 3DEXPERIENCE document with SOLIDWORKS Connected.

//---------------------------------------------------------------

// Preconditions:

// 1. Open SOLIDWORKS Connected.

// 2. Open a new part.

// 3. Open the Immediate window.

// 4. Run the macro to the Break.

// 5. Close the document in the user interface.

// 6. Press F5 to re-load the document from

//    your collaborative space in 3DEXPERIENCE.

//

// Postconditions:

// 1. NonActiveSave.sldprt is saved to a collaborative space

//    on the 3DEXPERIENCE platform and re-opened.

// 2. Use 3DEXPERIENCE 3DSearch to find NonActiveSave.sldprt

//    in your collaborative space.
// NOTE: Before running this example again, change strFileName to a
//       unique file name or delete NonActiveSave.sldprt.
//-------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System.Diagnostics;

 

 

namespace OpenAndSave_CSharp

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

             ModelDoc2 swModel;

             ModelDocExtension swModExt;

             SaveTo3DExperienceOptions swSaveTo3DExp;

             PLMObjectSpecification swPLMObjectSpecification;

             DocumentSpecification swDocSpecification;

             string strPLMid;

             string strFileName, strComment;

             bool bStat;

             int lError = 0;

             int IWarning = 0;

 

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModExt = swModel.Extension;

 

            if (swApp.ApplicationType == (int) swApplicationType_e.swApplicationType_3DEXPERIENCE)

            {

                swSaveTo3DExp = (SaveTo3DExperienceOptions)swApp.GetSaveTo3DExperienceOptions();

 

                strFileName = "NonActiveSave.sldprt";

                strComment = "No comment";

                swSaveTo3DExp.FileName = strFileName;

                bStat = swSaveTo3DExp.SetRevisionComments(strComment);

 

                bStat = swModExt.SaveTo3DExperience(swSaveTo3DExp, ref lError, ref IWarning);

 

                strPLMid = swModExt.GetPLMID();

                Debug.Print(swModel.GetPathName() + " " + strPLMid);

 

                System.Diagnostics.Debugger.Break(); // Close the document in the user interface

 

                // Re-open the document from 3DEXPERIENCE

                swDocSpecification = (DocumentSpecification)swApp.GetOpenDocSpec("");

                swDocSpecification.DocumentType = (int) swDocumentTypes_e.swDocPART;

                swPLMObjectSpecification = (PLMObjectSpecification)swDocSpecification.PLMObjectSpecification;

                swPLMObjectSpecification.PLMID = strPLMid;

 

                swModel = swApp.OpenDoc7(swDocSpecification);

 

            }

}

 

    // The SldWorks swApp variable is pre-assigned for you.

    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:   Open And Save Document to 3DEXPERIENCE 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) 2022 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.