Hide Table of Contents

Get Model Pathnames from a BOM Table Example (VB.NET)

This example shows how to get the model pathnames from a specified row of a BOM table annotation.

'----------------------------------------------------------------------------
' Preconditions:
' 1. Open a drawing containing a BOM table annotation named Bill of Materials1.
' 2. Open an Immediate Window.
'
' Postconditions: Inspect the Immediate Window for model pathnames.
' ---------------------------------------------------------------------------

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Imports System.Diagnostics

Partial Class SolidWorksMacro

    
Sub Main()

        
Dim swModel As ModelDoc2
        
Dim swDraw As DrawingDoc
        
Dim swFeat As Feature
        
Dim swBomFeat As BomFeature

        swModel = swApp.ActiveDoc
        swDraw = swModel
        swFeat = swModel.FirstFeature
        
Do While Not swFeat Is Nothing
            If (swFeat.GetTypeName = "BomFeat") Then
                Debug.Print("******************************")
                Debug.Print(
"Feature Name = " & swFeat.Name)
                swBomFeat = swFeat.GetSpecificFeature2
                
If (swFeat.Name = "Bill of Materials1") Then
                    ProcessBomFeature(swApp, swModel, swBomFeat)
                
End If
            End If
            swFeat = swFeat.GetNextFeature
        
Loop
    End Sub
    Sub ProcessBomFeature(ByVal swApp As SldWorks, ByVal swModel As ModelDoc2, ByVal swBomFeat As BomFeature)
        GetPathNames(swApp, swBomFeat)
    
End Sub

    Sub GetPathNames(ByVal swApp As SldWorks, ByVal swBomFeature As BomFeature)
        
Dim vConfigurations As Object
        Dim strConfiguration As String
        Dim vVisibility As Object = Nothing
        Dim lIdx As Long
        Dim lNumConfigurations As Long
        Dim lNumRow As Long
        Dim lNumColumn As Long
        Dim lRow As Long
        Dim swBOMTableAnnotation As BomTableAnnotation
        
Dim swTableAnnotation As TableAnnotation
        
Dim swDocument As ModelDoc2
        
Dim swAssembly As AssemblyDoc
        
Dim strDocumentName As String
        Dim lStartRow As Long
        Dim bGetVisible As Boolean
        Dim vModelPathNames As Object
        Dim strItemNumber As String = ""
        Dim strPartNumber As String = ""
        Dim vModelPathName As Object
        Dim strModelPathName As String

        strDocumentName = swBomFeature.GetReferencedModelName
        swDocument = swApp.GetOpenDocumentByName(strDocumentName)
        Debug.Print(
"Referenced model = " & strDocumentName)
        swAssembly = swDocument

        
' For now assume we have only 1 table annotation.
        swBOMTableAnnotation = swBomFeature.GetTableAnnotations(0)
        swTableAnnotation = swBOMTableAnnotation
        lNumRow = swTableAnnotation.RowCount
        lNumColumn = swTableAnnotation.ColumnCount

        lStartRow = 1

        
If (Not (swTableAnnotation.TitleVisible = False)) Then
            lStartRow = 2
        
End If

        bGetVisible = False
        Debug.Print("# configurations = " & swBomFeature.GetConfigurationCount(bGetVisible))
        vConfigurations = swBomFeature.GetConfigurations(bGetVisible, vVisibility)

        
If (Not IsNothing(vConfigurations)) Then
            lNumConfigurations = UBound(vConfigurations) - LBound(vConfigurations) + 1
            
For lIdx = 0 To (lNumConfigurations - 1)
                strConfiguration = vConfigurations(lIdx)
                Debug.Print(
"")
                Debug.Print(
"Configuration: " & strConfiguration)

                
For lRow = lStartRow To (lNumRow - 1)
                    Debug.Print(
"  row = " & (lRow - lStartRow + 1))
                    vModelPathNames = swTableAnnotation.GetModelPathNames(lRow, strItemNumber, strPartNumber)

                    Debug.Print(
"    item number = " & strItemNumber)
                    Debug.Print(
"    part number = " & strPartNumber)

                    
If (Not IsNothing(vModelPathNames)) Then
                        Debug.Print("    # models contributing to row = " & swTableAnnotation.GetModelPathNamesCount(lRow))
                        
For Each vModelPathName In vModelPathNames
                            strModelPathName = vModelPathName
                            Debug.Print(
"       " & strModelPathName)
                        
Next vModelPathName
                    
Else
                        Debug.Print("    # models contributing to row = 0")
                        Debug.Assert(
False)
                    
End If
                Next lRow
            
Next lIdx
        
End If
    End Sub

    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:   Get Model Pathnames from a BOM Table 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.