Hide Table of Contents

Write Parasolid Partition Stream to File Example (VB.NET)

This example shows how to write a Parasolid partition stream to a file for a part or assembly using the SolidWorks Document Manager API.

 
NOTE: To get the name of the stream and a preview bitmap of the sheet active when the drawing was last saved, use ISwDMDocument10::GetPreviewBitmap and ISwDMDocument10::PreviewStreamName. To get the name of the streams and the preview bitmaps for all sheets in a drawing, use ISwDMSheet2::GetPreviewPNGBitmap and
ISwDMSheet2::PreviewPNGStreamName.

'---------------------------------------------------------------------------
' Preconditions:
' 1. Read the SolidWorks Document Manager API Getting Started
'    topic and ensure that the required DLLs have been registered.
' 2. Copy and paste this module into a C# console application
'    in Microsoft Visual Studio.
' 3. Ensure that the specified part exists (or point to
'    another part or assembly).
' 4. Add the SolidWorks.Interop.swdocumentmgr.dll reference
'    to the project:
'    a. Right-click the solution in Solution Explorer.
'    b. Select Add Reference.
'    c. Click the Browse tab.
'    d. Load:

'    
<SolidWorks_install_dir>\api\redist\CLR2\SolidWorks.Interop.swdocumentmgr.dll
' 5. Add the following references to the project:
'    
System.Drawing.dll, stdole.dll,
'    and Microsoft.VisualBasic.Compatibility.VB6.dll.
' 6. Substitute <your_license_code> with your SolidWorks
'    Document Manager license key.
' 7. Compile and run this program in Debug mode.

' Postconditions: Inspect the Output Window and the code
' to see how the API is used.
'---------------------------------------------------------
------------------

Imports System
Imports System.Diagnostics
Imports SolidWorks.Interop.swdocumentmgr
Imports Microsoft.VisualBasic.Compatibility.VB6
Imports System.Drawing.Image
Imports stdole

Module Module1

    
Public Enum SwDmDocumentVersion_e
        SwDmDocumentVersionSolidWorks_2000 = 1500
        SwDmDocumentVersionSolidWorks_2001 = 1750
        SwDmDocumentVersionSolidWorks_2001Plus = 1950
        SwDmDocumentVersionSolidWorks_2003 = 2200
        SwDmDocumentVersionSolidWorks_2004 = 2500
        SwDmDocumentVersionSolidWorks_2005 = 2800
        SwDmDocumentVersionSolidWorks_2006 = 3100
        SwDmDocumentVersionSolidWorks_2007 = 3400
        SwDmDocumentVersionSolidWorks_2008 = 3800
        SwDmDocumentVersionSolidWorks_2009 = 4100
        SwDmDocumentVersionSolidWorks_2010 = 4400
    
End Enum


    Sub main()

        
Const sLicenseKey As String = "<your_license_code>" 'Specify license key
        Const sDocFileName As String = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\multibody\multi_inter.sldprt" 'Specify document
        Const sExtractDir As String = "c:\temp\"


        Dim swClassFact As SwDMClassFactory
        
Dim swDocMgr As SwDMApplication
        
Dim swDoc As SwDMDocument
        
Dim swCfgMgr As SwDMConfigurationMgr
        
Dim vCfgNameArr As Object
        Dim vCfgName As String
        Dim swCfg As SwDMConfiguration2
        
Dim pPreview As IPictureDisp
        
Dim nDocType As Long
        Dim nRetVal As Long
        Dim i As Long
        Dim image As Drawing.Image

        
' Determine type of SolidWorks file based on file extension
        If InStr(LCase(sDocFileName), "sldprt") > 0 Then
            nDocType = SwDmDocumentType.swDmDocumentPart
        
ElseIf InStr(LCase(sDocFileName), "sldasm") > 0 Then
            nDocType = SwDmDocumentType.swDmDocumentAssembly
        
