Author Topic: How to get the 4 corner_points' coordinates of a table cell ?  (Read 3300 times)

0 Members and 1 Guest are viewing this topic.

e2002

  • Mosquito
  • Posts: 7
How to get the 4 corner_points' coordinates of a table cell ?
« on: January 01, 2015, 03:09:23 AM »
How to get the 4 corner_points'  coordinates of a table cell ?

Tharwat

  • Swamp Rat
  • Posts: 553
  • Hypersensitive
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #1 on: January 01, 2015, 06:06:54 AM »
Just curious , What would you do with the four corners of a  cell ?

e2002

  • Mosquito
  • Posts: 7
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #2 on: January 01, 2015, 06:36:20 AM »
i want use AutoLISP move text objects to the rectangle region of cells , then convert the text contents as the contens of cell.

Tharwat

  • Swamp Rat
  • Posts: 553
  • Hypersensitive
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #3 on: January 01, 2015, 07:24:56 AM »
Try this function and let me know .

Code - Auto/Visual Lisp: [Select]
  1. (defun _cell:coordinates (tbl column row / w h i a b c d)
  2.   ;;;   Tharwat 01.01.2015      ;;;
  3.   ;;; Get the four coordinates  ;;;
  4.   ;;; of a specific cell        ;;;
  5.   (setq w 0.
  6.         h 0.
  7.         i -1
  8.   )
  9.   (if (and (eq (vla-get-objectname tbl) "AcDbTable")
  10.            (<= row (vla-get-rows tbl))
  11.            (<= column (vla-get-columns tbl))
  12.       )
  13.     (progn
  14.       (repeat (1- column)
  15.         (setq w (+ w (vla-getcolumnwidth tbl (setq i (1+ i)))))
  16.       )
  17.       (setq p (vlax-get tbl 'insertionpoint)
  18.             i -1
  19.       )
  20.       (repeat (1- row)
  21.         (setq h (+ h (vla-getrowheight tbl (setq i (1+ i)))))
  22.       )
  23.       (setq a (list (+ (car p) w) (- (cadr p) h) (caddr p))
  24.             b (list (+ (car a) (vla-getcolumnwidth tbl (1- column)))
  25.                     (cadr a)
  26.                     (caddr a)
  27.               )
  28.             c (list (car b)
  29.                     (- (cadr b) (vla-getrowheight tbl (1- row)))
  30.                     (caddr b)
  31.               )
  32.             d (list (car a)
  33.                     (- (cadr a) (vla-getrowheight tbl (1- row)))
  34.                     (caddr a)
  35.               )
  36.       )
  37.     )
  38.   )
  39.   (list a b c d)
  40. )
  41.  


The way to call the function .

Code - Auto/Visual Lisp: [Select]
  1. (_cell:coordinates  (vlax-ename->vla-object (car (entsel "\n Select Table :"))) 4 8)

Lee Mac

  • Seagull
  • Posts: 12395
  • London, England
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #4 on: January 01, 2015, 09:29:07 AM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun cellextents ( obj row col / lst rtn )
  2.     (setq lst (vlax-invoke obj 'getcellextents row col :vlax-true))
  3.     (repeat 4 (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst)))
  4.     rtn
  5. )

e2002

  • Mosquito
  • Posts: 7
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #5 on: January 02, 2015, 09:41:49 AM »
Cool code! Thanks for LM and Tharwat.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7045
  • AKA Daniel
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #6 on: January 02, 2015, 09:44:44 AM »
you may need to test if the cell is merged, not sure with com

Lee Mac

  • Seagull
  • Posts: 12395
  • London, England
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #7 on: January 02, 2015, 10:27:03 AM »
Cool code! Thanks for LM and Tharwat.

You're welcome!  :-)

you may need to test if the cell is merged, not sure with com

A good point - after some brief testing, it would appear that the ActiveX getcellextents method accounts for this if the queried cell is the leftmost/topmost cell of those merged. With this in mind, something like this should suffice:

Code - Auto/Visual Lisp: [Select]
  1. (defun cellextents ( obj row col / a b c d lst rtn )
  2.     (if (= :vlax-true (vla-ismergedcell obj row col 'a 'b 'c 'd))
  3.         (setq row a col c)
  4.     )
  5.     (setq lst (vlax-invoke obj 'getcellextents row col :vlax-true))
  6.     (repeat 4 (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst)))
  7.     (reverse rtn)
  8. )
« Last Edit: January 02, 2015, 10:35:00 AM by Lee Mac »

Tharwat

  • Swamp Rat
  • Posts: 553
  • Hypersensitive
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #8 on: January 02, 2015, 12:30:23 PM »
Cool code! Thanks for LM and Tharwat.

You are welcome and Happy that my approach worked for you .  :-)

Nice approach Lee and specially the second one for the emerged cells  :wink:

Lee Mac

  • Seagull
  • Posts: 12395
  • London, England
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #9 on: January 03, 2015, 08:27:10 AM »
Thank you Tharwat  :-)

