Hey all, I'm having to modify this routine pretty heavily for a new project that I've been on.
I'll be getting past each task as I come to it, and the first one I've came across is this....firstly, there are three tags for the blocks that I am extracting from the .dwg into excel...."Size" "Type" and "Tag".
The program I am using creates a "valllist" (values list), and then it shoots each bit of the vallist into excel, so I need these vallist to show the attribute values in a consistent manner.
Upon running the subfunction a few times over one drawing, I've noticed that some of the blocks have their attributes in reverse order, creating a fudged vallist. Where the size should be, I'm getting the "tag" in about half of the blocks.
I'll post how this vallist is looking, and then the code behind it.
(createvallist ss) (("1623" "L6TM-H2" "02-0.5\"") ("1624" "L6TM-H2" "02-0.5\"") ("1625" "L6TM-H2" "02-0.5\"") ("02-1.5\"" "X1TF-H2" "1601") ("02-0.5\"" "X1TR-H2" "1602") ("02-1\"" "X4S-H2" "1603") ("02-1.5\"" "X1TF-H2" "1606") ("02-0.5\"" "X1TR-H2" "1607") ("02-1\"" "X4S-H2" "1608") ("02-1.5\"" "X1TF-H2" "1611") ("02-0.5\"" "X1TR-H2" "1612") ("02-1\"" "X4S-H2" "1613") ("02-1\"" "U2TR-H2" "1616") ("1615" "L6TN-H2" "02-0.5\"") ("1600" "L6TM-H2" "02-0.5\"") ("1605" "L6TM-H2" "02-0.5\"") ("1610" "L6TM-H2" "02-0.5\"") ("1626" "X1TR-H2" "02-0.5\"") ("1627" "X1TR-H2" "02-0.5\"") ("1628" "X1TR-H2" "02-0.5\"") ("1629" "X1TR-H2" "02-0.5\"") ("1630" "X1TR-H2" "02-0.5\"") ("1631" "X1TR-H2" "02-0.5\"") ("02-0.5\"" "X1TR-H2" "1632") ("02-0.5\"" "X1TR-H2" "1633") ("0.5\"" "X1TR-H2" "1634") ("0.5\"" "X1TR-H2" "1637") ("0.5\"" "L6TM-H2" "1636") ("0.5\"" "L6TM-H2" "1635") ("0.5\"" "X1TR-H2" "1638") ("02-0.5\"" "X5TC-H2" "1639") ("02-0.5\"" "X1TR-H2" "1640") ("" "" "") ("" "" "") ("" "" ""))
and here's what creates the vallist, the subfunction
(defun createvallist ( ss / taglist tagrow valrow edata e i) (setq i -1) ;;FOR OAK GROVE VALVES (setq TagList '("TYPE" "TAG" "SIZE")) (repeat (sslength ss) (setq TagRow nil) (setq ValRow nil) (setq Edata (entget (setq e (ssname ss (setq i (1+ i)))))) (while (/= (Dxf 0 Edata) "SEQEND") (if (and (= (Dxf 0 Edata) "ATTRIB") (member (dxf 2 Edata) TagList) ;;if tag is on list );and (progn (setq TagRow (cons (Dxf 2 Edata) TagRow)) (setq valRow (cons (Dxf 1 Edata) ValRow)) );progn ) (setq Edata (entget (setq e (entnext e)))) ) ;while (setq vallist (cons valrow vallist)) );repeat );defun
Now I've tried code like this, added right under the (setq TagRow...) and (setq ValRow...) portions
(progn (setq TagRow (cons (Dxf 2 Edata) TagRow)) (if (= (car tagrow) (strcase "TAG")) (reverse tagrow)) (setq valRow (cons (Dxf 1 Edata) ValRow)) (if (= (car tagrow)(strcase "TAG")) (reverse valrow)) );progn
But unfortunately for me the vallist doesn't come out in a consistent manner, despite code that to me should work.
Could someone point me in the right direction, getting these attribute values to appear in a consistent fashion no matter the order that the attributes are showing in the blocks/vallist?
Attached is a .dwg that contains some of the blocks that are in the code, if it allows me I'll post the complete lisp file as well.
Thanks in advance!
Hi Brandon,
I don't have AutoCAD to test, but perhaps something like this...
(defun vallst (ss / a attlst b c ent hnd i lst obj) (repeat (setq i (sslength ss)) (setq hnd (ssname ss (setq i (1- i))) ent (entget hnd) attlst nil obj (vlax-ename->vla-object hnd) attlst (vlax-invoke obj 'GetAttributes) );; setq (foreach att attlst (cond ((and (= (strcase (vla-get-TagString att)) "SIZE") (/= (vla-get-TextString att) "")) (setq a (vla-get-TextString att)) ) ((and (= (strcase (vla-get-TagString att)) "TYPE") (/= (vla-get-TextString att) "")) (setq b (vla-get-TextString att)) ) ((and (= (strcase (vla-get-TagString att)) "TAG") (/= (vla-get-TextString att) "")) (setq c (vla-get-TextString att)) ) );; cond );; foreach (if (and a b c) (setq lst (cons (list a b c) lst) a nil b nil c nil) );; if );; repeat lst ) ;; usage ;; (setq vallist (vallst ss))
HTH
Henrique
@Anonymous wrote:
Hey all, I'm having to modify this routine pretty heavily for a new project that I've been on.
I'll be getting past each task as I come to it, and the first one I've came across is this....firstly, there are three tags for the blocks that I am extracting from the .dwg into excel...."Size" "Type" and "Tag".
Thanks in advance!
Does that mean the block should have all three TAGS [Size.Type.Tag] otherwise dont include on the list?
EDIT: I see henrique already provided you a solution 🙂
Henrique and Pbejse, glad to see you two still around here.
Thanks Henrique, i'll proceede this morning!
Looks good, accounts for empty strings too.
Thanks a ton, this'll allow me to get further this morning.