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


Categories: API∕Macros

Comments
Last comment By: Amen Allah Jlili   Wed, 13 Sep 2017 16:37:05 GMT
Re: How to swap-out general table in drawing

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

By: Deepak Gupta  Tue, 12 Sep 2017 15:04:12 GMT
Re: How to swap-out general table in drawing
By: John Stoltzfus  Tue, 12 Sep 2017 15:34:23 GMT
Re: How to swap-out general table in drawing

Hi Deepak,

No there is only one general table per sheet at any one time.

By: Bjorn Hulman  Tue, 12 Sep 2017 15:52:31 GMT
Re: How to swap-out general table in drawing

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.

By: Bjorn Hulman  Tue, 12 Sep 2017 15:59:15 GMT
Re: How to swap-out general table in drawing

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

By: Amen Allah Jlili  Tue, 12 Sep 2017 16:13:47 GMT
Re: How to swap-out general table in drawing

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();
                           }
                      }
                 }
            }
By: Alex Burnett  Tue, 12 Sep 2017 17:40:28 GMT
Re: How to swap-out general table in drawing

Try the codes from this post to delete general table: Why can only delete a General Table and I hope you know how to add the new one.

 

Set UseAnchorPoint to True to insert the table at anchor point. And set value of AnchorType as desired.

 

instance.InsertTableAnnotation2(UseAnchorPoint, X, Y, AnchorType, TableTemplate, Rows, Columns)

By: Deepak Gupta  Wed, 13 Sep 2017 06:23:19 GMT
Re: How to swap-out general table in drawing

Thanks Deepak,

That should give me sufficient info to help sort out my table problem. I'll try and get this all going later this week.

By: Bjorn Hulman  Wed, 13 Sep 2017 08:07:51 GMT
Re: How to swap-out general table in drawing

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.

By: Bjorn Hulman  Wed, 13 Sep 2017 08:14:53 GMT
Re: How to swap-out general table in drawing

Hi Amen Allah Jlili,

I don't currently have any code for deleting the table. I haven't written any code for almost 20 years so I've been heavily reliant on examples on here and the API section of solidworks help. Though I'd managed to find examples of all the other code i required, changing sheet formats, updating the rev table, changing the title block entries dependant on different client requirements etc. I hadn't found anything to select the table so I could delete it.

 

EDIT,

actually, I have also been relying on Mike Spens, by way of his book 'Automating SOLIDWORKS 2017 Using Macros'. Worth the money, but it doesn't cover everything. I imagine it would be a great deal heavier if it did.

By: Bjorn Hulman  Wed, 13 Sep 2017 08:13:35 GMT
Re: How to swap-out general table in drawing

Thanks Deepak,

I have that working so it swaps out tolerance tables depending on part process (Injection mould, sheetmetal, cnc etc)

Only glitch is that it gives inserts the table with a 0.5mm border where if I insert it manually it comes in with 0.18mm border as desired. Likely a setting in my drawing template somewhere, I'll have a look around. If you have any suggestions though, I'd be very glad to hear them.

By: Bjorn Hulman  Wed, 13 Sep 2017 10:18:04 GMT
Re: How to swap-out general table in drawing

Use these lines to set the border and grid lines weight. Add after the table insertion line.

If Not swTableAnnotation Is Nothing Then

       swTableAnnotation.BorderLineWeight = 0

       swTableAnnotation.GridLineWeight = 0

End If

By: Deepak Gupta  Wed, 13 Sep 2017 10:50:28 GMT
Re: How to swap-out general table in drawing

There should be an option to like a comment more than once. I've been looking everywhere with no joy. That works a charm!

 

Thank you very kindly!

By: Bjorn Hulman  Wed, 13 Sep 2017 10:55:26 GMT
Re: How to swap-out general table in drawing

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!

By: Alex Burnett  Wed, 13 Sep 2017 12:35:28 GMT
Re: How to swap-out general table in drawing

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.

By: Bjorn Hulman  Wed, 13 Sep 2017 12:56:15 GMT
Re: How to swap-out general table in drawing

In order to delete a table, select it using SelectByID2 (either by name or location) and then call 2012 SOLIDWORKS API Help - EditDelete Method (IModelDoc2) . If you're using split tables, than you can only select it location.

By: Amen Allah Jlili  Wed, 13 Sep 2017 16:37:05 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.