Im getting this error when trying to get the max of my list of numbers. What am I missing?
Solved! Go to Solution.
Solved by john.kaulB9QW2. Go to Solution.
Try this. I hope you can figure out the reason for getting error with your code.
I would need test dwg for your code, but obviously cons is not needed. It create list ((a b c d)) and this is unnecessary to look for max value inside list.
(defun c:TEST (/ MFF 1stk 2stk 3stk 4stk toc hpd b18 c18 d18 e18 f18 j3 j6 j9)
(setq MFF (getreal "Enter MFF :"))
(setq 1stk (car (entsel "\nSelect Front Left Stake: ")))
(setq 1stk (atof (getpropertyvalue 1stk "ELEV2")))
(setq 2stk (car (entsel "\nSelect Back Left Stake: ")))
(setq 2stk (atof (getpropertyvalue 2stk "ELEV2")))
(setq 3stk (car (entsel "\nSelect Back Right Stake: ")))
(setq 3stk (atof (getpropertyvalue 3stk "ELEV2")))
(setq 4stk (car (entsel "\nSelect Front Right Stake: ")))
(setq 4stk (atof (getpropertyvalue 4stk "ELEV2")))
(setq toc (car (entsel "\nSelect High TOC: ")))
(setq toc (atof (getpropertyvalue toc "ELEV2")))
(setq hpd (list 1stk 2stk 3stk 4stk))
(setq hpd (apply 'max hpd))
(setq b18 (- MF 100))
(setq c18 (- MF toc))
(setq e18 (- hpd toc))
(setq f18 (+ e18 0.8))
(setq j3 (list f18 b18 c18))
(setq j3 (apply 'max j3))
(setq d18 (+ j3 100))
(setq j6 (+ toc j3))
(setq j9 (- j6 0.8))
(princ j3)
(princ j6)
(princ j9)
)
Add some testing procedure to make your code bulletproof.
Also check
(setq b18 (- MF 100))
I guess it should be:
(setq b18 (- MFF 100))
Miljenko Hatlak
Also check this helper function. It assures that asked entity is selected before processing.
(defun get_selection (msg)
(setq e (car(entsel msg)))
(if (and (not e) (= (getvar 'Errno) 7)) (get_selection msg) e)
)
Usage:
(setq e (get_selection "\nPick it >"))
As long as you don't pick some entity i.e function receives nil it recursively calls itself. With some variations this is standard include in my autolisp codes.
Miljenko Hatlak
Since you don't use that list for anything else, there's no need to make it into a list variable first, and then apply (max) to it and replace the value in the variable, for example like this:
(setq hpd (list 1stk 2stk 3stk 4stk))
(setq hpd (apply 'max hpd))
You can just get the maximum of those values directly, without the middle-man of the list variable:
(setq hpd (max 1stk 2stk 3stk 4stk))
Can't find what you're looking for? Ask the community or share your knowledge.