Message 1 of 9

Not applicable
11-17-2019
12:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
Recently I wanted to create a script that would help my office to realize the difference between AutoCAD screen colors and actual plot colors. You helped me a lot and I want to share with you the result.
RGB_ARRAY
The created routine is producing 4096 (16x16x16) hatch rectangles, each having subsequent color in RGB.
(R: 0, G: 0, B: 0), (R: 17, G: 0, B: 0), (R: 34, G: 0, B: 0) ... (R: 255, G: 255, B: 255).
Well! The code is working properly, but at first glance seems to me a bit repetitive?
Please test it for yourself and let me know what kind of optimization would you add?
;;;;;;;;;;;;;;;;;;;;;;;; FUNCTION TO REMAP RGB COLOR INTO RGB DXF420;;;;;;;;;;;;;;; (defun RGB->vp-col (l) (apply '+ (mapcar 'lsh (if (numberp l) (list 195 0 0 l) (cons 194 l)) '(24 16 8 0) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;; RGB_ARRAY (R G AND B VALUES);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:RGB_Array_RGB (/ rgb_interval rgb_hatch R G B RGB global_translation i_translation x_translation y_translation layername x1 x2 x3 x4 y1 y2 y3 y4 ) (setq B 0 global_translation 0 ) ;;;;;; CREATES 16 x 2D ARRAYS EACH TIME WITH HIGHER "B" VALUE (repeat 16 (RGB_Array_RG rgb_interval rgb_hatch R G B RGB global_translation i_translation x_translation y_translation layername x1 x2 x3 x4 y1 y2 y3 y4 ) (setq B (+ B 17)) (setq global_translation (+ global_translation 2000)) ) ) ;;;;;;;;;;;;;;;;;;;;;;;; RGB_ARRAY (ONLY R AND G VALUES) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun RGB_Array_RG ( rgb_interval rgb_hatch R G B RGB global_translation i_translation x_translation y_translation layername x1 x2 x3 x4 y1 y2 y3 y4 ) (setq rgb_interval 17 y_translation 0 x_translation 0 i_translation 0 R 0 G 0 ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; OUTER REPEAT LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CREATES AN 2D ARRAY OF HATCH ENTITIES WITH SUBSEQUENT R and G VALUES ;; (repeat 16 ;;;;;; HATCH_ENTITY_LAYER_COORDINATES_COLOR (setq layername "0" x1 (+ 0 x_translation global_translation) y1 (+ 0 y_translation) x2 (+ 100 x_translation global_translation) y2 (+ 0 y_translation) x3 (+ 100 x_translation global_translation) y3 (+ 100 y_translation) x4 (+ 0 x_translation global_translation) y4 (+ 100 y_translation) RGB (list R G B) RGB (RGB->vp-col RGB) ) ;;;;;; HATCH_ENTITY (setq rgb_hatch (list (cons 0 "HATCH") ; ENTITY TYPE (cons 100 "AcDbEntity") (cons 8 layername) ; LAYER NAME (cons 100 "AcDbHatch") (cons 62 256) ; COLOR NUMBER (cons 10 (list 0.0 0.0 0.0)) (cons 210 (list 0.0 0.0 1.0)) (cons 2 "SOLID") (cons 70 1) (cons 71 0) (cons 91 1) (cons 92 1) (cons 93 4) (cons 72 1) ; FIRST POINT (cons 10 (list x1 y1)) (cons 11 (list x2 y2)) (cons 72 1) ; SECOND POINT (cons 10 (list x2 y2)) (cons 11 (list x3 y3)) (cons 72 1) ; THIRD POINT (cons 10 (list x3 y3)) (cons 11 (list x4 y4)) (cons 72 1) ; FOURTH POINT (cons 10 (list x4 y4)) (cons 11 (list x1 y1)) (cons 97 0) (cons 75 2) (cons 76 1) (cons 98 1) (cons 10 (list 0.0 0.0 0.0)) (cons 470 "LINEAR") (cons 420 RGB) ) ) ;_end rgb_hatch (entmake rgb_hatch) ;_create_hatch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; INNER REPEAT LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;; CREATES 15 HATCH ENTITIES, EACH TIME WITH HIGHER G VALUE (repeat 15 ;;;;;; HATCH_ENTITY_LAYER_COORDINATES_COLOR (setq x1 (+ 100 i_translation global_translation) y1 (+ 0 y_translation) x2 (+ 200 i_translation global_translation) y2 (+ 0 y_translation) x3 (+ 200 i_translation global_translation) y3 (+ 100 y_translation) x4 (+ 100 i_translation global_translation) y4 (+ 100 y_translation) G (+ G rgb_interval) RGB (list R G B) RGB (RGB->vp-col RGB) i_translation (+ i_translation 100) ) ;;;;;; HATCH_ENTITY (setq rgb_hatch (list (cons 0 "HATCH") ; ENTITY TYPE (cons 100 "AcDbEntity") (cons 8 layername) ; LAYER NAME (cons 100 "AcDbHatch") (cons 62 256) ; COLOR NUMBER (cons 10 (list 0.0 0.0 0.0)) (cons 210 (list 0.0 0.0 1.0)) (cons 2 "SOLID") (cons 70 1) (cons 71 0) (cons 91 1) (cons 92 1) (cons 93 4) (cons 72 1) ; FIRST POINT (cons 10 (list x1 y1)) (cons 11 (list x2 y2)) (cons 72 1) ; SECOND POINT (cons 10 (list x2 y2)) (cons 11 (list x3 y3)) (cons 72 1) ; THIRD POINT (cons 10 (list x3 y3)) (cons 11 (list x4 y4)) (cons 72 1) ; FOURTH POINT (cons 10 (list x4 y4)) (cons 11 (list x1 y1)) (cons 97 0) (cons 75 2) (cons 76 1) (cons 98 1) (cons 10 (list 0.0 0.0 0.0)) (cons 470 "LINEAR") (cons 420 RGB) ) ;_end list ) ;_end rgb_hatch (entmake rgb_hatch) ;_create_hatch ) ;_ end INNER LOOP (setq y_translation (+ y_translation 100) i_translation 0 G 0 R (+ R rgb_interval) ) ) ;_ end OUTER REPEAT LOOP ) ; _end RGB_ARRAY_RG
Solved! Go to Solution.