4 Replies Latest reply on May 31, 2014 4:03 AM by Deepak Gupta

    Create a macro to save the current view of a part as a DXF

    Jacob Suther

      This is my first macro that I have tried to create. I am trying to create one that will take the current view of a part and save it as a dxf. I have seen some that export the flattened pattern of a sheet metal part as a dxf, but I am not working with sheet metal so this is not applicable. I recorded a macro of me going to save as and selecting dxf and the current view which resulted in this:

       

       

      Sub main()

       

      Set swApp = _

      Application.SldWorks

       

      Set Part = swApp.ActiveDoc

      longstatus = Part.SaveAs3("\\2014-04-16\test.DXF", 0, 0)

      Set Part = swApp.ActiveDoc

      Dim myModelView As Object

      Set myModelView = Part.ActiveView

      myModelView.FrameLeft = 0

      myModelView.FrameTop = 22

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      Set Part = swApp.NewDocument("\\Ansi B.drwdot", 0, 0, 0)

      swApp.ActivateDoc2 "Draw4 - SHEET 1", False, longstatus

      Set Part = swApp.ActiveDoc

      Set Part = swApp.ActiveDoc

      Set myModelView = Part.ActiveView

      myModelView.FrameLeft = 0

      myModelView.FrameTop = 22

      Set myModelView = Part.ActiveView

      myModelView.FrameState = swWindowState_e.swWindowMaximized

      swApp.ActivateDoc2 "test.SLDPRT", False, longstatus

      Set Part = swApp.ActiveDoc

      Dim myView As Object

      Set myView = Part.CreateDrawViewFromModelView3("C:\Users\user\Desktop\test.SLDPRT", "*Current", 0, 0, 0)

      boolstatus = Part.DeleteNamedView(*Current) 'There is a syntax error here

      Part.ClearSelection2 True

      End Sub

       

      The editor shows a syntax error at boolstatus = Part.DeleteNamedView(*Current), if I comment this line out and run it gets hung up on the line above it with the error of "Object doesn't support this property or method". Any help would be appreciated.