Expanding a List - Trouble wit
Part of my automation project needs to work off of a list of blocks in a certain format (name l w x y A), I would like to build this from an existing list that has the block names.My current progress is the following:(defun builditemlist (l /)(princ "\nStartingBuild") (if (/= l nil) (progn ;if l isnt empty ;Take first item in l (setq item (ssname l 0)) (princ " GotItem") ;grab data from INSERT reference (x and y insertion) (setq ins_block (cdr (assoc 10 (entget item))) ) (princ ins_block) (princ "\n") ;grab data from BLOCK reference (l and w) ;make a list of the form (ssname x y l w A) (setq sublist (list item ins_block) ) ) (progn ;if l is empty (princ "\nDONE!") )) (list sublist (builditemlist (cdr l))))
The function is called in the main by:
(setq tobeshelved (builditemlist tobeshelved))
When I run in AutoCAD, the lists are formed, and do print.It looks like the error pops up when the tailcall? (not sure im using the correct words) is performed.
The call here:
(list sublist (builditemlist (cdr l)))
Is where I think the problem is.I want the routine to return a list that has its first element as the sublist, then the tail is filled with a call to builditemlist, with just the tail of the original list that was passed to it.
The error I get on running this is:
StartingBuild GotItem(6.1 72.0 0.0)
; error: bad function: ( (6.1 72.0 0.0))
Thank you in advance! Maybe this... I've only moved your last line into (if -> then statement); else statement is unnecessary...
(defun builditemlist ( l / item ins_block sublist ) (if l (progn ;if l isnt empty ;Take first item in l (setq item (car l)) ;grab data from INSERT reference (x and y insertion) (setq ins_block (cdr (assoc 10 (entget item))) ) ;grab data from BLOCK reference (l and w) ;make a list of the form (ssname x y l w A) (setq sublist (list item ins_block) ) (cons sublist (builditemlist (cdr l))) ) ))
The main function should have call to obtain sel. set "ss" and (builditemlist) function should operate on list of entity names obtained from sel. set "ss"...
(setq ss (ssget '((0 . "INSERT"))))(setq tobeshelved (builditemlist (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
Thanks for the suggestions.In my main I use a nice routine I found here to obtain a SS of the INSERT instances.That SS is passed to the routine in the setq I wrote out.I have tried moving the call into the if-then structure, and I get the same 'error; bad function' message Ahh!Nevermind!Just saw what you were getting at with what I was passing to the sub!Thanks so much, working great now!
页:
[1]