Hide Table of Contents

Export SOLIDWORKS MBD to STEP 242 Example (C#)

This example shows how to export a SOLIDWORKS MBD part to a STEP 242 file and publish it to SOLIDWORKS MBD PDF.

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

// Preconditions:

// 1. Verify that:

//    * specified part,

//    * SOLIDWORKS MBD 3D PDF theme, and

//    * c:\temp exist.

// 2. Ensure that the SOLIDWORKS MBD add-in is loaded.

// 3. Open the Immediate window.

//

// Postconditions:

// 1. Opens the specified part.

// 2. Gets the MBD3DPdfData object.

// 3. Gets the MBDSTEP242Data object.

// 4. Sets properties on the objects.

// 5. Exports the part to STEP 242.

// 6. Publishes the part to SOLIDWORKS MBD PDF.

// 7. Examine the Immediate window and c:\temp.

//

// NOTE: Because the part is used elsewhere, do not save changes.

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


using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 

namespace STEP242_CSharp

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

            ModelDoc2 swModel;

            ModelDocExtension swModDocExt;

            MBDSTEP242Data swMBDSTEP242Data;

            MBD3DPdfData swMBD3DPDFData2;

            int status;

            string fileName;

            object standardViews;

            int[] viewIDs = new int[3];

            int errors = 0;

            int warnings = 0;

 

            fileName = @"C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2025\samples\tutorial\api\block.sldprt";

            swModel = swApp.OpenDoc6(fileName, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings);

            swModDocExt = swModel.Extension;

 

            swMBDSTEP242Data = (MBDSTEP242Data)swModDocExt.GetMBDSTEP242Data();

            swMBD3DPDFData2 = (MBD3DPdfData)swModDocExt.GetMBD3DPdfData();

 

            // Populate IMBD3DPdfData2

            swMBD3DPDFData2.CreateAttachSTEP242 = true;

            swMBD3DPDFData2.STEP242Edition = (int)swMBDSTEP242PublishEdition_e.swPublishSTEP242Edition_3_0;

            // Set path and file name for SOLIDWORKS MBD 3D PDF

            swMBD3DPDFData2.FilePath = @"c:\temp\MyBlockMBD.PDF";

            // Set SOLIDWORKS MBD 3D PDF theme

            swMBD3DPDFData2.ThemeName = @"E:\Program Files\SolidWorks Corp\SOLIDWORKS\data\themes\template_coverpage_multipleviewports_stylized\theme.xml";

            // Set standard views for SOLIDWORKS MBD 3D PDF

            viewIDs[0] = (int)swStandardViews_e.swFrontView;

            viewIDs[1] = (int)swStandardViews_e.swTopView;

            viewIDs[2] = (int)swStandardViews_e.swDimetricView;

            standardViews = viewIDs;

            swMBD3DPDFData2.SetStandardViews(standardViews);

 

            // Populate IMBDSTEP242Data

            swMBDSTEP242Data.PublishFileName = @"C:\Temp\MyBlockMBDSTEP242.stp";

            swMBDSTEP242Data.STEP242Edition = (int)swMBDSTEP242PublishEdition_e.swPublishSTEP242Edition_3_0;

            swMBDSTEP242Data.PublishWithAllCustomProperties = true;

 

            // Dim CusPropNames(1) As String

            // CusPropNames(0) = "MIKCustom"

            // CusPropNames(1) = "MIKConfig"

            // swMBDSTEP242Data.CusPropertiesToPublish = CusPropNames

 

            swMBDSTEP242Data.SplitPeriodicFaces = false;

            swMBDSTEP242Data.ExportFaceEdgeProperties = true;

 

            // Publish

            status = swModDocExt.PublishSTEP242File2(swMBDSTEP242Data);

            status = swModDocExt.PublishTo3DPDF(swMBD3DPDFData2);

        }

 

        // 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:   Export SOLIDWORKS MBD to STEP 242 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) 2025 SP03

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.