Home > Enterprise >  How to get list of values and not names of variables, in Autolisp
How to get list of values and not names of variables, in Autolisp

Time:11-03

I am trying to create a function to use the variable name instead of values, but at the princ it is showing me only the name not the value.

(defun c:loop3 ()
    (setq xp 5)
    (setq count 0)
    (setq zp 200)
    
    (setq yp 5)
    (setq cenPT '(count xp yp zp))
    (princ cenPT)
  (princ)
)

I am expecting to print the value 5 0 200 but it prints the name of the variables.

CodePudding user response:

The use of the apostrophe (') or the quote function in AutoLISP causes the expression that follows to be marked as a literal expression, to be taken at face value and not interpreted - I explain this in far more detail in my tutorial on The Apostrophe and the Quote Function.

Hence, your expression:

(setq cenPT '(count xp yp zp))

Will result in the symbol cenPT being assigned the list of symbols (COUNT XP YP ZP) rather than evaluating such symbols to yield the values they may hold.

To evaluate the values, you should construct the list using the list function, i.e.:

(setq cenPT (list count xp yp zp))

CodePudding user response:

I found the answer

(setq cenPT count xp yp zp)

  • Related