Nemie hi,
here is more 'invested' solution to your 'problem'.
it works with excel CSV. you can save your xlsx file to CSV (Comma delimited) file. if excel complains it can't save a multi sheets file and\or has some incompatible properties you can accept the error message and pick OK. this will create a csv file that contain your interest data at the top of the file (and that's what is needed 😀)
the command AZC is also based on KEYS-CELL data list:
(setq KEYS-CELL (list
"X" ; index=0
"Y" ; index=1
"X1-segmented" ; index=2
"Y2-segmented" ; index=3
"number of columns" ; index=4
"number of rows" ; index=5
"Zx -segmented" ; index=6
"Zy -segmented" ; index=7
); list
)
it's a list of the data keys exactly as they found in your file. if you change the keys name in the file, you need to come here and fix the keys in KEYS-CELL also.
the order of keys are important, the first is index 0 and the last is 7 (total of 8). you can add here more keys to be read from the excel file but these keys (at this moment) will not be use by this program.
Note: keys 6 + 7 has a space in them, to me it looks like a mistake but at this moment i left it as it is.
the program calculate on it's own the Spacing X, Spacing Y keys and that's why i didn't put them in KEYS-CELL data list. if there is a mistake in calculation, you will see it in the drawing.
the program starts by asking you to select the csv file + Specify lower left corner: of the rectangle.
if there is a mismatch keys (between the csv file and KEYS-CELL) you will be notify.
enjoy
moshe
; Aperture siZe Calculator
(defun c:AZC (/ to-upcase read-csv-file check-data calc-space ; local function
fpath p0 p1 KEYS-CELL f pos rowString cellValue csv-data^ wht hgt)
; convert list of strings to uppercase
(defun to-upcase (lst)
(mapcar
'(lambda (str)
(strcase str)
)
lst
); mapcar
); to-upcase
(defun read-csv-file (/ read-cell ; local function
f rowString pos key cellValue lst)
(defun read-cell (/ ch cell)
(setq ch (substr rowString (setq pos (1+ pos)) 1) cell "")
(while (and (/= ch ",") (/= ch ""))
(setq cell (strcat cell ch))
(setq ch (substr rowString (setq pos (1+ pos)) 1))
); while
cell
); read-cell
(if (setq f (open fpath "r"))
(progn
(setq rowString (read-line f))
(while rowString
(setq pos 0)
(if (and
(member (strcase (setq key (read-cell))) KEYS-CELL)
(setq cellValue (read-cell))
)
(setq lst (cons (cons (strcase key) (atof cellValue)) lst))
); if
(setq rowString (read-line f))
); while
); progn
); if
lst
); read-csv-file
(defun check-data (/ prtm ;| local function |; l)
(defun prtm (lst)
(foreach a lst (princ a))
); prtm
(if (not
(setq l
(vl-remove-if
'not
(mapcar
'(lambda (key)
(if (null (assoc key csv-data^))
key
)
)
KEYS-CELL
); mapcar
)
)
)
T ; all keys exist, return T
(if (/= (length l) 0)
(progn
(vlr-beep-reaction)
(prtm (list "\nthe following key(s) " l " not found in \n" fpath " file."))
nil
); progn
); if
); if
); check-data
(defun calc-space (p)
(/ (- (cdr (assoc (nth (+ p 0) KEYS-CELL) csv-data^))
(* (cdr (assoc (nth (+ p 6) KEYS-CELL) csv-data^)) 2)
(* (cdr (assoc (nth (+ p 2) KEYS-CELL) csv-data^))
(cdr (assoc (nth (+ p 4) KEYS-CELL) csv-data^))
)
); subtract
(1- (cdr (assoc (nth (+ p 4) KEYS-CELL) csv-data^)))
); divide
); calc-space
; here start (c:azc)
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(if (and
(setq fpath (getfiled "Select excel file" "" "csv" 8))
(setq p0 (getpoint "\nSpecify lower left corner: "))
)
(progn
; key cellValues on interest
(setq KEYS-CELL (list
"X" ; index=0
"Y" ; index=1
"X1-segmented" ; index=2
"Y2-segmented" ; index=3
"number of columns" ; index=4
"number of rows" ; index=5
"Zx -segmented" ; index=6
"Zy -segmented" ; index=7
); list
); KEYS-CELL
; convert to uppercase
(setq KEYS-CELL (to-upcase KEYS-CELL))
(if (and
(setq csv-data^ (read-csv-file))
(check-data)
)
(progn
(command "._rectangle" "_None" p0 "_None" (mapcar '+ p0 (list (cdr (assoc (nth 0 KEYS-CELL) csv-data^)) (cdr (assoc (nth 1 KEYS-CELL) csv-data^)) 0.0)))
(setq p1 (mapcar '+ p0 (list (cdr (assoc (nth 6 KEYS-CELL) csv-data^)) (cdr (assoc (nth 7 KEYS-CELL) csv-data^)) 0.0)))
(command "._rectangle" "_None" p1 "_None" (mapcar '+ p1 (list (setq wht (cdr (assoc (nth 2 KEYS-CELL) csv-data^)))
(setq hgt (cdr (assoc (nth 3 KEYS-CELL) csv-data^))) 0.0)))
(command "._array" "_si" "_last" "_Rectangular" (fix (cdr (assoc (nth 4 KEYS-CELL) csv-data^)))
(fix (cdr (assoc (nth 5 KEYS-CELL) csv-data^)))
(+ hgt (calc-space 0))
(+ wht (calc-space 1)))
); progn
); if
); progn
); if
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
); c:azc