Code Red > AutoLISP (Vanilla / Visual)
Change crosshait color with lisp
PM:
Hi . I am searching how to change the color of modelspace to 40 with lisp and how to bring iti back in normal (white) with lisp. I have seen some post with this but i can not understand the colors.
Thanks
Stefan:
First, I think you should not mess with these properties in lisp, unless you know exactly what you're doing.
When you change them with Options command, autocad takes care of the contrast you need to clearly distinguish them on screen.
And not only the modelspace and crosshair, but also the little Viewport Control text on the top-left of the modelspace window.
Second, which one is correct? Crosshair from the title, or modelspace, from your post?
The colors, for some obscure reason, are always expressed in BlueGreenRed values and not RGB!!!
This will change the crosshair color only.
Use vla-put-graphicswinmodelbackgrndcolor for modelspace and (setenv "2D Model viewport control color" ... ) for viewport control
--- Code - Auto/Visual Lisp: ---(defun c:chcol (/ dsp chc) (setq dsp (vla-get-display (vla-get-preferences (vlax-get-acad-object) ) ) ) (setq chc (vlax-variant-value (vlax-variant-change-type (vla-get-modelcrosshaircolor dsp) vlax-vblong ) ) ) ;color 40 -> 16760576 -> RGB = 255 191 0 ;crosshair 40 -> 49151 -> BGR = 0 191 255 ??? (if (= chc 49151) (vla-put-modelcrosshaircolor dsp (vlax-make-variant 16777215 vlax-vblong) ) (vla-put-modelcrosshaircolor dsp (vlax-make-variant 49151 vlax-vblong) ) ) (princ))
Lee Mac:
You could use something like this -
--- Code - Auto/Visual Lisp: ---(defun-q c:msc ( / d ) (eval (list 'defun-q 'c:msc '( / c ) (list 'setq 'c (list 'quote (list 49151 (vla-get-modelcrosshaircolor (setq d (vla-get-display (vla-get-preferences (vlax-get-acad-object) ) ) ) ) ) ) ) (list 'vla-put-modelcrosshaircolor d '(car c)) '(setq c:msc (vl-list* (car c:msc) (list 'setq 'c (list 'quote (reverse c))) (cddr c:msc))) '(princ) ) ) (c:msc))(vl-load-com) (princ)
The above function redefines itself with every evaluation, reversing the order of the stored colour numbers.
The colours are expressed as OLE colours, for which you can calculate the appropriate values using the OLE conversion functions as part of my Colour Conversion functions.
Stefan:
Nice one Lee, I like the way you switch the colors.
The only thing is, if the initial color is 40 when you load the lisp, nothing happens.
I had the same problem trying to store the initial value with setenv. But if 40 is hard coded, white could be also hard coded.
PM:
Thanks for the help :smitten:
Navigation
[0] Message Index
[#] Next page
Go to full version