1 Reply Latest reply on Oct 1, 2014 9:31 AM by Jesse Seger

    Name Sketch Upon Creation

    Manu Rao

      I need to create a 3D sketch with a specific name so that I can call it out later.


      Upon creation of a new sketch, Solidworks provides a name for it automatically, but this depends on how many sketches were created before. I would like it to create a sketch with a specified name so that I can selectbyid2 later regardless of how many other sketches there are.

        • Re: Name Sketch Upon Creation
          Jesse Seger

          Here is a macro that will prompt you to name the sketch.  Add a macro button to your toolbar to run this macro.




          Dim swApp As SldWorks.SldWorks

          Dim swModel As ModelDoc2

          Dim swSketchMgr As SketchManager

          Dim swSketch As Sketch

          Dim swFeat As Feature

          Dim name As String



          Sub main()



          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swSketchMgr = swModel.SketchManager



          name = InputBox("Name Sketch", "Insert 3D Sketch")



          If name = "" Then

              MsgBox "Invalid Sketch Name"


          End If



          swSketchMgr.Insert3DSketch False

          Set swSketch = swSketchMgr.ActiveSketch

          Set swFeat = swSketch

          swFeat.name = name

          swSketchMgr.Insert3DSketch False



          End Sub