Author Topic: MapTableRegion - Am I expecting too much?  (Read 1785 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
MapTableRegion - Am I expecting too much?
« on: August 15, 2009, 04:28:17 PM »
Am I expecting too much thinking I can build a procedure that I can use to access all of the properties and methods for a region  of "cells" in an Acad table?

Here is what I have so far.  Example 1 works, but I'm not sure how I would even call example 2.  Suggestions are appreciated.
Code: [Select]
;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  Routine: MapTableRegion
  Purpose: Map all cells in a table range to a user provided procedure
  Arguments: objTable, vla-object table object, or ename or entity list for a table object
  RowMin, integer, the top row of the region
  RowMax, integer, the bottom row of the region
  ColMin, integer, the first column of the region
  ColMax, integer, the last column of the region
  Func, the function to which we will map the cells
  FuncArgs, a list of the arguments required by Func
     Two special symbols may be used for the Row and Column arguments of the table object
     methods.  #ROW# will be interpreted as the cell's row and #COL# will be interpreted as
     the cell's column.
  Returns: A list of the results, similar to the way mapcar works.
...
  Example 1: To get the cell values from a region:
  (MapTableRegion objTable 3 5 1 3 'vla-gettext '('#ROW# '#COL#)) and will return a list, thus
  (((2 4) . "C4") ((1 4) . "B4") ((2 3) . "C3") ((1 3) . "B3"))
  Example 2: To put the sum of the row number and the column number into each cell in a region
  (MapTableRegion
  objTable
  3 5
  1 3
  (function
    (lambda(args)
     (vla-settext objTable #Row# #Col# [color=red]...  This is where I got lost:-([/color]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;
(defun MapTableRegion (objTable RowMin    RowMax    ColMin    ColMax
       Func FuncArgs  /      rtlist    RowIndex
       
       ColIndex #Row#    #Col#
      )
  (setq RowIndex (1- RowMin))
  (while (> RowMax (setq RowIndex (1+ RowIndex)))
    (setq ColIndex (1- ColMin))
    (while (> ColMax (setq ColIndex (1+ ColIndex)))
      (setq #Row# RowIndex
    #Col# ColIndex
      )
      (setq rtlist (cons (cons (list ColIndex RowIndex)
       (eval (append (list func objTable) funcargs))
)
rtlist
   )
      )
    )
  )
  rtlist
)