×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How do I add a sum/total cell to a table through API?

How do I add a sum/total cell to a table through API?

How do I add a sum/total cell to a table through API?

(OP)
I've got code that creates a drawing, inserts views, and inserts a table (not excel based) and adds a row to the bottom... now i need it to add a sum/total cell to a column, but i can't find how, or if it's even possible...

anyone done this successfully before?

RE: How do I add a sum/total cell to a table through API?

Are you creating a new column?

RE: How do I add a sum/total cell to a table through API?

I don't know about in Code - But I assume you know how to do this in SW otherwise? If not see SW05 What's new manual, it tells you there.

Regards,

Scott Baugh, CSWP
3DVision Technologies

www.3dvisiontech.com
www.scottjbaugh.com
FAQ731-376
FAQ559-716 - SW Fora Users

RE: How do I add a sum/total cell to a table through API?

Use a loop which calls TableAnnotation.Text (Row, Column) at each cell to retrieve its value.  Convert to the required number format and add to the total.

RE: How do I add a sum/total cell to a table through API?

(OP)
I suppose thats the only way to do it. seems rediculous though, that you can't just change the property of the cell to 'sum/total' like you can when viewing a drawing. it would be so easy to program....

RE: How do I add a sum/total cell to a table through API?

Did you check out the What's new in 05? It explains the entire process there, then you can figure out if you can do it in code.

Chapter 10 - Page 10-16

Regards,

Scott Baugh, CSWP
3DVision Technologies

www.3dvisiontech.com
www.scottjbaugh.com
FAQ731-376
FAQ559-716 - SW Fora Users

RE: How do I add a sum/total cell to a table through API?

(OP)
i hadn't read that, but i already knew how to do it through those checkboxes... but i can't find any reference to sum cells or total cells in the object browser, or searching in the API help.

could it be part of another reference that i don't have installed? how would i know what i need activated?

as far as i can tell, it's not possible to make a cell a sum/total cell through API...

RE: How do I add a sum/total cell to a table through API?

(OP)
Also, i've tried recording a macro making the change. all i get (as I usually do) is a program that selects my BOM.

why is the macro recorder such a piece of crap?

RE: How do I add a sum/total cell to a table through API?

(OP)
there were quite a few things i tried recording macros for and ended up with a bunch of code that was all 'SelectByID2' lines. i can't remember at the moment if it was all BOM stuff, but it may have been.

i'm quite convinced this isn't built into the API. should be, though.

RE: How do I add a sum/total cell to a table through API?

The macro recorder can only track actions, not logic.  You need to add the logic yourself.  The functionality to sum columns/rows is already built into the api.  For example, to sum column 3 of a rev table:


Option Explicit

Dim swApp       As SldWorks.SldWorks
Dim DwgDoc      As SldWorks.ModelDoc2
Dim swSheet     As SldWorks.Sheet
Dim swRevTable  As SldWorks.TableAnnotation

Dim Msg         As String
Dim nRow        As Long
Dim nCol        As Long
Dim nSum        As Long

Sub Main()

    Set swApp = Application.SldWorks
    Set DwgDoc = swApp.ActiveDoc
    Set swSheet = DwgDoc.GetCurrentSheet
    Set swRevTable = swSheet.RevisionTable
   
    nSum = 0
    nCol = 3
    
    For nRow = 1 To swRevTable.RowCount - 2
        nSum = nSum + CLng(swRevTable.Text(nRow, nCol))
    Next nRow
    
    swRevTable.Text(swRevTable.RowCount - 1, nCol) = CStr(nSum)
    
End Sub  

RE: How do I add a sum/total cell to a table through API?

(OP)
that's what i've done, but it worries me. if the table gets updated (which is possible) that total isn't dynamic, where a sum/total cell is.

RE: How do I add a sum/total cell to a table through API?

The lack of dynamic update is the biggest problem with the custom table.  The only way I have solved it in the past is by converting my code to an add-in that runs whenever someone loads / changes the active window to a drawing.

Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...

RE: How do I add a sum/total cell to a table through API?

(OP)
Here's a zip file from solidworks. i don't know why i didn't find this earlier, and now we've restructured the drawings and no longer need the calculated cells, but if anyone else needs some help here, this file includes a nice powerpoint slideshow and some useful programs to cause calculated cells to refresh on every rebuild. i haven't read the code, so i can't vouch for it, but they do claim to have code to help with this.

http://www.solidworks.com/downloads/API/Downloads/00000/0300s/0311/Automating%20and%20Customizing%20New%20Bill%20Of%20Materials.zip

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources