Message 1 of 20
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Here is a fabulous Code I found somewhere which is by LeeMac probably. This code applies color to 3DFace entities according to their Z-value.
(defun c:zmap ( / cma cmi del elv enx idx lst pct rng sel zmn zmx )
(setq cmi '(0 0 255) ;; Minimum colour
cma '(255 0 0) ;; Maximum colour
zmx -2.0
zmn -14.0
)
(if (setq sel (ssget "_:L" '((0 . "3DFACE"))))
(progn
(repeat (setq idx (sslength sel))
(setq enx (entget (ssname sel (setq idx (1- idx))))
elv (if (= "3DFACE" (cdr (assoc 0 enx)))
(max (cadddr (assoc 10 enx)) (cadddr (assoc 11 enx)))
(cdr (assoc 38 enx))
)
lst (cons (list enx elv) lst)
zmx (max zmx elv)
zmn (min zmn elv)
)
)
(setq rng (mapcar '- cma cmi)
del (- zmx zmn)
)
(if (equal 0.0 del 1e-8)
(princ "\nNo change in elevation.")
(foreach itm lst
(setq pct (/ (- (cadr itm) zmn) del))
(entmod
(append (car itm)
(list
(cons 420
(apply 'LM:rgb->true
(mapcar '(lambda ( a b ) (+ a (* b pct))) cmi rng)
)
)
)
)
)
)
)
)
)
(princ)
)
;; RGB -> True - Lee Mac
;; Args: r,g,b - [int] Red, Green, Blue values
(defun LM:RGB->True ( r g b )
(logior (lsh (fix r) 16) (lsh (fix g) (fix b))
)
(princ)
The only problem with this code is that I can only select two colors and it will create a gradient based on them. Instead, I need to be able to select more than two colors, such that the gradient starts from the first (minimum) color and proceeds to next colors, and finally ending on the last (maximum) color.
For starters, you can try to include (some or all of) the following colors.
(setq cmi '(0 0 255) ;; Minimum colour
col_2 '(0 95 255)
col_3 '(0 205 255)
col_4 '(0 255 160)
col_5 '(30 255 0)
col_6 '(215 255 0)
col_7 '(255 225 0)
col_8 '(255 185 0)
col_9 '(255 100 0)
cma '(255 0 0) ;; Maximum colour
)
Any help?
Solved! Go to Solution.