5 Replies Latest reply on Jul 20, 2015 8:17 AM by Bruce Perry

    Revision table macro

    Michael Raikh

      Hi,

      i've been trying to run a macro i've built, it fills in the revision table.

      -------------------------------------------------------------------------------------------------------------------------------------------------------------------------

       

      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

       

       

      'Edit the Revision Table

      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.2653942284632, 0.2752584044808, 0, False, 0, Nothing, 0)

      Dim currentSheet As Object

      Dim myRevisionTable As Object

      Set currentSheet = Part.GetCurrentSheet()

      Set myRevisionTable = currentSheet.RevisionTable

      longstatus = myRevisionTable.AddRevision("")

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.2498048865494, 0.2679361378244, 0, False, 0, Nothing, 0)

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.2498048865494, 0.2679361378244, 0, False, 0, Nothing, 0)

      'Part.ClearSelection2 True

      Dim myTable As Object

      Set myTable = Part.SelectionManager.GetSelectedObject5(1)

      myTable.Text(2, 0) = "#"

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.2656304306134, 0.2676999356742, 0, False, 0, Nothing, 0)

      'Part.ClearSelection2 True

      Set myTable = Part.SelectionManager.GetSelectedObject5(1)

      myTable.Text(2, 1) = "-"

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.2814559746773, 0.2658103184725, 0, False, 0, Nothing, 0)

      'Part.ClearSelection2 True

      Set myTable = Part.SelectionManager.GetSelectedObject5(1)

      myTable.Text(2, 2) = "0"

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.3147604778567, 0.2676999356742, 0, False, 0, Nothing, 0)

      'Part.ClearSelection2 True

      Set myTable = Part.SelectionManager.GetSelectedObject5(1)

      myTable.Text(2, 3) = "New Part"

      boolstatus = Part.Extension.SelectByID2("DetailItem504@Sheet1", "REVISIONTABLE", 0.3964864218288, 0.2676999356742, 0, False, 0, Nothing, 0)

      'Part.ClearSelection2 True

      Set myTable = Part.SelectionManager.GetSelectedObject5(1)

      myTable.Text(2, 5) = "Yossi B.-ZAE"

       

       

      'Delete the Path line at the bottom of the SHEET

      boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0.2299456113629, 0.09981751925915, 0, False, 0, Nothing, 0)

      Part.EditTemplate

      Part.EditSketch

      Part.ClearSelection2 True

      boolstatus = Part.Extension.SelectByID2("DetailItem503@Sheet Format1", "NOTE", 0.2930098110623, 0.00263396438633, 0, False, 0, Nothing, 0)

      Part.EditDelete

      Part.EditSheet

      Part.EditSketch

      End Sub

       

      it runs into an Run-time error '91'.

       

      it does work some times, some times not.

      what could be the solution?

       

      I'm running SW2010

        • Re: Revision table macro
          Michael Raikh

          Any thoughts?

          I've tried replacing some lines, deleting others and what not..

          i'll appriciate some little help..

          • Re: Revision table macro
            Bruce Perry

            I think what your going to find is that "DetailItem504@Sheet1" isn't always "DetailItem504@Sheet1". it could be 505 or 506 or something entirely different. use the code below to see if that's true.

             

            There was a nice little code that someone wrote I commented out somethings to serve my purpose:

            '---------------------------------

            ' Precondition: Drawing document is open and a note is selected.

            ' Postcondition: Name of the selected note is

            '               changed to "@MYADDIN-ANN1"

            '---------------------------------

            Option Explicit

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swDrawing As SldWorks.DrawingDoc

            Dim swSelMgr As SldWorks.SelectionMgr

            Dim swNote As SldWorks.Note

            Dim swAnn As SldWorks.Annotation

             

            Sub main()

            Set swApp = Application.SldWorks

            Set swModel = swApp.ActiveDoc

            Set swSelMgr = swModel.SelectionManager

            Set swNote = swSelMgr.GetSelectedObject6(1, 0)

            Set swAnn = swNote.GetAnnotation

            Debug.Print swAnn.GetName

             

            ' New name must be unique

            'swAnn.SetName "@MYADDIN-ANN1"

            'MsgBox swAnn.GetName

             

            End Sub

              • Re: Revision table macro
                Michael Raikh

                hi,

                thanks for yoyr answer, i've tried to apply this code to mine, didn't seem to work though...

                is it too nuch trouble to ask of you to show me how the code should look like after you apply the necessary lines?

                  • Re: Revision table macro
                    Bruce Perry

                    It looks as if you will have to modify the code some for your use.

                     

                    But open up a new module and place the code there and just select run.

                    The code should run ok from there. Without running any other of your code.

                    Make sure a note is physically selected before running it or it will not work.

                    Below the code in the intermediate window is where you should see the output.

                    Or where it will DEBUG.PRINT