Switch Backgroundcolor

Switch Backgroundcolor

C.Utzinger
Collaborator Collaborator
881 Views
2 Replies
Message 1 of 3

Switch Backgroundcolor

C.Utzinger
Collaborator
Collaborator

Hi

 

I have this wonderful code for switching the Backgroundcolor between black and grey:

 

(defun c:SWITCH_BACKCOLOR ( /); ANZEIGE )
  (vl-load-com)
  (setq Anzeige(vla-get-Display(vla-get-Preferences(vla-get-application(vlax-get-acad-object)))))
  (if (= (vlax-variant-value(vlax-variant-change-type(vla-get-GraphicsWinModelBackgrndColor ANZEIGE) vlax-vbLong))0)
    (progn
      (vla-put-GraphicsWinModelBackgrndColor ANZEIGE 6710886)
      (princ "\nHintergrund Modellbereich auf -grau- gesetzt")
    )
    (progn
      (vla-put-GraphicsWinModelBackgrndColor ANZEIGE 0)
      (princ "\nHintergrund Modellbereich auf -schwarz- gesetzt")
    )  
  )
  (princ)
)  

 

But i'm looking for a code witch saves the original Color (for example blue) and turns back to this after i finish witch the grey one.

 

Please help...

0 Likes
Accepted solutions (1)
882 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

It depends.

 

Most simple solution could be like this.

 

(vl-load-com)

(defun c:SWITCH_BACKCOLOR  (/ ANZEIGE cbc)
  
  (setq Anzeige (vla-get-Display
                  (vla-get-Preferences
                    (vla-get-application (vlax-get-acad-object))))
        cbc (vlax-variant-value
              (vlax-variant-change-type
                (vla-get-GraphicsWinModelBackgrndColor ANZEIGE)
                vlax-vbLong)))
  (if (or (not *switch_backcolor-original*)
          (= *switch_backcolor-original* cbc)
          )
    (progn
      (setq *switch_backcolor-original* cbc)
      (vla-put-GraphicsWinModelBackgrndColor ANZEIGE 6710886)
      (princ "\nHintergrund Modellbereich auf -grau- gesetzt"))
    (progn
      (vla-put-GraphicsWinModelBackgrndColor ANZEIGE *switch_backcolor-original*)
      (princ "\nHintergrund Modellbereich auf -ORIGINAL- gesetzt")))
  (princ)
)

 

But. If the user turns off AutoCAD with temp color on, then the original color is lost.

 

... solution I can imagine is that we can export the original number to *.txt file. This will be exported once when the file does not exist and when the current color is different than exported original or your temp color (meaning in case that user changed the setting on purpose)

 

Then you need to add one line to ACADDOC.lsp to reset a background on start up.

 

Or... someone else will figure out something easier.

Message 3 of 3

C.Utzinger
Collaborator
Collaborator

HI

 

The first Option is enough for me. Thank you!!!

 

 

Kind Regards

 

Christian

0 Likes