How to add data to table in autocad using vba

How to add data to table in autocad using vba

Anonymous
Not applicable
11,221 Views
3 Replies
Message 1 of 4

How to add data to table in autocad using vba

Anonymous
Not applicable
Dear Sir,

I am using table in autocad the for the adding the contents for BOM ....... and for the other data too..........

So i am planning to do perform a program to add the data using the prompt

Can you please give me some idea or code to add the data to row of the table using vba

thanks in advance

mallikarjun
0 Likes
11,222 Views
3 Replies
Replies (3)
Message 2 of 4

Hallex
Advisor
Advisor
This will get you started I hope
{code}
Option Explicit

Sub Ch_Add_Table()

Dim minp As Variant
Dim maxp As Variant
Dim pt(2) As Double
Dim acTable As AcadTable

Set acTable = ThisDrawing.ActiveLayout.Block.AddTable(pt, 10, 4, 10, 60)

With acTable
.RegenerateTableSuppressed = True
.RecomputeTableBlock False
.TitleSuppressed = False
.HeaderSuppressed = False
.SetTextStyle AcRowType.acTitleRow, "ROMANS" '<-- change text style name here
.SetTextStyle AcRowType.acHeaderRow, "ROMANS"
.SetTextStyle AcRowType.acDataRow, "ROMANS"
Dim i As Double, j As Double
Dim col As New AcadAcCmColor
col.SetRGB 255, 0, 255

'title
.SetCellTextHeight i, j, 6.4
.SetCellAlignment i, j, acMiddleCenter
col.SetRGB 194, 212, 235
.SetCellBackgroundColor i, j, col
col.SetRGB 127, 0, 0
.SetCellContentColor i, j, col
.SetCellType i, j, acTextCell
.SetText 0, 0, "Table Title"

i = i + 1

'headers
For j = 0 To .Columns - 1
col.SetRGB 203, 220, 183
.SetCellBackgroundColor i, j, col
col.SetRGB 0, 0, 255
.SetCellContentColor i, j, col
.SetCellTextHeight i, j, 5.2
.SetCellAlignment i, j, acMiddleCenter
.SetCellType i, j, acTextCell
.SetText i, j, "Header" & CStr(j + 1)
Next

'data rows
For i = 2 To .Rows - 1
For j = 0 To .Columns - 1

.SetCellTextHeight i, j, 4.5
.SetCellAlignment i, j, acMiddleCenter
If i Mod 2 = 0 Then
col.SetRGB 239, 235, 195
Else
col.SetRGB 227, 227, 227
End If
.SetCellBackgroundColor i, j, col
col.SetRGB 0, 76, 0
.SetCellContentColor i, j, col
.SetCellType i, j, acTextCell
.SetText i, j, "Row" & CStr(i - 1) & " Column" & CStr(j + 1)

Next j
Next i

' set color for grid
col.SetRGB 0, 127, 255
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acVertInside, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acVertRight, AcRowType.acTitleRow, col

.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acVertInside, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acVertRight, AcRowType.acHeaderRow, col

.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acVertInside, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acVertRight, AcRowType.acDataRow, col

'set line weights for grid
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acTitleRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acTitleRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acTitleRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzBottom, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzInside, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertInside, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzBottom, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzInside, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertInside, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acDataRow, AcLineWeight.acLnWt040

.RegenerateTableSuppressed = False
.RecomputeTableBlock True
.Update

.GetBoundingBox minp, maxp
ZoomWindow minp, maxp
ZoomScaled 0.9, acZoomScaledRelative
ThisDrawing.SetVariable "LWDISPLAY", 1
Set col = Nothing

End With

MsgBox "Huh?"

End Sub
{code}

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 4

rmcefr
Enthusiast
Enthusiast

Hello

if we use the following statement to set specific Column Width only

.SetColumnWidth(col as integer,  Width as Double)

.SetColumnWidth(2, 100)

 

All Columns in Table will change, not only col No.2 !!!

Any idea How to Set Specific Column Width Only without change other columns

 

thanks

 

 

0 Likes
Message 4 of 4

Ed__Jobe
Mentor
Mentor

First of all, this has nothing to do with this thread. You should have started a new thread.

 

.SetColumnWidth(2, 100) should work. Can you post your code and a sample dwg so we can see if there's something else going on?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes