16 Replies Latest reply on Sep 13, 2017 12:37 PM by Amen Allah Jlili

    How to swap-out general table in drawing

    Bjorn Hulman

      Hi Folks,

      After many years on here being a general nuisance and offering the few strands of experience I have gathered when the appropriate occasions arise, I am now looking for some help.

       

      The last few weeks I have been working on a macro that updates a drawing sheet relative to the information entered through the custom properties tab at part/assembly level. All going well and I have made a lot of progress through filtering through previous posts.

       

      Now I have come across an issue I cannot find a solution to. I wish to delete a general table from all sheets, and insert a new one when certain options are selected. So I'd be extraordinarily grateful if someone might be able to shed some light on this for me.

       

      Many thanks,

      Bjorn

        • Re: How to swap-out general table in drawing
          Deepak Gupta

          Do you've more than one general table on each or any of the sheet?

            • Re: How to swap-out general table in drawing
              Bjorn Hulman

              Thanks John,

              I've seen these and the methods illustrated of inserting of the table is helpful. It's locating/selecting and deleting the table I'm finding more problematic. And possibly also inserting it on the anchor point, which is the next bridge.

                • Re: How to swap-out general table in drawing
                  Alex Burnett

                  You could iterate through the annotations in the following manner (note this is c# so the VBA syntax will be different). You don't need to iterate through all of the drawing views but I have it set up that way because I'm looking for a lot of different annotation types.

                   

                                  // Get all sheet views. This is an array of View[] objects for each sheet.
                                  object[] allSheetViewArrays = (object[])drawing.GetViews();
                                  
                                  // Loop through all views
                                  for (int i = 0; i < allSheetViewArrays.Count(); i++)
                                  {
                                      // Get all view objects for current sheet
                                      object[] allViews = (object[])allSheetViewArrays[i];
                  
                  
                                      // Loop through all drawing views
                                      for (int j = 0; j < allViews.Count(); j++)
                                      {
                                          // Set current view object as v
                                          v = (View)allViews[j];
                                          if (v != null)
                                          {
                                              // Get annotation for current view
                                              swAnno = v.GetFirstAnnotation3();
                                              
                                              // Loop through all annotations in this view
                                              while (swAnno != null)
                                              {
                                                  if (annoType == (long)swAnnotationType_e.swTableAnnotation)
                                                  {
                  
                  
                                                    // Do what you want with your table here
                                                    // Get the annotation object from the table object
                                                    swAnno = (IAnnotation)table.GetAnnotation();
                  
                                                    // Select the annotation which selects the revision table
                                                    swAnno.Select(false);
                  
                                                    // Call the delete command on the currently selected object(s)
                                                    swDraw.EditDelete();
                                                  }
                                                 // Set annotation to next before the while loop restarts
                                                 swAnno = swAnno.GetNext3();
                                             }
                                        }
                                   }
                              }
                  
                    • Re: How to swap-out general table in drawing
                      Bjorn Hulman

                      Thanks Alex,

                      That looks like it may be helpful. The syntax alterations will definitely blow some cobwebs off some long resting neurons in my brain.

                        • Re: How to swap-out general table in drawing
                          Alex Burnett

                          I certainly understand that. I was hoping it would help a bit with the logic an commands required to find the table and then select it to delete it. From there, the InsertTableAnnotation2 function has a field to set the anchor point but it is ignored for general tables as far as I can tell from the resource page. I believe the X and Y coordinates are all that can be used to locate that. It's always a challenge to find a solution to a specific problem unique to yourself which I have encountered many times as well. This forum has been very helpful to me in getting things working. Good luck!

                            • Re: How to swap-out general table in drawing
                              Bjorn Hulman

                              Thanks Alex,

                              I noticed the anchorpoint option didn't work when I spec'd TopRight by accident and it didn't work. I have save the tables with 'attach to anchor point' selected. and they seem to be landing on the mark so far.

                              This forum has always been a fantastic place to learn from others. Since being a member, this is the first time I've not been able to find what I was after without asking.

                    • Re: How to swap-out general table in drawing
                      Amen Allah Jlili

                      I don't understand how is that problematic. Can you post the code where you try to locate, select and delete the tables?