17 Replies Latest reply on May 3, 2016 10:15 AM by Deepak Gupta

    How do you code a macro to point to the default assembly template location?

    Alfred Jelinek

      I currently have a large macro to create an assembly then subassemblies and mates, mate references....etc. for Designing of Stamping Dies.

       

      The last thing I think I need to correct is I currently have the code pointing to a location of my assembly template file....but I would like to eventually let others use it so I would like to correct the code to point to the default Solidworks assembly template set in the options.

       

      right now the line with:

      "C:\Users\aljel\Desktop\Mill Tool Templates - 2016\templates\Assembly.asmdot"

      Will not work for others. (LocationInfo.Caption and AppearAs.Caption are the labels where the final folder and file name are shown for the user to verify the selections made are correct.)

       

      my code for this is currently:

       

      'create new assembly
      Set swApp = _
      Application.SldWorks
      Set Part = swApp.NewDocument("C:\Users\aljel\Desktop\Mill Tool Templates - 2016\templates\Assembly.asmdot", 0, 0, 0)
      swApp.ActivateDoc2 "Assem1", False, longstatus
      Set Part = swApp.ActiveDoc
      longstatus = Part.SaveAs3(LocationInfo.Caption, 0, 2)

       

      'close default/all assembly file(s)
      boolstatus = swApp.CloseAllDocuments(True)

       

      'open new assembly
      Set Part = swApp.OpenDoc6(LocationInfo.Caption, 2, 0, "", longstatus, longwarnings)
      swApp.ActivateDoc2 AppearAs.Caption, False, longstatus
      Set Part = swApp.ActiveDoc
      Set Part = swApp.ActiveDoc
      Dim myModelView As Object
      Set myModelView = Part.ActiveView
      myModelView.FrameLeft = 0
      myModelView.FrameTop = 0
      Set myModelView = Part.ActiveView
      myModelView.FrameState = swWindowState_e.swWindowMaximized
      Set myModelView = Part.ActiveView
      myModelView.FrameState = swWindowState_e.swWindowMaximized

       

       

      Thank you for your help!!!

       

      Al