4 Replies Latest reply on Jan 16, 2018 5:29 PM by Colt Carson

    Unable to replace revision block and edit text in cells during same macro routine.

    Colt Carson

      I am trying to cobble together a macro to replace our revision table template on existing drawings and then reenter the old revision information. The problem arises when the macro reaches the point of editing the cells in the freshly inserted table. In the attached macro 'replaceRevisionTableTest' it appears to edit the cells in the table with the new data but once ForceRebuild3 is called the edits vanish. If I then run the attached macro 'onlyModifyRevTable' with nearly identical code it successfully edits the revision table. What is causing this behavior? Why would splitting the code in two different macros make a difference?

       

      I have tried doing a force rebuild & saving the drawing file after each revision addition but that did not solve the problem. Thank you!

        • Re: Unable to replace revision block and edit text in cells during same macro routine.
          Jacob Corder

          try  this

          add this line before you start adding data to the revisiontable

          DoEvents

           

          what this does is it allows all the messages in the message pool to execute.  this may be why 2 separate macros works.

           

           

          DOEvents

            • Re: Unable to replace revision block and edit text in cells during same macro routine.
              Colt Carson

              Thanks for the help Jacob. I tried putting this command where you suggested and at various places in my script but it did not solve the problem. I was really hoping this would do the trick.

               

              This was my final workaround for anyone else that encounters this issue

               

              First macro

              - Export the revision table as a csv file in the

              - replace the revision table

              - add all required rows back to the newly inserted table

              - call the second macro using swApp.RunMacro

               

              Second macro

              - import data from csv

              - insert data into table

                • Re: Unable to replace revision block and edit text in cells during same macro routine.
                  Alex Burnett

                  I know this might be redundant at this point since it sounds like you more or less figured this out but I stumbled through this same issue when writing my C# add-in to update the drawing template which includes updating the revision table.

                   

                  Note, this is all in c# and can be translated to VBA relatively easily if you need to with translators available online.

                   

                  I've found that SW wants things done in a specific order.

                  1.) Add a new row to the table with 2016 SOLIDWORKS API Help - AddRevision Method (IRevisionTableAnnotation)

                  2.) Create a reference to the TableAnnotation reference of the revision table

                  table = (TableAnnotation)revTable;
                  

                  3.) To edit the cells in the table, use the following method.

                  table.Text[row, col] = "Your cell text here";
                  

                  4.) If you have revision bubbles, these get tricky as it's easiest to add them back as you're creating rows with the following method. This will associate it with the last row currently in the revision table.

                  // re-add revision symbol to the location it was at previously and attach it to the correct view.
                  swNote = drawing.InsertRevisionSymbol(symbolPosition[0], symbolPosition[1]);
                  
                    • Re: Unable to replace revision block and edit text in cells during same macro routine.
                      Colt Carson

                      Alex, Thanks for the tip! Although it is not the exact answer, it did direct me towards finding the problem.

                       

                      The problem was how I was getting the reference for the revision table after it was replaced. In my original script I used similar code to search for the revision table reference both before and after replacing the table. This technique of looping over all tables until a revision table is found does not seem to work after the table is replaced. Instead you must use the value returned by InsertRevisionTable to edit the table text.

                       

                      Set rev_table_handle = swsht.InsertRevisionTable(True, 0, 0, swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight, "path")
                      rev_table_handle.Text(1, 1) = "test"
                      

                       

                      Thanks again!