7 Replies Latest reply on May 15, 2017 8:14 AM by Deepak Gupta

    Modify macro to insert part (with selection)

    Mark Bradford

      Good afternoon,

           I have recorded a macro that uses the "insert part" command and functions correctly for a particular part file.   I would to modify the macro so that it can work with any "active part" rather than a file with a particular part name.   I would also like the macro to ensure certain settings are applied (see attached image) when inserting the part file, and also save the iges file to the same path as the active file that the macro was started with.   Please let me know if you have any questions.


      Thanks so much for any help you can offer.    I really appreciate it.



      Image 001.jpg


      ' ******************************************************************************
      ' C:\Users\mbradford\AppData\Local\Temp\swx1512\Macro1.swb - macro recorded on 05/03/17 by mbradford
      ' ******************************************************************************
      Dim swApp As Object
      Dim Part As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long
      Sub main()
      Set swApp = Application.SldWorks
      Set Part = swApp.ActiveDoc
      Dim myModelView As Object
      Set myModelView = Part.ActiveView
      myModelView.FrameState = swWindowState_e.swWindowMaximized
      ' New Document
      Dim swSheetWidth As Double
      swSheetWidth = 0
      Dim swSheetHeight As Double
      swSheetHeight = 0
      Set Part = swApp.NewDocument("\\DELLSERVER\Departments\DESIGN LIBRARY\PFG part templates\TEMPLATES\Part-PFG.prtdot", 0, swSheetWidth, swSheetHeight)
      Dim swPart As PartDoc
      Set swPart = Part
      swApp.ActivateDoc2 "Part3", False, longstatus
      Set Part = swApp.ActiveDoc
      Dim myFeature As Object
      Set myFeature = Part.InsertPart2("C:\Users\mbradford\Desktop\5280A\Model\5280A - Base # 1 LH.sldprt", 34001)
      ' Save As
      longstatus = Part.SaveAs3("C:\Users\mbradford\Desktop\5280A - Base # 1 LH.IGS", 0, 0)
      End Sub