1 Reply Latest reply on Sep 10, 2013 12:32 PM by Simon Turner

    Insert Bend table Not working using solidworks API

    Vikas DC

      Trying to insert a bend table for a flat pattern view, Nothing happens when this macro is run.(only creates flat pattern view). Try to debug it , Crashes at line

      Set myBendTableAnnot = Fview.InsertBendTable(False, 0.1, 0.15, 1, "A", "C:\Users\Vikas\Documents\SOLIDWORKS DRAWINGS\BendTable.sldbndtbt")

      Not sure whats causing this, Please can anybody help


      ‘This macro will create a Flat pattern View and insert Bend table



      Option Explicit


      Dim swApp As SldWorks.SldWorks

      Dim swModel As ModelDoc2

      Dim swDrawing As DrawingDoc

      Dim filename As String

      Dim ext As String

      Dim fso As Scripting.FileSystemObject


      Dim longerrors As Long, longwarnings As Long



      Sub main()


      Set fso = CreateObject("Scripting.FileSystemObject")


      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc


      If swModel Is Nothing Then Exit Sub


      filename = swModel.GetPathName

      ' Find all files ending in .SLDPRT

      ext = UCase(Right(filename, 6))

      If ext <> "SLDPRT" And ext <> "SLDASM" Then Exit Sub


      Dim curfilename As String

      curfilename = Left(filename, Len(filename) - 7) & ".SLDDRW"


      ' Check whether file already exists

      If fso.FileExists(curfilename) Then

          If MsgBox(curfilename & " already exists. Overwrite?", vbYesNo + vbQuestion) = vbNo Then Exit Sub

      End If


      ' Get default template

      Dim template As String

      template = swApp.GetUserPreferenceStringValue(swDefaultTemplateDrawing)

      ' NewDocument templateName, paperSize, width, height. Paper Size, Width & Height if specified in template are redundant

      Set swDrawing = swApp.NewDocument(template, 0, 0, 0)


      If swDrawing Is Nothing Then

      MsgBox "Failed to create drawing"

      Exit Sub

      End If


      If (ext = "SLDPRT") Then

          swApp.OpenDoc6 filename, swDocPART, swOpenDocOptions_ReadOnly, "", longerrors, longwarnings

      Else: swApp.OpenDoc6 filename, swDocASSEMBLY, swOpenDocOptions_ReadOnly, "", longerrors, longwarnings

      End If


      ' Get sheet size

      Dim cursheet As sheet

      Dim sheetwidth As Double, sheetheight As Double

      Set cursheet = swDrawing.GetCurrentSheet

      1. cursheet.GetSize sheetwidth, sheetheight


      Dim view As view

      Dim vOutline As Variant, vPosition As Variant

      Dim viewWidth As Double, viewHeight As Double


      ' Insert the Flat Pattern View

      Dim Fview As view

      Dim ConfigName As String

      Dim HideBendLines As Boolean

      Dim LocX As Double

      Dim LocY As Double

      Dim LocZ As Double

      Dim FlipView As Boolean

      Dim value As view


      LocX = 0.2

      LocY = 0.1

      LocZ = 0

      HideBendLines = False

      ConfigName = "" 'DefaultSM-FLAT-PATTERN

      Set Fview = swDrawing.CreateFlatPatternViewFromModelView3(filename, ConfigName, LocX, LocY, LocZ, HideBendLines, False)





      'Insert Bend table for the flat pattern


      Dim swView As view

      Dim myBendTableAnnot As BendTableAnnotation

      Dim myBendTableFeat As BendTable

      Dim checkname As String


      Set myBendTableAnnot = Fview.InsertBendTable(False, 0.1, 0.15, 1, "A", "C:\Users\Vikas\Documents\SOLIDWORKS DRAWINGS\BendTable.sldbndtbt")



      Set myBendTableFeat = myBendTableAnnot.BendTable

      Debug.Print myBendTableFeat.GetFeature.Name

      Debug.Print "Starting tag: " & myBendTableFeat.StartingValue

      Debug.Print "swBendTableTagStyle_e option: " & myBendTableFeat.TagStyle

      Debug.Print "Number of bend table annotations: " & myBendTableFeat.GetTableAnnotationCount


      swModel.ClearSelection2 True


      'swApp.CloseDoc filename

      'swApp.CloseDoc curfilename


      End Sub