Hello,
I am trying to build a LISP that
-selects all dynamic blocks of a given name (done)
-extracts the attributes for the blocks (done, maybe?)
-removes blocks from the selection set with a blank value for a certain attribute (stuck)
-loads csv data into a list of lists (done)
-matches the remaining blocks to corresponding rows in the csv data (maybe done if I could get the LISP that far)
-updates the attribute data in the blocks (probably done if I could get that far)
I think I have the base code written for all of it, I'm error checking now and hitting a wall filtering the blocks with nil data
The current subfunction is here. Much of it is from @ronjonp, heavily modified from a previous project.
(defun SelectBlocks ( / name n out)
(if (setq name "SPLICE CLOSURE" ;;selecting all dynamic blocks of this name
Blklst (ssget "_X" '((0 . "INSERT")))
n -1
out (ssadd)
)
(while (setq blck (ssname Blklst (setq n (1+ n))))
(if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object blck)))
(if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object blck))) (strcase name))
(ssadd blck out)
)
)
)
)
(vl-remove-if 'listp (mapcar 'cadr (ssnamex Blklst))) ;;remove if not a list?
(if (/= 0 (sslength out))(sssetfirst nil out)(princ (strcat "No Dynamic Block found by the Name - " name))) ;;if no blocks error
(foreach blck BlkLst ;;for each block
(progn
(vl-remove-if 'listp (mapcar 'cadr (ssnamex Blklst))) ;;remove if not a list? (setq d (vlax-invoke (vlax-ename->vla-object blck) 'getattributes)) ;;Get attributes
(setq AttLst (cons (append (mapcar 'vla-get-textstring d)) AttLst)) ;;Compile list of attribute values
(alert "got attributes")
(setq ExZ 0.0)
(cons ExZ AttLst)
(setq ExEst (getpropertyvalue blk "Position/Y"))
(cons ExEst Attlst)
(setq ExNrth (getpropertyvalue blk "Position/X"))
(cons ExNrth AttLst)
(if (= (nth 3 AttLst) nil) ;;if SPLICE_NUMBER attribute is blank then
(vl-remove blck Blklst) ;;remove block from selection set
)
(alert "removed blanks")
)
)
)
I get a 'bad argument type: consp <Selection set: be>' error at about the 'for each' line.
The full code is attached below
Thanks for any insights.