Jump to content

Lisp to change background color modelspace and layout


Sandervp

Recommended Posts

Every time, after I start up AutoCad, the background color of my model en layout are black.

 

I prefer the RGB color 40,40,40. This is dark grey.

 

AutoCad doesn't save this.

 

Why?

 

I've searched on the internet and I have found some lisps to change my background color by using different commands.

The most of these lisps are creating commands for changing the background in white, black, red, green or grey.

This grey is not the grey that I want to have.

 

What do I have to change in this lisp to get the RGB 40,40,40 color background?

 

; Set the background in model and paper space to grey
(defun c:BGGrey ()
 (vl-load-com)
 (setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))
 (setq drafting (vla-get-drafting (vla-get-preferences (vlax-get-acad-object))))
 (vla-put-GraphicsWinModelBackgrndColor disp 5987163)
 (vla-put-GraphicsWinLayoutBackgrndColor disp 5987163)
 (vla-put-LayoutCrosshairColor disp 16777215)
 (vla-put-ModelCrosshairColor disp 16777215)
 (vla-put-AutoTrackingVecColor disp 16777215)
 (vla-put-AutoSnapMarkerColor drafting 2)
 (princ)
)

 

The other colors are white in this lisp except the last:

(vla-put-AutoSnapMarkerColor drafting 2)

 

How can I change this into an other, wanted, RGB color?

 

 

Thank you for your help

Link to comment
Share on other sites

