More Table Woes

More Table Woes

john.uhden
Mentor Mentor
1,713 Views
28 Replies
Message 1 of 29

More Table Woes

john.uhden
Mentor
Mentor

I created a base table with a few data rows and wblocked it out to its own dwg file.

When required by my "OpenChannelFlow.lsp" routine, it inserts it expoded to get just the table.

When I add another row to take another depth and resulting hydraulic data, and then set the cell values, the new row is created but the cells do not get populated.  I even added vla-updates after each row addition and each row population.

Must the table have sufficient rows before filling it with data?  Or is there some other prerequisite?

I mean that I could create the base table with plenty of rows and then remove the rows not used, if that would solve my problem.

John F. Uhden

0 Likes
Accepted solutions (2)
1,714 Views
28 Replies
Replies (28)
Message 2 of 29

paullimapa
Mentor
Mentor

When you populated the Table the first time did you use AutoCAD's DATAEXTRACTION command to create it?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 29

john.uhden
Mentor
Mentor

@paullimapa ,

No.  I don't even know what AutoCAD's DATAEXTRACTION is.

Each row has a depth that is incremented by 0.10.  That depth is used to calculate 8 hydraulic values for each row (via AutoLisp, not via cell formulae), and I populate each cell one by one.

I found that using vla-update really slows down the process, so I have removed them.

 

John F. Uhden

0 Likes
Message 4 of 29

john.uhden
Mentor
Mentor

@paullimapa ,

I think that adding lotsa rows to my base table and vla-deleting the empties upon population is my solution.  Whaddya think?

John F. Uhden

0 Likes
Message 5 of 29

paullimapa
Mentor
Mentor

Sure might as well give it a try


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 29

CodeDing
Advisor
Advisor

@john.uhden ,

 

I cannot duplicate your issue..

 

Started here:

image.png

 

Ran this First (I predefined "tbl" as just a global variable of the table):

(progn
  (vlax-invoke tbl 'InsertRows 4 0.36 1)
  (vlax-invoke tbl 'SetCellValue 4 0 "Hello")
  (vlax-invoke tbl 'SetCellValue 4 1 "World")
)

First Outcome:

image.png

 

Ran this Second:

(progn
  (vlax-invoke tbl 'InsertRows 5 0.36 2)
  (vlax-invoke tbl 'SetCellValue 5 0 "Hello again")
  (vlax-invoke tbl 'SetCellValue 5 1 "World again")
  (vlax-invoke tbl 'SetCellValue 6 0 "Hello ...again")
  (vlax-invoke tbl 'SetCellValue 6 1 "World ...again")
)

Second Outcome:

image.png

 

Best,

~DD

0 Likes
Message 7 of 29

Sea-Haven
Mentor
Mentor

Yes John use INSERTROWS. You have my email.

Some example code.

 

 

(Setq curspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table:  ")))
(setq numrows 3)
(setq numcolumns 4)
(setq rowheight 25)
(setq colwidth 80)
(setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "Heading 1")
(vla-settext objtable 1 0 "Count")
(vla-settext objtable 1 1 "Layer or\nObject")
(vla-settext objtable 1 3 "Length")
(vla-Setcolumnwidth Objtable  0 45 0)
(vla-Setcolumnwidth Objtable  1 75 0)
(vla-Setcolumnwidth Objtable  2 100 0)
(vla-Setcolumnwidth Objtable  3 55 0)
(setq objtable (vlax-ename->vla-object (entlast)))

(setq numrows 3)
(foreach val lst2
  (vla-InsertRows Objtable  numrows (vla-GetRowHeight Objtable (1- numrows)) 1)
  (vla-settext objtable numrows 1 "Polyline")
  (vla-settext objtable numrows 2 (car val))
  (vla-settext objtable numrows 3 (rtos (cadr val) 2 3))
  (setq numrows (1+ numrows))
)

 

 

You can create your own table style using lisp or modify the "Standard" to match what you want it to look like once you have made it, you can basically change everything about the table, like text alignment, color and size.

 

0 Likes
Message 8 of 29

komondormrex
Mentor
Mentor

table-woe, table-foe

follows me

whenever i draw

Message 9 of 29

john.uhden
Mentor
Mentor

@komondormrex ,

Amen.

John F. Uhden

0 Likes
Message 10 of 29

john.uhden
Mentor
Mentor

@Sea-Haven , et al,

Well the biggest part of my problem was stupidity.

What can you see is wrong with this?...

(setq i 0)
(while (<= i 8)
  (vla-setcellvalue table row i (nth i data))
)

Yes, I know you found it.  So did I.

BUT, why won't this work?...

(vlax-put table 'horzcellmargin 0.15)

No errors; it just does nothing.

This is really urinating me off!

John F. Uhden

0 Likes
Message 11 of 29

paullimapa
Mentor
Mentor

assuming table is the vl object, have you tried:

(vla-put-HorzCellMargin table 0.05)

you can read more about it on this thread:

https://www.theswamp.org/index.php?topic=56237.0


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 29

Sea-Haven
Mentor
Mentor

A couple more

 

;; Sets the horizontal margin for the table cells
(vla-put-HorzCellMargin custObj txtht )

;; Sets the vertical margin for the table cells
(vla-put-VertCellMargin custObj txtht )

;; Set the alignment for the Data, Header, and Title rows
(vla-SetAlignment custObj (+ acDataRow acHeaderRow acTitleRow) acMiddleCenter)
0 Likes
Message 13 of 29

john.uhden
Mentor
Mentor

Thanks for responding, @paullimapa .

Yes, table is a vla-object, but

No, nothing happened.

Well, not NOTHIING.  A dump showed that horzcellmargin was set to 0.15, but the table was still displayed as though horzcellmargin were 0.0.

Nor did a (vla-update table) change its appearance.

John F. Uhden

0 Likes
Message 14 of 29

john.uhden
Mentor
Mentor

@paullimapa & @Sea-Haven & @komondormrex & @CodeDing ,

Since I could not make horzcellmargin acmiddleright behave at all, I surrendered to acmiddlecenter which appears to work consistently.

Thank you all for all your helpful efforts.

johnuhden_0-1702505243832.png

 

John F. Uhden

0 Likes
Message 15 of 29

Sea-Haven
Mentor
Mentor

Food for thought you can put a block in a table so your diagram could be a block and be within the table. Would need a big row height for say 1st row.

 

Thinking some more cheat make 1st row height big and just move diagram.

0 Likes
Message 16 of 29

john.uhden
Mentor
Mentor

Hi, @Sea-Haven ,

I had thought of including the ChanSect block in the table, but I haven't tested to see if the block (with attributes) could be modified in terms of editing attributes, so I put it on its own.

The technique is the first I've seen wherein the attribute values in the block can be changed via EATTEDIT and read and used to perform the calculations that are put into the table, complete with alerts for when a value is not valid (not a number, less than zero, TCW is less than BCW).  It's working pretty well now except the cell formatting takes too long for my pleasure.  And it all plots out nicely on letter-sized paper for inclusion into a report.

John F. Uhden

0 Likes
Message 17 of 29

Sea-Haven
Mentor
Mentor

You can say make the title row 250 high compared to text at 2.5, then block may fit, its manually there so its a block not part of the table, using merge cells can make the header row what was the title row , follow with 1st data row as the descriptions for the columns. In my tables I have a row number as the starting row for data so in your code if similar would just need row start number to be 4 and not 3.

 

 

 

;; Set the text height for the Title, Header and Data rows
(vla-SetTextHeight custObj acDataRow txtht)
(vla-SetTextHeight custObj acHeaderRow (* txtht 1.2))
(vla-SetTextHeight custObj acTitleRow (* txtht 1.5))

 

 

 (vla-mergecells custobj row1 col1 row2 col2)
0 Likes
Message 18 of 29

komondormrex
Mentor
Mentor

@john.uhden wrote:

Since I could not make horzcellmargin acmiddleright behave at all


should work all the way, but you have to check length of mtext string, cell width and margins i suppose

 

komondormrex_0-1702542165878.png

 

0 Likes
Message 19 of 29

john.uhden
Mentor
Mentor

@komondormrex ,

Hmm.  My work is at work, but I think I format the numbers ('REALs) via %lu2%pr2 before I try to impose the horizontal alignment.  If I am doing the alignment first, do you think that would cause the symptom?

John F. Uhden

0 Likes
Message 20 of 29

komondormrex
Mentor
Mentor

i honestly think it is better not to format cell's data data with "%lu2%pr2" but format cell itself instead like eg.

(vla-setcelldatatype table_object row_index column_index acdouble acunitdistance)

set cell's alignment

(vla-setcellalignment table_object row_index column_index acmiddleright)

and then put data into it

(vla-settext table_object row_index column_index your_real)

 actually i think the order doesn't really matter

0 Likes