How to change the note in BomTalbe?

D

Debug.print  Bottom Code , Result

    PART NUMBER 材料    质量    QTY.   

1   件号1-3法兰 16MnII  11.33   1  

2   件号1-4接管 20  6.30    1 

My question

How to change "件号1-4接管" to "Pipe" ("件号1-4接管" replace "Pipe")

Programe Code


Dim swApp As SldWorks.SldWorks
Dim DrawDoc As SldWorks.DrawingDoc
Dim TableAnn As SldWorks.TableAnnotation
Dim BOM As SldWorks.BomTableAnnotation '.TableAnnotation ' This can be either type
Dim View As SldWorks.View

Sub main()

Set swApp = Application.SldWorks
Set DrawDoc = swApp.ActiveDoc
Set View = DrawDoc.GetFirstView ' this is the sheet
Set TableAnn = View.GetFirstTableAnnotation

Do While Not TableAnn Is Nothing
    If TableAnn.Type = 2 Then '2 is the bom table type
        Set BOM = TableAnn
        Exit Do
    End If
    Set TableAnn = TableAnn.GetNext
Loop

If BOM Is Nothing Then
    Debug.Print ("BOM was not found")
Else
    Dim Txt As String
    Dim Row As Long
    Dim Col As Long
    For Row = 0 To BOM.RowCount - 1
    Txt = ""
        For Col = 0 To BOM.ColumnCount - 1
            Txt = Txt & BOM.Text(Row, Col) & vbTab
        Next Col
        Debug.Print Txt
    Next Row
End If
Debug.Print "Done"
End Sub

--------------

This program  from web site --- https://forum.solidworks.com/message/132872#132872

Thank.

SolidworksApi macros
Answers 2
YN
YN 2012-02-26 Best Answer

In this tip, https://forum.solidworks.com/message/110919#110919

like code is

---------

Private Sub DeleteAllSwBomTables()

  Dim swDraw As SldWorks.DrawingDoc
  Dim swView As SldWorks.View
  Dim swAnn As SldWorks.Annotation
  Dim swSelData As SldWorks.SelectData
  Dim Boolstatus As Boolean
  Dim SwApp As SldWorks.SldWorks
  Dim SwModel As SldWorks.ModelDoc2
  Set SwApp = Application.SldWorks
  Set SwModel = SwApp.ActiveDoc
  Set swDraw = SwModel
  Set swView = swDraw.GetFirstView
  'Loop through the views and delete the SW BOM if they exists
  While Not swView Is Nothing
    Debug.Print " View = " & swView.GetName2
    Set swAnn = swView.GetFirstAnnotation3
    While Not swAnn Is Nothing
      'Debug.Print swAnn.GetType
      If swTableAnnotation = swAnn.GetType Then
        Debug.Print "GetType--" & swAnn.GetType & " , GetName--" & swAnn.GetName
        Boolstatus = swAnn.Select3(True, swSelData)
        Debug.Assert Boolstatus
      End If
      Set swAnn = swAnn.GetNext3
    Wend
    Set swView = swView.GetNextView
  Wend
  SwModel.EditDelete
End Sub

---------------------

Debug.print result

View = 件号1管箱

GetType--14 , GetName--细节项目104

View = 件号1管箱左

View = 件号1管箱右

-----

My question

GetType--14 ---------GetName--细节项目104 -----------What mean for "细节项目104"

YN
YN 2012-02-27

'Get Table Annotation and Contents Example (VB)

'This example shows how to get the table annotation and its contents.

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

'

' Preconditions: Drawing must be open.

'

' Postconditions: None

'

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

Option Explicit

Sub ProcessTable _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swTable As SldWorks.TableAnnotation _

)

    Dim swAnn                   As SldWorks.Annotation

    Dim nNumCol                 As Long

    Dim nNumRow                 As Long

    Dim sRowStr                 As String

    Dim i                       As Long

    Dim j                       As Long

    Set swAnn = swTable.GetAnnotation

   

    nNumCol = swTable.ColumnCount

    nNumRow = swTable.RowCount

    ' Show the name and type of table

    Debug.Print "    " & swAnn.GetName & " <" & swTable.Type & ">"

   

    ' Get the table contents

    For i = 0 To nNumRow - 1

        sRowStr = "      ["

        For j = 0 To nNumCol - 1

            sRowStr = sRowStr & swTable.Text(i, j) & ","

        Next j

   ' Show the table contents

        Debug.Print Left(sRowStr, Len(sRowStr) - 1) & "]"

    Next i

End Sub

Sub main()

    Dim swApp                   As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swDraw                  As SldWorks.DrawingDoc

    Dim swView                  As SldWorks.View

    Dim swTable                 As SldWorks.TableAnnotation

    Dim bRet                    As Boolean

   

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

   

    Debug.Print "File = " & swModel.GetPathName

    ' Get the first view

    Set swView = swDraw.GetFirstView

    Do While Not swView Is Nothing

        ' Show the name of the view

        Debug.Print "  " & swView.Name

        ' Get the first table annotation for this view

        Set swTable = swView.GetFirstTableAnnotation

        Do While Not swTable Is Nothing

            ProcessTable swApp, swModel, swTable

       

            ' Get next table annotation for this view

            Set swTable = swTable.GetNext

        Loop

        ' Get the next view

        Set swView = swView.GetNextView

    Loop

End Sub

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

debug.print result

File = F:\BE(J)S\BES500-2.5-55-6/25-2I\件号1管箱.SLDDRW

  件号1管箱

    细节项目104 <2>

      [6,,,1,Q345R,,49.14,]

      [5,,,2,20,4.58,9.16,]

      [4,HG/T20592-2009, 法兰 WN250-25(B) RF,2,16MnII,11.33,22.66,]

      [3,,,1,Q345R,,73.85,]

      [2,,,1,Q345R,,200.58,]

      [1,,,1,Q345R,,118.72,]

      [序号,标 准 号,名        称, 数量,材    料,质量(单),质量(合),备 注]

  件号1管箱左

  件号1管箱右