You could use this lisp to convert the color from rgb to OLE_color (not written by me)

  ;; Convert a list of RGB to TrueColor
 ;(RGBtoOLE_color '(118 118 118))
 (defun RGBtoOLE_color (RGB-codes / r g b)
   (setq r (lsh (car RGB-codes) 16))
   (setq g (lsh (cadr RGB-codes) )
   (setq b (caddr RGB-codes))
   (+ (+ r g) b)
 )

So just pop that into your code then you can call:

(vla-put-GraphicsWinLayoutBackgrndColor disp (RGBtoOLE_color '(40 40 40)))

Instead of what you have.

Link to comment
Share on other sites

You could use this lisp to convert the color from rgb to OLE_color (not written by me)

  ;; Convert a list of RGB to TrueColor
 ;(RGBtoOLE_color '(118 118 118))
 (defun RGBtoOLE_color (RGB-codes / r g b)
   (setq r (lsh (car RGB-codes) 16))
   (setq g (lsh (cadr RGB-codes) )
   (setq b (caddr RGB-codes))
   (+ (+ r g) b)
 )

So just pop that into your code then you can call:

(vla-put-GraphicsWinLayoutBackgrndColor disp (RGBtoOLE_color '(40 40 40)))

Instead of what you have.

 

Hello Commandobill,

 

How do I have to put the code into the lisp? I have tried it but it doesn't work.

I think I am doing something wrong.

 

Thank you

Link to comment
Share on other sites

you can go to Options > Display > Colors

on the 2D Model Space select Uniform COlor Background

on the Color go to True Color then type the RGB code from there which is 40,40,40

no need for a lisp

Link to comment
Share on other sites

you can go to Options > Display > Colors

on the 2D Model Space select Uniform COlor Background

on the Color go to True Color then type the RGB code from there which is 40,40,40

no need for a lisp

 

 

 

That's the problem, I can change this every time I start Autocad.

 

 

He doesn´t save my backgroundcolor after closing Autocad.

Link to comment
Share on other sites

Hello Commandobill,

 

How do I have to put the code into the lisp? I have tried it but it doesn't work.

I think I am doing something wrong.

 

Thank you

It worked on my PC, did you remember to setq disp first?

(setq disp (vla-get-display (vla-get-preferences (vlax-get-acad-object))))

Link to comment
Share on other sites

That's the problem, I can change this every time I start Autocad.

 

 

He doesn´t save my backgroundcolor after closing Autocad.

 

That would not be normal behavior, you have something resetting them.

Link to comment
Share on other sites

Using the code found here: http://cadpanacea.com/wp/?p=242

 

Change the color value in that lisp to a value of "2631720"

 

Put that code in your "acaddoc.lsp" file (append it or create a new one if needed - either way make sure it's located in the TOP support file search path)

Then run the command TBC to toggle between black and 40,40,40

 

Feel free to modify as needed.

Link to comment
Share on other sites

That would not be normal behavior, you have something resetting them.

 

Indeed, it's strange AutoCad doesn't save my background colors of my model and layout.

I can change the crosshair colors, block editor colors etc. That's no problem. It's only a problem with the background color in my model and layout.

Link to comment
Share on other sites

Sorry, I haven't read the whole thread, but are you using a default Autocad PROFILE, or have you saved one reflecting your preferences?

Link to comment
Share on other sites

Using the code found here: http://cadpanacea.com/wp/?p=242

 

Change the color value in that lisp to a value of "2631720"

 

Put that code in your "acaddoc.lsp" file (append it or create a new one if needed - either way make sure it's located in the TOP support file search path)

Then run the command TBC to toggle between black and 40,40,40

 

Feel free to modify as needed.

 

Thank you, Rkmcswain! :D

 

I'd copied the lisp and changed the color into 2631720. After that, I tried the TBC command and it worked.

I have changed also another part of the lisp. Because after I used the TBC command, the crosshair colors were also changed. They became black at the time my background was 40,40,40. And they became 40,40,40 at the time the color of the background was black.

 

They were not really visible.

 

I have changed the lisp into:

 

?(vl-load-com)
(defun c:TBC (/ pref col tm)
 (setq tm (getvar "tilemode"))
 (setq pref (vla-get-display
       (vla-get-Preferences
                 (vlax-get-acad-object)
              )
     )
 )
 (if (zerop tm)
   (setq cur (vla-get-graphicswinlayoutbackgrndcolor pref))
   (setq cur (vla-get-graphicswinmodelbackgrndcolor pref))
 )
 (setq col (vlax-variant-value
      (vlax-variant-change-type
        cur
        vlax-vblong
      )
    )
 )
 (if (not (or (eq col 0) (eq col 2631720)))
   (setq col 0)
 )
 (cond ((zerop tm)
 (vla-put-graphicswinlayoutbackgrndcolor
     pref
     (vlax-make-variant (abs (- col 2631720)) vlax-vblong)
 )
 (vla-put-layoutcrosshaircolor
     pref
     (vlax-make-variant (abs (- col 16777215)) vlax-vblong)
 )
)
(t
 (vla-put-graphicswinmodelbackgrndcolor
     pref
     (vlax-make-variant (abs (- col 2631720)) vlax-vblong)
 )
 (vla-put-modelcrosshaircolor
     pref
     (vlax-make-variant (abs (- col 16777215)) vlax-vblong)
 )
)
 )
 (vlax-release-object pref)
 (princ)
)

 

Thanks a lot!

 

 

I only need to create a new/ other acaddoc.lsp because I'm not authorized to change the original.

Link to comment
Share on other sites

Sorry, I haven't read the whole thread, but are you using a default Autocad PROFILE, or have you saved one reflecting your preferences?

 

Hello Dadgad,

 

I'm drawing heating, ventilation, airco and cooling (HVAC) installations into a floorplan of a building.

Because of that, I need to draw with an application which is created to draw this kind of installations with AutoCad.

This program has got his own profile. I am using this profile.

 

But my preferences are saved in my workspace. I do not have my own profile

Link to comment
Share on other sites

It sounds like rk and friends have just about got you back in the game, cool! :beer:

 

I was just curious, as I believe that your display color settings are defined components of your Profile, as opposed to your Workspace settings.

This sort of followed from SLW's observation that something was changing your settings.

I thought it was worth clarifying, and glad you are coming to grips with it. :)

Edited by Dadgad
Link to comment
Share on other sites

I only need to create a new/ other acaddoc.lsp because I'm not authorized to change the original.

 

Keep in mind AutoCAD will only load the first acaddoc.lsp it finds. You could copy the original and add to it making sure it's in a location that will be loaded first. Since you're not using your own profile that may be tricky. You may need to look at other ways to have it load.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...