I have two routines...On that gets the values of tags and sets them to a variable of the same name.
This works fine.
the next routine setRev Attribs that sets the value of tags, does not.
(defun getRevAttribs ()
(setq tl_blk (ssget "X" '((0 . "INSERT") (2 . "_Rev")) ))
(if tl_blk
(progn
(setq lst '(1REV 1DES 1DRWN 1CHKD 1DATE) cnt -1)
(setq llst (vl-list-length lst))
(setq NM (ssname tl_blk 0))
(setq ENT (entget NM))
(repeat llst
(setq NM (entnext NM))
(setq ENT (entget NM))
(setq cnt (1+ cnt))
(if (= (cdr (assoc 2 ENT)) (vl-symbol-name (nth cnt lst)))
(set (nth cnt lst) (cdr (assoc 1 ENT)))
);if
);while
);progn
);if
);getRevAttribs
The the other routine places the value into the tag
(defun setRevAttribs ()
(setq tl_blk (ssget "X" '((0 . "INSERT") (2 . "_Rev")) ))
(if tl_blk
(progn
(setq lst '(1REV 1DES 1DRWN 1CHKD 1DATE) cnt -1)
(setq llst (vl-list-length lst))
(setq NM (ssname tl_blk 0))
(setq ENT (entget NM))
(repeat llst
(setq NM (entnext NM))
(setq ENT (entget NM))
(setq cnt (1+ cnt))
(if (= (cdr (assoc 2 ENT)) (vl-symbol-name (nth cnt lst)))
(entmod (subst (cons 1 (value (nth cnt lst))) (assoc 1 ENT) ENT))
);if
; (if (= (cdr (assoc 2 ENT)) "1REV")
; (entmod (subst (cons 1 1REV)(assoc 1 ENT) ENT)))
);while
);progn
);if
);setRevAttribs
the list of vars all test correctly as far as their values.
this is where it is failing...(in bold...)
(if (= (cdr (assoc 2 ENT)) (vl-symbol-name (nth cnt lst)))
(entmod (subst (cons 1 (nth cnt lst)) (assoc 1 ENT) ENT))
);if
I should get a dotted pair that says (1 . "A"). Instead, I get (1 . 1REV)
what I can't seem to figure out is how to get the value of 1REV.
When I manually use this, it works...
; (if (= (cdr (assoc 2 ENT)) "1REV")
; (entmod (subst (cons 1 1REV)(assoc 1 ENT) ENT)))
Is there a (value_of (nth cnt lst)) ?
Thanks....
Tim
Solved! Go to Solution.
Solved by martti.halminen. Go to Solution.
Solved by Gary_J_Orr. Go to Solution.
@Anonymous wrote:
Is there a (value_of (nth cnt lst)) ?
If you need the value stored in the variable named by the symbol you get from (nth cnt lst), the function you are looking for is VL-SYMBOL-VALUE.
--
@Anonymous wrote:
Let me ask a followup question....
What would the syntax be to create a list of attribute tags of a selected block?
here are a couple of functions feel free to adapt and/or grab the parts that are revelant to your needs...
one gets a list of attribute names while the other gets a list of dotted pairs in the form of ("tagname" . "tagvalue")
;returns list of attribute names from a selected Insert ;(setq TestList(GJO_Get-AttNames)) (defun GJO_Get-AttNames ( / Insert InsertEntyList NextEnt EntList ReturnList) (setq Insert (car (entsel))) (setq InsertEntyList (entget Insert)) (if (= 1 (cdr (assoc 66 InsertEntyList))) (progn (setq NextEnt (entnext Insert)) (while NextEnt (setq EntList (entget NextEnt)) (if (= (cdr (assoc 0 EntList)) "ATTRIB") (setq ReturnList (cons (cdr (assoc 2 EntList)) ReturnList)) );if attribute (setq NextEnt (entnext NextEnt)) );while );progn );if has attributes (if ReturnList (reverse ReturnList) nil) );defun ;returns list of paired attribute names and values from a selected insert ;(setq TestList(GJO_Get-AttNamesAndVals)) (defun GJO_Get-AttNamesAndVals ( / Insert InsertEntyList NextEnt EntList ReturnList) (setq Insert (car (entsel))) (setq InsertEntyList (entget Insert)) (if (= 1 (cdr (assoc 66 InsertEntyList))) (progn (setq NextEnt (entnext Insert)) (while NextEnt (setq EntList (entget NextEnt)) (if (= (cdr (assoc 0 EntList)) "ATTRIB") (setq ReturnList (cons (cons (cdr (assoc 2 EntList)) (cdr (assoc 1 EntList)) ) ReturnList ) );setq );if attribute (setq NextEnt (entnext NextEnt)) );while );progn );if has attributes (if ReturnList (reverse ReturnList) nil) );defun
-Gary
In addition to what Gary posted, here are a couple of alternatives depending on whether you want to pick an insert or enter a block name:
;;DCB return a list of non-constant attribute tags for a ;;block reference given the ename (defun blockrefatts (ename / lst) (while (setq ename (entnext ename)) (setq lst (cons (cdr(assoc 2 (entget ename))) lst)) (reverse (cdr lst)))) ;;DCB Return a list of non-constant attributes given the ;;name of a block (defun blockatts (name / ename ei lst) (if (setq ename (tblobjname "block" name)) (while (setq ename (entnext ename)) (setq ei (entget ename)) (if (and (= "ATTDEF" (cdr(assoc 0 ei))) (/= 2 (logand (cdr(assoc 70 ei)) 2)));;not constant (setq lst (cons (cdr(assoc 2 ei)) lst)) ) ) ) (reverse lst)) ;;to return a list of symbol names (mapcar 'read (blockatts <name>))