Hey everyone....again.
I'm attaching a sample file and my lisp routine because it's giving me an error and i'm not sure why.
Nope, I don't, but I have a theswamp.org membership, and their forums accepted my attachments.
Here's the link if you'd care to take a look:
The gist of my issue is this...and I so don't understand what the heck is causing it?!??
!vallist
(("25" "TE") ("23" "TI") ("26" "TE") ("25" "TE"))
(defun doname (vallist / c cell namedata)
(_> (setq c 0)
(_> (setq len (length vallist))
(_> (setq cell (strcat "E" @excel_row))
(_> (setq cell (string_ cell))
(_> (repeat len
((_> (setq namedata (getname))
((_> (putcell cell namedata)
((_> (setq cell (string_ cell))
((_> (setq c (1+ c))
((_> );repeat
(_> (if (= c len)(doitem vallist))
(_> ;;goto item subfunction
(_> );defun doname
DONAME
Command: (doname vallist)
; error: bad argument type: consp
Why would my function give me an error when I pass it the list argument?!??
It isn't necessarily an issue with the vallist. It could be getting a bad argument type inside the routine. I would either trace when you run it or put some markers inside (terpri)(princ "A") in various locations to pinpoint which line is giving you the error. It looks like you have several custom sub functions so it is hard to locate the issue just from the code.
Vlide is saying that the error results from the following lines (but im not sure why):
(if (and Column# Row#)
(foreach Item Data@
(vlax-put-property ExcelRange "Item" Row# Column# (vl-princ-to-string Item))
(setq Column# (1+ Column#))
);foreach
@Anonymous wrote:
The gist of my issue is this...and I so don't understand what the heck is causing it?!??
....
Command: (doname vallist)
; error: bad argument type: consp
Why would my function give me an error when I pass it the list argument?!??
Does it say anything after the "consp" in the error message? I'm used to seeing it tell what kind of information it was given that isn't in the format it's expecting. It could be that you have a dotted pair somewhere and you're using (cadr) to get the second item from it, rather than (cdr). You could be pairing something with (cons) that should be paired with (list), e.g. note the difference between:
Command: (cons "25" "TE")
("25" . "TE")
and
Command: (list "25" "TE")
("25" "TE")
The latter is like what's in your list. Compare:
Command: (setq when (list "23" "TT"))
("23" "TT")
Command: (car when)
"23"
Command: (cdr when)
("TT") ; a one-item list
Command: (cadr when)
"TT" ; the item itself
versus:
Command: (setq what (cons "23" "TT"))
("23" . "TT")
Command: (car what)
"23"
Command: (cdr what)
"TT" ; same function, but returns the item, not in a list
Command: (cadr what)
; error: bad argument type: consp "TT"
Notice that the error message shows what wasn't in the form it expected [the "TT" after the word "consp"], Show us what your (string_), (getname) and (doitem) functions do, and it might be apparent.
You got it Kent....and I think the (cadr) may be the cause like you were mentioning. Anyways, here are the subs:
(defun String_ (In_Str / OutStr AddFlg DecFlg TmpLst) (setq OutStr (vl-list->string (foreach ForElm (reverse (vl-string->list In_Str)) (if AddFlg (setq TmpLst (cons ForElm TmpLst)) (cond ( (= 57 ForElm) ;(chr 57)=> "9" (setq DecFlg T TmpLst (cons 48 TmpLst)) ) ( (> 57 ForElm 47) ;"8"->-"0" (chr 47)=> "/" (setq AddFlg T TmpLst (cons (1+ ForElm) TmpLst)) ) ( (if DecFlg ; (chr 49)=> "1" (setq AddFlg T TmpLst (cons ForElm (cons 49 TmpLst))) (setq TmpLst (cons ForElm TmpLst)) ) ) ) ) ) ) ) (if AddFlg OutStr (strcat OutStr "1")) );defun
and getname
(defun getname (/ dwgname tempname1 dwgname1) ;;subfunction that returns simply the last 5 characters of a dwg name before the ".dwg" ;;ex output on "213035-PIPE-PID-00000500-00.DWG" returns "00500" ;;bhull 2/27/14 (setq dwgname (getvar "dwgname")) (setq tempname1 (substr dwgname (+ -7 (vl-string-search ".dwg" dwgname)))) (setq dwgname1 (substr tempname1 1 (- (strlen tempname1) 7))) (princ) );defun
and doitem
(defun doitem ( vallist / itemcell itemdata c) (setq c 0) (setq len (length vallist)) (setq itemcell (strcat "A" @excel_row)) (setq itemcell (string_ itemcell)) (setq itemdata "00") (repeat len (setq itemdata (string_ itemdata)) (putcell itemcell itemdata) (setq itemcell (string_ itemcell)) (setq c (1+ c)) );repeat (if (= c len)(dotype vallist)) ;;goto type subfunction );defun doitem
Alrighty, so to the cadr thing...here's the code where that may come into play:
(setq cell (strcat "B" @excel_row)) ;;starting cell value to leave one line from the top for a column header ;;subfunction (string_ cell) will increment to "A2" and then ;;"A3", incrementing each pass of the repeat loop until the end of the list. (setq c 0) (setq len (length vallist)) (repeat len (setq data (nth c vallist)) (setq adata (cadr data)) (setq bdata (car data)) (if (not fdata) (setq fdata (strcat adata "-" bdata))) (setq cell (string_ cell)) (putcell cell fdata) (setq ldata (list bdata adata)) (if (member ldata @dupeslist) (putcolor cell 15) );if (setq fdata nil) (setq c (1+ c)) );repeat (cond ((= c len)(doname vallist)) );cond ;;passes number of items entered to next subroutine to enter ;;information into the next column of excel. This time it's ;;the dwg-name, which should be the same per dwg. );defun
(setq ldata (list bdata adata)) but alas im not sure why that would prevent the function from operating as it was yesterday.
Okay, getting it narrowed down some I believe...
Still throwing the error if the routine is ran:
putex
; error: bad argument type: consp
and vlide shows the error coming from this function, the bolded lines
(defun PutCell (StartCell$ Data@ / Cell$ Column# ExcelRange Row#) (if (= (type Data@) 'STR) (setq Data@ (list Data@)) ) (setq ExcelRange (vlax-get-property *ExcelApp% "Cells")) (if (Cell-p StartCell$) (setq Column# (car (ColumnRow StartCell$)) Row# (cadr (ColumnRow StartCell$)) );setq (if (vl-catch-all-error-p (setq Cell$ (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property *ExcelApp% "ActiveSheet") "Range" StartCell$)) );setq );vl-catch-all-error-p (alert (strcat "The cell ID \"" StartCell$ "\" is invalid.")) (setq Column# (vlax-get-property Cell$ "Column") Row# (vlax-get-property Cell$ "Row") );setq );if );if (if (and Column# Row#) (foreach Item Data@ (vlax-put-property ExcelRange "Item" Row# Column# (vl-princ-to-string Item)) (setq Column# (1+ Column#)) );foreach );if (princ) );defun PutCell
Yet however
(putcell "b14" "TEST") into cad results in
it works just fine. So does this mean then that somehow the data type is incorrect despite
(if (= (type Data@) 'STR)
(setq Data@ (list Data@))
)
being in the putcell routine already??
Okay.
Repair of cad fixed the issue.
Was one of those buggy times where cad suddenly doesn't like something that's been working before.