0 Replies Latest reply on Sep 16, 2015 7:01 AM by Henrich-Jürgen Kuklane

    Help me modify Vba code (BOM export)

    Henrich-Jürgen Kuklane

      Hey

       

      I need help

       

      This code makes New BOM on a drawing and prints all columns of BOM separated by commas

       

      I want to use similar code to use on my active Model and print BOM from model i have tried few thing but i have failed maybe someone can help me

       

      Thank you in advance

       

      CODE:

      Option Explicit

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swModelDocExt As SldWorks.ModelDocExtension

      Dim swDrawing As SldWorks.DrawingDoc

      Dim swSelMgr As SldWorks.SelectionMgr

      Dim swView As SldWorks.View

      Dim swBomTable As SldWorks.BomTableAnnotation

      Dim swTable As SldWorks.TableAnnotation

      Dim vPickPt As Variant

      Dim nNumCol As Long

      Dim nNumRow As Long

      Dim sRowStr As String

      Dim i As Long

      Dim j As Long

      Dim bRet As Boolean

      Dim fileName As String

      Dim errors As Long

      Dim warnings As Long

      Sub main()

          Set swApp = Application.SldWorks

          'Open drawing document and select drawing view

          fileName = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\driveworksxpress\mobile gantry.slddrw"

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

          Set swDrawing = swModel

          Set swModelDocExt = swModel.Extension

          bRet = swDrawing.ActivateView("Drawing View4")

          bRet = swModelDocExt.SelectByID2("Drawing View4", "DRAWINGVIEW", 0.130207615492954, 0.11628112033195, 0, False, 0, Nothing, 0)

          'Insert BOM table

          Set swSelMgr = swModel.SelectionManager

          Set swView = swSelMgr.GetSelectedObject6(1, -1)

          vPickPt = swSelMgr.GetSelectionPoint2(1, -1)

          Set swBomTable = swView.InsertBomTable2(False, vPickPt(0), vPickPt(1), swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, swBomType_e.swBomType_Indented, "", "")

          Set swTable = swBomTable

          nNumCol = swTable.ColumnCount

          nNumRow = swTable.rowCount

          'List BOM contents

          For i = 0 To nNumRow - 1

              sRowStr = ""

              For j = 0 To nNumCol - 1

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

              Next j

              Debug.Print Strings.Left(sRowStr, Len(sRowStr) - 1)

          Next i

      End Sub