Hide Table of Contents

Export SOLIDWORKS MBD to STEP 242 Example (VB.NET)

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.

'---------------------------------------------------------------

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Imports System.Runtime.InteropServices

Imports System

Imports System.Runtime.InteropServices.ComTypes

 

 

Partial Class SolidWorksMacro

 

    Public Sub main()

 

        Dim swModel As ModelDoc2

        Dim swModDocExt As ModelDocExtension

        Dim swMBDSTEP242Data As MBDSTEP242Data

        Dim swMBD3DPDFData2 As MBD3DPdfData

        Dim status As Integer

        Dim fileName As String

        Dim standardViews As Object

        Dim viewIDs(2) As Integer

        Dim errors As Integer

        Dim warnings As Integer

 

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

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

        swModDocExt = swModel.Extension

 

        swMBDSTEP242Data = swModDocExt.GetMBDSTEP242Data()

        swMBD3DPDFData2 = swModDocExt.GetMBD3DPdfData()

 

        'Populate IMBD3DPdfData2

        swMBD3DPDFData2.CreateAttachSTEP242 = True

        swMBD3DPDFData2.STEP242Edition = 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) = swStandardViews_e.swFrontView

        viewIDs(1) = swStandardViews_e.swTopView

        viewIDs(2) = swStandardViews_e.swDimetricView

        standardViews = viewIDs

        swMBD3DPDFData2.SetStandardViews(standardViews)

 

        'Populate IMBDSTEP242Data

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

        swMBDSTEP242Data.STEP242Edition = 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)

 

    End Sub

    ''' <summary>

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

    ''' </summary>

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