kozmos

  • Newt
  • Posts: 37
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #10 on: January 04, 2015, 11:38:37 PM »
Cool code! Thanks for LM and Tharwat.

You're welcome!  :-)
Seemed that GetCellExtents only get the boundary of cell content area, so need to add the horizontal and vertical margins into the the calculation to get the exact cell corner.

you may need to test if the cell is merged, not sure with com

A good point - after some brief testing, it would appear that the ActiveX getcellextents method accounts for this if the queried cell is the leftmost/topmost cell of those merged. With this in mind, something like this should suffice:

Code - Auto/Visual Lisp: [Select]
  1. (defun cellextents ( obj row col / a b c d lst rtn )
  2.     (if (= :vlax-true (vla-ismergedcell obj row col 'a 'b 'c 'd))
  3.         (setq row a col c)
  4.     )
  5.     (setq lst (vlax-invoke obj 'getcellextents row col :vlax-true))
  6.     (repeat 4 (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst)))
  7.     (reverse rtn)
  8. )
KozMos Inc.

Lee Mac

  • Seagull
  • Posts: 12395
  • London, England
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #11 on: January 05, 2015, 12:44:31 PM »
Cool code! Thanks for LM and Tharwat.

You're welcome!  :-)

Seemed that GetCellExtents only get the boundary of cell content area, so need to add the horizontal and vertical margins into the the calculation to get the exact cell corner.

The function seems to perform as expected for me - the attached image shows the points returned for a cell with horizontal & vertical margins set to 2 & 3 units respectively:

kozmos

  • Newt
  • Posts: 37
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #12 on: January 08, 2015, 01:58:21 AM »
Found the reason, I called (setq lst (vlax-invoke tbl 'getcellextents row col 0)) and it returns the cell content box.
 
KozMos Inc.

alanjt

  • Needs a day job
  • Posts: 5337
  • Standby for witty remark...
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #13 on: January 08, 2015, 11:10:10 AM »
Doubt I'll ever had a use for this, but it's still pretty damn cool. Well done, Lee.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12395
  • London, England
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #14 on: January 08, 2015, 06:11:40 PM »
Doubt I'll ever had a use for this, but it's still pretty damn cool. Well done, Lee.

Cheers Alan  :-)

roy_043

  • Water Moccasin
  • Posts: 1825
  • BricsCAD 18
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #15 on: October 16, 2015, 07:36:22 PM »
Can someone explain the meaning of the 4th argument of (vla-getcellextents)? I don't understand.

bOuterCell (Boolean )
  TRUE: The specified cell is an outer cell.
  FALSE: The specified cell is an inner cell.

Master_Shake

  • Swamp Rat
  • Posts: 1447
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #16 on: October 19, 2015, 10:19:16 AM »
Just a stab in the dark, as an easy conditional to determine if the cell is a border cell or interior cell. Potentially for borders?

roy_043

  • Water Moccasin
  • Posts: 1825
  • BricsCAD 18
Re: How to get the 4 corner_points' coordinates of a table cell ?
« Reply #17 on: October 19, 2015, 01:35:05 PM »
Of course this was my first thought as well. But it doesn't make sense. The Boolean is an argument not a return value. And I already know from the column and row indices if a cell is a border cell or not.