1 Reply Latest reply on Nov 22, 2017 5:24 AM by Taylor Duran

    Macro for Deleting Item off Current Drawing Sheet

    Taylor Duran

      I am trying to create a macro that will delete a note off of a current drawing sheet format.

      The note is standard on the template but is only needed on certain drawings.

      When I recorded the macro it worked fine but would only delete the note from the single sheet in the drawing and wouldn't work on any other.

       

      I think I am am close but am having trouble specifying the current sheet. This is the code I have so far. Any help & suggestions would be greatly appreciated

       

      Sub main()

       

       

      Dim swApp As Object

       

       

      Dim Part As Object

      Dim swModel As SldWorks.ModelDoc2

      Dim swConfig As SldWorks.Configuration

      Dim swDrawingDoc As SldWorks.DrawingDoc

      Dim swSheet As SldWorks.Sheet

      Dim nDocType As Long

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

       

       

       

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Set swDrawingDoc = swModel

      Set swSheet = swDrawingDoc.GetCurrentSheet

       

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SelectByID2("& swSheet.GetName() &", "SHEET", 8.88251268656716E-02, 0.249583432835821, 0, False, 0, Nothing, 0)

      Part.EditTemplate

      Part.EditSketch

      Part.ClearSelection2 True

      boolstatus = Part.Extension.SelectByID2("DetailItem159@ & swSheet.GetSheetFormatName() & ", "NOTE", 0.390947932206707, 0.230293898698196, 0, False, 0, Nothing, 0)

      Part.EditDelete

      boolstatus = Part.Extension.SelectByID2(" & swSheet.GetSheetFormatName() & ", "SHEET", 0.284276326189945, 0.223110625565754, 0, False, 0, Nothing, 0)

      Part.EditSheet

      Part.EditSketch

      Part.ClearSelection2 True

       

       

      ' Zoom To Fit

      Part.ViewZoomtofit2

      End Sub

       

       

      Thanks in advance!

      -Taylor

        • Re: Macro for Deleting Item off Current Drawing Sheet
          Taylor Duran

          I figured it out!

          The fix is below in case anyone has run into a similar issue.

           

          There was a slight syntax error that was preventing the proper note from being selected.

          "DetailItem159@" + swSheet.GetSheetFormatName seemed to fix it

           

           

          Sub main()

           

           

          Dim swApp As Object

           

           

          Dim Part As Object

          Dim swModel As SldWorks.ModelDoc2

          Dim swConfig As SldWorks.Configuration

          Dim swDrawingDoc As SldWorks.DrawingDoc

          Dim swSheet As SldWorks.Sheet

          Dim nDocType As Long

          Dim boolstatus As Boolean

          Dim longstatus As Long, longwarnings As Long

           

           

           

           

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

          Set swDrawingDoc = swModel

          Set swSheet = swDrawingDoc.GetCurrentSheet

           

           

          Set Part = swApp.ActiveDoc

          boolstatus = Part.Extension.SelectByID2(swSheet.GetName, "SHEET", 8.88251268656716E-02, 0.249583432835821, 0, False, 0, Nothing, 0)

          Part.EditTemplate

          Part.EditSketch

          Part.ClearSelection2 True

          boolstatus = Part.Extension.SelectByID2("DetailItem159@" + swSheet.GetSheetFormatName, "NOTE", 0.390947932206707, 0.230293898698196, 0, False, 0, Nothing, 0)

          Part.EditDelete

          boolstatus = Part.Extension.SelectByID2(swSheet.GetSheetFormatName, "SHEET", 0.284276326189945, 0.223110625565754, 0, False, 0, Nothing, 0)

          Part.EditSheet

          Part.EditSketch

          Part.ClearSelection2 True

           

           

          ' Zoom To Fit

          Part.ViewZoomtofit2

          End Sub