ElseIf InStr(LCase(sDocFileName), "slddrw") > 0 Then
            nDocType = SwDmDocumentType.swDmDocumentDrawing
        
Else

            ' Probably not a SolidWorks file
            nDocType = SwDmDocumentType.swDmDocumentUnknown

            
' so cannot open
            Exit Sub
        End If

        ' Because drawing documents do not have configurations,
        ' only continue running the macro if the document
        ' is a part or assembly document

        If (nDocType <> SwDmDocumentType.swDmDocumentDrawing) Then

            swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")
            swDocMgr = swClassFact.GetApplication(sLicenseKey)
            swDoc = swDocMgr.GetDocument(sDocFileName, nDocType,
False, nRetVal) : Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone = nRetVal)
            swCfgMgr = swDoc.ConfigurationManager


            Debug.Print(
"File = " & swDoc.FullName)
            Debug.Print(
"  ActiveCfgName    = " & swCfgMgr.GetActiveConfigurationName)
            Debug.Print(
"")
            Debug.Print(
"  Version          = " & swDoc.GetVersion)
            Debug.Print(
"  Author           = " & swDoc.Author)
            Debug.Print(
"  Comments         = " & swDoc.Comments)
            Debug.Print(
"  CreationDate     = " & swDoc.CreationDate)
            Debug.Print(
"  Keywords         = " & swDoc.Keywords)
            Debug.Print(
"  LastSavedBy      = " & swDoc.LastSavedBy)
            Debug.Print(
"  LastSavedDate    = " & swDoc.LastSavedDate)
            Debug.Print(
"  Subject          = " & swDoc.Subject)
            Debug.Print(
"  Title            = " & swDoc.Title)

            vCfgNameArr = swCfgMgr.GetConfigurationNames

            
For Each vCfgName In vCfgNameArr
                swCfg = swCfgMgr.GetConfigurationByName(vCfgName)
                pPreview = swCfg.GetPreviewBitmap(nRetVal)
                image = Support.IPictureDispToImage(pPreview)
                image.Save(
"c:\temp\" + vCfgName + ".bmp")

                Debug.Print(
"  " & vCfgName)
                Debug.Print(
"    Description              = " & swCfg.Description)
                Debug.Print(
"    ParentCfgName            = " & swCfg.GetParentConfigurationName)
                Debug.Print(
"    Preview   stream         = " & swCfg.PreviewStreamName)

                
Select Case swDoc.GetVersion

                    
Case SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2000, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2001, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2001Plus, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2003
                        Debug.Print(
"    Body      stream         = " & swCfg.StreamName)
                        Debug.Print(
"      Body count             = " & swCfg.GetBodiesCount - 1)

                        
For i = 0 To swCfg.GetBodiesCount - 1
                            nRetVal = swCfg.GetBody(i, sExtractDir & vCfgName &
"_" & i & ".x_b") : Debug.Assert(SwDmBodyError.swDmBodyErrorNone = nRetVal)
                        
Next i

                    
Case SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2004, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2005, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2006, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2007, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2008, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2009, SwDmDocumentVersion_e.SwDmDocumentVersionSolidWorks_2010
                        Debug.Print(
"    Partition stream         = " & swCfg.StreamName)

                        
' SwDMConfiguration2::GetPartitionStream takes filename as an input and writes
                        ' to it. *.xmp_bin (for NTFS) and *.p_b (for FAT) are the valid extensions
                        ' of a partition file. PK_PARTITION_receive_u will takes this file name as
                        ' input to get partitions and bodies in it.
                        ' Refer to Parasolid documentation for details.

                        nRetVal = swCfg.GetPartitionStream(sExtractDir & vCfgName & ".xmp_bin") : Debug.Assert(SwDmBodyError.swDmBodyErrorNone = nRetVal)

                    
Case Else
                        Debug.Assert(False)
                
End Select
            Next
        End If
    End Sub

End
Module

 



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:   Write Parasolid Partition Stream to File 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) 2014 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.