1 Reply Latest reply on Oct 22, 2014 2:30 PM by Daniel Andersson

    Repetitive Sketch Operation Macro

    Parish Parishram

      Hi,

       

      Am trying to perform a fillet/ trim-extend operation on a sketch multiple times. When I record a Macro for one such instance, it records the operation with absolute coordinates. Is there a way to record or change the code to relative coordinates? Am thinking i could then just pick a new location and run the Macro each time.

       

       

      ------

      Sub main()

       

       

      Set swApp = _

      Application.SldWorks

       

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 4.88842062031602E-03, 1.17409886110679E-03, 5.00000000000025E-05, True, 0, Nothing, 0)

      boolstatus = Part.Extension.SelectByID2("Fillet<1>", "SKETCHSEGMENT", 5.16552479057979E-03, 9.9824429151632E-04, 5.00000000000038E-05, True, 0, Nothing, 0)

      Dim skSegment As Object

      Set skSegment = Part.SketchManager.CreateFillet(0.00012954, 1)

      Part.SetPickMode

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

      boolstatus = Part.SketchManager.SketchExtend(4.90973632572092E-03, 1.15811208205311E-03, 0)

      Part.SetPickMode

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

      boolstatus = Part.SketchManager.SketchExtend(4.96302558923319E-03, 8.91665764491791E-04, 0)

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 4.93105203112583E-03, 7.5844260571113E-04, 5.00000000000054E-05, True, 0, Nothing, 0)

      boolstatus = Part.Extension.SelectByID2("Fillet<1>", "SKETCHSEGMENT", 5.12822230612121E-03, 8.17060795574621E-04, 5.0000000000005E-05, True, 0, Nothing, 0)

      Set skSegment = Part.SketchManager.CreateFillet(0.00012954, 1)

      Part.SetPickMode

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

      boolstatus = Part.SketchManager.SketchExtend(4.9044073993697E-03, 6.83837636793959E-04, 0)

      Part.SetPickMode

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)

      boolstatus = Part.SketchManager.SketchExtend(4.97901236828687E-03, 9.8225751246264E-04, 0)

      boolstatus = Part.Extension.SelectByID2("Arc2507", "SKETCHSEGMENT", 4.95871782985486E-03, 8.78854032100175E-04, 0, False, 2, Nothing, 0)

      boolstatus = Part.SketchManager.SketchTrim(4, 0, 0, 0)

      boolstatus = Part.Extension.SelectByID2("D4@Sketch1@BVS_3.51_28mm.SLDPRT", "DIMENSION", 4.85644706220866E-03, 8.27718648277073E-04, 5.00000000000049E-05, False, 0, Nothing, 0)

      Part.ClearSelection2 True

      boolstatus = Part.Extension.SketchBoxSelect("0.004761", "0.001057", "0.000000", "0.004894", "0.000833", "0.000000")

      boolstatus = Part.Extension.SelectByID2("D3@Sketch1@BVS_3.51_28mm.SLDPRT", "DIMENSION", 4.89374954666724E-03, 8.27718648277073E-04, 5.00000000000049E-05, False, 0, Nothing, 0)

      Part.EditDelete

      boolstatus = Part.Extension.SelectByID2("D4@Sketch1@BVS_3.51_28mm.SLDPRT", "DIMENSION", 4.89907847301847E-03, 9.2363932259915E-04, 5.00000000000043E-05, False, 0, Nothing, 0)

      Part.EditDelete

      End Sub

        • Re: Repetitive Sketch Operation Macro
          Daniel Andersson

          To record with other coordinates is not possible. You could edit the code you got to use variables and calculate your needed coordinates. Note that the recorded macro also needs to have the same name of the segments as you had during recording in order to work.

           

          There might be alternative solutions to this, but it is difficult to see since there is no image attached that explains what you do / want to do. I'm thinking in the best case, you do not need, or could extract the coordinates from selected objects instead... etc etc..

           

          Others might have other ideas to present if you add a principle sketch that explains what you are extending and triming.