Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Milothicus

Mechanical
Sep 21, 2003
39
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?
 
Replies continue below

Recommended for you

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.
 
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....
 
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...
 
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?
 
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.
 
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
 
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.
 
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...
 
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.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor