Flateen a part

I'm trying to flatten a sheetmetal part. The piece of code i get from the macro is

Sub main()

  Set swApp = _

Application.SldWorks

Set Part = swApp.ActiveDoc

Part.ClearSelection2 True

longstatus = Part.SetBendState(2)

boolstatus = Part.EditRebuild3()

End Sub

The above code is not working while running macro as well as in my application code.

Please suggest a method to flatten a part.

SolidworksApi macros