Author Topic: Lisp for Coloring entities by Elevation in RGB Colors  (Read 1421 times)

0 Members and 1 Guest are viewing this topic.

jtm2020hyo

  • Newt
  • Posts: 198
Lisp for Coloring entities by Elevation in RGB Colors
« on: April 14, 2020, 04:53:54 PM »
I need to change the color by elevation properties, I found some lisp, I need to use all colors and limit the elevation range


image 1;


 

In image 1, I need to set a limit the max elevation to 11000 and minimal in 1000, blue for the highest and red for lower, in the middle green, I mean RGB, and If possible use DCL to let the user choose colors. I need to use all the colors range in the Index Color pallet. Anyone can help me?

 

image 2

 

 

links:

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-coloring-entities-by-elevat...

 

https://www.theswamp.org/index.php?topic=51064.0

 

here an example:

 
Code: [Select]
    (defun c:zmap ( / cma cmi del elv enx idx lst pct rng sel zmn zmx )
        (setq cmi '(255   0   0) ;; Minimum colours
              cma '(255 255   0) ;; Maximum colours
              zmx 0.0
              zmn 0.0
        )
        (if (setq sel (ssget "_:L" '((0 . "LINE,LWPOLYLINE"))))
            (progn
                (repeat (setq idx (sslength sel))
                    (setq enx (entget (ssname sel (setq idx (1- idx))))
                          elv (if (= "LINE" (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)