View Full Version : Toggle display color with LISP
Flores
5th Nov 2003, 03:14 pm
I used to have a routine that toggled the display color from black to white. It was written in VLISP, but I cannot find it anymore. I used it for saving images with a white background, then I would toggle the screen back to black. Does anyone have this routine or one similar to it?
Flores
CADTutor
5th Nov 2003, 03:35 pm
This may help somewhat: http://www.civil.bcit.ca/faculty/thurston/acad/ACADFAQ2_copy.HTMl It details the use of the WMFBKGND variable. This can be used to change the background of objects copied to the clipboard from the background color to transparent.
I assume that there must also be a system variable that controls the background colour and a LISP routine could easily be used to change it but short of ploughing through the full list I can't tell you what that variable is.
Flores
5th Nov 2003, 04:34 pm
WMFBKGND seems to be only useful when using the "wmfout" command. It doesn't help with the "saveimg" > .bmp. Wmfout doesn't work with render:
Render + wmfout = wireframe image.
Hide + wmfout = correct image.
Shade + wmfout = hidden image, no shade.
As far as rendering images and background colors go: Type in "background" at the command line > Solid Radio button: Uncheck "Autocad Background" > move all sliders to the right so the 3 colors in the RGB color system is "1.00". Now whenever you render, it will have a white background regardless of the display color.
I do not know if it is possible to change the background color with LISP, I believe it has to be done with VLISP.
Flores
fuccaro
6th Nov 2003, 03:30 pm
The system variable called RIBACKGROUND was used for this, but it is no longer available. So you will need Visual Lisp or VBA to change the background collor.
Flores
6th Nov 2003, 05:12 pm
This worked pretty good... it only takes 2 letters to go back and forth between the colors, but I would still like to make it work as a toggle.
***********************************************
;;Background color changer
;;Gary Maze, SMC Corporation of America
;;11/27/02
;;
;;acadobject is the ActiveX component of the AutoCad instance
;;acadpref is the preferences property of acadobject
;;acaddisp is the display property of acadpref
;;the background color is the windows color number calculated
;;by the following formula;
;;(65536*blue)+(256*green)+red, where blue, green and red can
;;be 0 (off) to 255 (all the way on)
;;WB makes a whitebackground with a black crosshair
(defun c:wb () ;;white background
(setq acadobject (vlax-get-acad-object))
(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ _ _(vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 16777215)
_ _ _(vlax-put-property acaddisp 'ModelCrosshairColor 0)
)
;;BB makes a black background with a white crosshair
(defun c:bb () ;; black background
;(defun c:blackback (/ acadobject acadpref acaddisp)
_(setq acadobject (vlax-get-acad-object))
_(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ (vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 0)
_ (vlax-put-property acaddisp 'ModelCrosshairColor 16777215)
_)
;The user just wanted to change his background color to white, but I
; thought it might be nice to add a restore function as well.
********************************************
Flores
fuccaro
12th Nov 2003, 10:07 am
This is the first time I “touch” a VL routine. I am sure that this is not the easiest way, but it works!
Flores, now you can create a button for toggle the background color. If it does not work, do not call me: I must admit that I do not understand completely how it works, I just decided to start learning VL.
;;Background color changer
;;Gary Maze, SMC Corporation of America
;;11/27/02
;;
;modified by Miklos Fuccaro
;mfuccaro@hotmail.com
;November 2003
;
(defun toggle_BackGround_color()
(defun wb () ;;white background
(setq whitebackground T)
(setq acadobject (vlax-get-acad-object))
(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ _ _(vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 16777215)
_ _ _(vlax-put-property acaddisp 'ModelCrosshairColor 0)
)
(defun bb () ;; black background
(setq whitebackground nil)
_(setq acadobject (vlax-get-acad-object))
_(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ (vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 0)
_ (vlax-put-property acaddisp 'ModelCrosshairColor 16777215)
_)
(if whitebackground (bb) (wb))
)
What’s up, Hendie? Hendie, did you read the code? And now you can not stop laughing?
hendie
13th Nov 2003, 10:05 am
fuccaro, I haven't had the chance to try out your code yet but rest assured I will not be laughing if it doesn't work (I'm sure it does !).
I have written thousands of lines of code that does not work :P
Flores
13th Nov 2003, 03:27 pm
Thanks Fuccaro it worked as expected . I just had to change the first line from
(defun toggle_BackGround_color() to
(defun c:toggle_BackGround_color() and then I made a macro for the button:
^C^C(if c:toggle_BackGround_color (princ)(load "toggle_BackGround_color")) toggle_BackGround_color and made sure that the folder that I saved it to was in the search path. Now I can simply press a button to toggle the screen.
Flores
fuccaro
13th Nov 2003, 03:41 pm
Great, Flores!
Together we are the smartest people around here :lol:
exout
29th Jul 2005, 04:58 pm
hi,
i found this topic because i had the exact same problem.
now i tried to use the code, but actually i don'T really know how to use it..
i saved it as a .lsp file, then loaded it in autocad as an application. now i made a button with the commandline flores wrote (tried the whole thing with and without the "c:"), but it just doesnt work.
am i doing anything wrong? where do i have to save the file?
i'm using acad2006.
thanks!
eX
NoelStalker
5th Nov 2008, 03:35 pm
I would like to make a command to toggle between white and black background as well. I tried Flores' lisp file and it did not work. It returned this error:
Command: WB
; error: no function definition: VLAX-GET-ACAD-OBJECT
fuccaro
5th Nov 2008, 08:40 pm
Try to add (vl-load-com) after the line
(defun toggle_BackGround_color()
Other than that I don't know.
NoelStalker
5th Nov 2008, 10:20 pm
fuccaro,
Thanks for the response. I don't see
(defun toggle_BackGround_color()
in here:
***********************************************
;;Background color changer
;;Gary Maze, SMC Corporation of America
;;11/27/02
;;
;;acadobject is the ActiveX component of the AutoCad instance
;;acadpref is the preferences property of acadobject
;;acaddisp is the display property of acadpref
;;the background color is the windows color number calculated
;;by the following formula;
;;(65536*blue)+(256*green)+red, where blue, green and red can
;;be 0 (off) to 255 (all the way on)
;;WB makes a whitebackground with a black crosshair
(defun c:wb () ;;white background
(setq acadobject (vlax-get-acad-object))
(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ _ _(vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 16777215)
_ _ _(vlax-put-property acaddisp 'ModelCrosshairColor 0)
)
;;BB makes a black background with a white crosshair
(defun c:bb () ;; black background
;(defun c:blackback (/ acadobject acadpref acaddisp)
_(setq acadobject (vlax-get-acad-object))
_(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ (vlax-put-property acaddisp 'GraphicsWinmodelBackgrndColor 0)
_ (vlax-put-property acaddisp 'ModelCrosshairColor 16777215)
_)
;The user just wanted to change his background color to white, but I
; thought it might be nice to add a restore function as well.
fuccaro
6th Nov 2008, 06:49 am
Firstly try to enter that line into the command line. After that if the program works, we will find a place to insert that line right in the program.
NoelStalker
6th Nov 2008, 07:57 pm
Fuccaro,
I entered that command on the command line and then tried to run the lisp. This is what happened
Command: (defun toggle_BackGround_color()
(_> wb
(_> bb
(_> *Cancel*
; error: Function cancelled
fuccaro
7th Nov 2008, 07:00 am
Here is what I meant:
- Load the Lisp program: Tools>Load application...
- Enter in the command line (vl-load-com)
- Start the program by entering in the command line (WB)
Unfortunately I don't have AutoCAD 2005 to try it out :(
rookie37
7th Nov 2008, 07:19 am
I would like this program.
How do I load and execute a vba or visual lisp
By the way, which one is this?
;;WB makes a whitebackground with a black crosshair
(defun c:wb () ;;white background
(setq acadobject (vlax-get-acad-object))
(setq acadpref (vlax-get-property acadobject 'preferences))
_(setq acaddisp (vlax-get-property acadpref 'display))
_ _ _(vlax-put-property acaddisp
Will it work on acad 2004 that I used at home?
NoelStalker
7th Nov 2008, 03:14 pm
fuccaro,
I tried what you suggested. Here is a copy of my command line
Command: appload
background color changer (doesn't work).lsp successfully loaded.
Command:
Command:
Command: (vl-load-com)
Command: (WB)
; error: no function definition: WB
Perhaps we should go about this a different way.
Is there a variable that I can change?
Can I type in a command like "background" and then type in the color?
If so then I could make a lisp file.
fuccaro
7th Nov 2008, 09:14 pm
I am so sorry for loosing your time!
Load the Lisp and type in the command line:
(TOGGLE_BACKGROUND_COLOR)
When I previously read your request I was at home, without AutoCAD. Now I tested and it works for me. Sorry again!
NoelStalker
10th Nov 2008, 10:05 pm
fuccaro
Of course! I should read the code. Thanks so much for your help. Have a great day.
:D
fuccaro
11th Nov 2008, 10:59 am
Thank you for returning with a feed-back! Have a nice day too! :)
ASMI
11th Nov 2008, 03:43 pm
This functions for RGB <-> AutoCAD bits translation can be usefull.
(defun RGB->Bits(RGB_List)
(if(vl-every
'(lambda(c)(and(< -1 c)(> 256 c)))RGB_List)
(apply '+(mapcar '* RGB_List '(65536 256 1)))
); end if
); end of RGB->Bits
(defun Bits->RGB(Bits / r g)
(if(and(< -1 Bits)(> 16777216 Bits))
(list(setq r(/ Bits 65536))
(setq g(/(- Bits(* r 65536))256))
(- Bits(+(* r 65536)(* g 256)))
); end list
); end if
); end Bits->RGB
For example Magenta color (255 0 255) to bits:
_$ (RGB->Bits '(255 0 255))
16711935
And back Magenta bits to RGB list:
_$ (Bits->RGB 16711935)
(255 0 255)
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.