Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error in creating a dotted pair.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
754 Views, 8 Replies

Error in creating a dotted pair.

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

 

 

Tags (1)
8 REPLIES 8
Message 2 of 9
Gary_J_Orr
in reply to: Anonymous

Your stored value is a string, not a symbol... to get to the symbol that matches the string you need to "read" the string into Vlisp before it can evaluate the underlying variable value:

(cons 1 (read (nth cnt lst)))

-Gary
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 3 of 9
martti.halminen
in reply to: Anonymous


@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.

--

Message 4 of 9
Anonymous
in reply to: Anonymous

Let me ask a followup question....

What would the syntax be to create a list of attribute tags of a selected block?
Message 5 of 9
Gary_J_Orr
in reply to: Anonymous


@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

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 6 of 9
Anonymous
in reply to: Gary_J_Orr

brain fart...cons, of course....ugh
had everything else except for that...

the elements in the list...how do I remove the quotes?

(1REV 1DES 1DRWN 1CHKD 1APPVD 1DATE)
vs
("1REV" "1DES" "1DRWN" "1CHKD" "1APPVD" "1DATE")
Message 7 of 9
Anonymous
in reply to: Gary_J_Orr

ok...found it....

(setq lst (cons (read (cdr (assoc 2 ENT))) lst))

now I am getting a stringp error

(defun getTags ()
(setq tl_blk (ssget "X" '((0 . "INSERT") (2 . "_Rev")) ))
(if tl_blk
(progn
(setq NM (ssname tl_blk 0))
(setq ENT (entget NM))
(while (or (= (cdr (assoc 66 ENT)) 1)(/= (cdr (assoc 0 ENT)) "SEQEND"))
(setq NM (entnext NM))
(setq ENT (entget NM))
(setq lst (cons (read (cdr (assoc 2 ENT))) lst))
);while
(setq lst (reverse lst))
);progn
);if
);getTags
(getTags)
Message 8 of 9
Anonymous
in reply to: Gary_J_Orr

the list is getting created....

(1DATE 1APPVD 1CHKD 1DRWN 1DES 1REV)
Message 9 of 9
dbroad
in reply to: Anonymous

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>))

 

Architect, Registered NC, VA, SC, & GA.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost