I have cobbled together some code that will give me various coordinates of columns/rows/cells in a table based on where the user picks. I have my code below, but I am sure I am missing something and there has to be a better way to accomplish this. Looking for any input at this point.
(defun c:CheckTable (/ Pt1 TableInfo CellUpperLeft CellLowerRight TableCell RowUpperLeft RowLowerRight ColumnUpperLeft ColumnLowerRight)
;Supporting Functions
(defun CW:GetTableCell (Pt1 / Result Tables ent Table PointOnTable)
;Supporting Functions
;Routine to output information with some blank lines
(defun Output (msg)
(princ "\n")(princ msg)(princ "\n")
)
(Defun LM:Hittest ( Pt Lst ) ; Lee Mac
(If (And (Vl-consp Pt) (Vl-every 'Numberp Pt))
(Vl-some
(Function
(Lambda ( O / R C )
(If (Eq :Vlax-true (Vla-hittest O (Vlax-3d-point (Trans Pt 1 0)) (Vlax-3d-point (Trans (Getvar 'Viewdir) 1 0)) 'R 'C)) (List O R C) )
)
)
Lst
); Vl-some
); If
); Defun Hittest
(Defun Getacadtableobjects ( / Ss I L ); Grrr1337
(If (Setq Ss (Ssget "X" (List '(0 . "Acad_table") (If (= 1 (Getvar 'Cvport)) (Cons 410 (Getvar 'Ctab)) '(410 . "Model")))))
(Repeat (Setq I (Sslength Ss)) (Setq L (Cons (Vlax-ename->vla-object (Ssname Ss (Setq I (1- I)))) L)) )
); If
); Defun Getacadtableobjects
;End Supporting Functions
(setq Tables (Getacadtableobjects))
(LM:Hittest Pt1 Tables)
)
(defun CW:GetCoordinates (TableInfo *RowUpperLeft *RowLowerRight *ColumnUpperLeft *ColumnLowerRight *CellUpperLeft *CellLowerRight / TotalColumnHeight Ct Obj Row Column Rows Columns InsPt ColumnCount RowCount ColumnDistance RowDistance)
;Supporting Functions
(defun d2r (NumberOfDegrees)
(* pi (/ numberOfDegrees 180.0))
)
;End Supporting Functions
(setq Obj (nth 0 TableInfo)
Row (nth 1 TableInfo)
Column (nth 2 TableInfo)
Rows (vla-get-rows Obj)
Columns (vla-get-columns Obj)
InsPt (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint Obj)))
ColumnCount 0
RowCount 0
ColumnDistance 0
RowDistance 0
Ct 0
)
(while (< ColumnCount Column)
(setq ColumnDistance (+ ColumnDistance (vla-getcolumnwidth Obj ColumnCount))
ColumnCount (+ ColumnCount 1)
)
(output (vla-getcolumnwidth Obj ColumnCount));column widths
)
(while (< Ct Rows)
(setq TotalColumnHeight (+ (vla-getrowheight Obj Ct))
Ct (+ ct 1)
)
)
(while (< RowCount Row)
(setq RowDistance (+ RowDistance (vla-getrowheight Obj RowCount))
RowCount (+ RowCount 1)
)
)
(set *ColumnUpperLeft (polar InsPt 0 ColumnDistance))
(set *ColumnLowerRight (polar (polar (eval *ColumnUpperLeft 0 (vla-getcolumnwidth Obj Column)) TotalColumnHeight)))
(set *RowUpperLeft (polar InsPt (d2r 270) RowDistance))
(set *RowLowerRight (polar (polar (eval *RowUpperLeft) 0 (vla-get-width Obj)) (d2r 270) (vla-getrowheight Obj Row)))
(set *CellUpperLeft (polar (polar InsPt 0 ColumnDistance) (d2r 270) RowDistance))
(set *CellLowerRight (polar (polar (eval *CellUpperLeft) 0 (vla-getcolumnwidth Obj Column)) (d2r 270) (vla-getrowheight Obj Row)))
)
;End of Supporting Functions
(setq Pt1 (getpoint "\nPick point on table: ")
TableInfo (CW:GetTableCell Pt1)
)
(cw:GetCoordinates TableInfo 'RowUpperLeft 'RowLowerRight 'ColumnUpperLeft 'ColumnLowerRight 'CellUpperLeft 'CellLowerRight)
;Output Information:
(output "ColumnUpperLeft: ")
(output ColumnUpperLeft)
(output "ColumnLowerRight: ")
(output ColumnLowerRight)
(output "CellUpperLeft: ")
(output CellUpperLeft)
(output "CellLowerRight: ")
(output CellLowerRight)
(output "RowUpperLeft: ")
(output RowUpperLeft)
(output "RowLowerRight")
(output RowLowerRight)
)