System Variable for Crosshair Color

System Variable for Crosshair Color

Anonymous
Not applicable
3,382 Views
19 Replies
Message 1 of 20

System Variable for Crosshair Color

Anonymous
Not applicable

Hello,

I want to write a lisp for "Change Crosshair's Color to Color number...: ", but I can't find right System Variable.

I know, that CURSORSIZE  is responsible for how long are extended lines of CrossHair.

How to get out of this problem? Please, help.

0 Likes
3,383 Views
19 Replies
Replies (19)
Message 2 of 20

hmsilva
Mentor
Mentor

Unfortunately, there is no System Variable to change Crosshair Color.

You'll have to set ModelCrosshairColor property at display object.

See this Jeff Mishler's code

 

Henrique

EESignature

0 Likes
Message 3 of 20

Anonymous
Not applicable

or, from autodesk help:

 

(vl-load-com)
(defun c:Example_ModelCrossHairColor()
    ;; This example returns the current setting of
    ;; Model space CrossHairColor. It then changes the value, and
    ;; finally resets the value back to the original setting.
    (setq acadObj (vlax-get-acad-object))
    (setq preferences (vla-get-Preferences acadObj))
  
    ;; Get the Display preferences object
    (setq ACADPref (vla-get-Display preferences))
    
    ;; Retrieve the current CrossHairColor value
    (setq currCrossHairColor (vlax-variant-change-type (vla-get-ModelCrosshairColor ACADPref) vlax-vbLong))
    (alert (strcat "The current value for the model space CrossHairColor is " (itoa (vlax-variant-value currCrossHairColor))))
    
    ;; Change the value for CrossHairColor
    (vla-put-ModelCrosshairColor ACADPref (vlax-make-variant acGreen 19))
    (setq newValue (vlax-variant-change-type (vla-get-ModelCrosshairColor ACADPref) vlax-vbLong))
    (alert (strcat "The new value for CrossHairColor is " (itoa (vlax-variant-value newValue))))
    
    ;; Reset CrossHairColor to its original value
    (vla-put-ModelCrosshairColor ACADPref (vlax-variant-change-type currCrossHairColor 19)) 
    (alert (strcat "The CrossHairColor value is reset to " (itoa (vlax-variant-value currCrossHairColor))))

 

dicra

0 Likes
Message 4 of 20

Anonymous
Not applicable

@dicra: Your code I save as .lsp file and I load it by APPLOAD, but it don't changes Crosshair's color.

Why it dones't work?

 

@hmsilva: 

I wrote lisp using your code

;CCCH = Color CrossHair
(defun c:CCCH
 (set_xhair_clr color)
 (setq color (getint "\nType the value to set CrossHair's color [1/2/3/4/5/6/7]: "))
  set_xhair_clr (color)
)

; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/crosshairs-color-system-variable/m-p/1481297#M196118 ; *Jeff Mishler (defun set_xhair_clr (color) (cond ((eq color 1)(setq color 255)) ((eq color 2)(setq color 65535)) ((eq color 3)(setq color 65280)) ((eq color 4)(setq color 16776960)) ((eq color 5)(setq color 16711680)) ((eq color 6)(setq color 16711935)) ((eq color 7)(setq color 16777215)) (t(setq color 1)) ) (vla-put-ModelCrosshairColor (vla-get-display (vla-get-Preferences (vlax-get-acad-object) ) ) color ) ) ;Command: CCCH ; error: too few arguments

 But there is error: too few arguments.

 

What is bad?

 

0 Likes
Message 5 of 20

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:

 But there is error: too few arguments.

 

What is bad?

 

You are missing the arguments/variable list for the defun expression, hence set_xhair_clr & color are being interpreted as arguments required by the function.

 

Perhaps try the following code instead:

 

(defun c:ccch ( / c )
    (if (setq c (acad_colordlg 7 nil))
        (vla-put-modelcrosshaircolor
            (vla-get-display (vla-get-preferences (vlax-get-acad-object)))
            (LM:ACI->OLE c)
        )
    )
    (princ)
)

;; ACI -> OLE  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->OLE ( c )
    (apply 'LM:RGB->OLE (LM:ACI->RGB c))
)

;; RGB -> OLE  -  Lee Mac
;; Args: r,g,b - [int] Red, Green, Blue values

(defun LM:RGB->OLE ( r g b )
    (logior (fix r) (lsh (fix g) 8) (lsh (fix b) 16))
)

;; ACI -> RGB  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->RGB ( c / o r )
    (if (setq o (vla-getinterfaceobject (LM:acapp) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
        (progn
            (setq r
                (vl-catch-all-apply
                   '(lambda ( )
                        (vla-put-colorindex o c)
                        (list (vla-get-red o) (vla-get-green o) (vla-get-blue o))
                    )
                )
            )
            (vlax-release-object o)
            (if (vl-catch-all-error-p r)
                (prompt (strcat "\nError: " (vl-catch-all-error-message r)))
                r
            )
        )
    )
)

;; Application Object  -  Lee Mac
;; Returns the VLA Application Object

(defun LM:acapp nil
    (eval (list 'defun 'LM:acapp 'nil (vlax-get-acad-object)))
    (LM:acapp)
)

(vl-load-com) (princ)

 

Colour conversion functions are from my site here.

 

Message 6 of 20

hmsilva
Mentor
Mentor

To call Jeff Mishler's code, try

 

;CCCH = Color CrossHair
(defun c:CCCH ( / color flag)
  (setq flag t)
  (while flag
    (initget 6)
    (setq color (getint "\nType the value to set CrossHair's color [1/2/3/4/5/6/7]: "))
    (cond ((and (= 'INT (type color))
                (< 0 color 8)
           )
           (set_xhair_clr color)
           (setq flag nil)
          )
          ((and (= 'INT (type color))
                (not (< 0 color 8))
           )
           (princ "\nColor value, must be from 1 to 7...")
          )
          ((not color)
           (princ "\nExiting...")
           (setq flag nil)
          )
    )
  )
  (princ)
)


; http://forums.autodesk.com/t5/visual-lisp-autolisp?-and-general/crosshairs-color-system-variable/m-p/?1481297#M196118
; by Jeff Mishler
(defun set_xhair_clr (color)
(cond ((eq color 1)(setq color 255))
((eq color 2)(setq color 65535))
((eq color 3)(setq color 65280))
((eq color 4)(setq color 16776960))
((eq color 5)(setq color 16711680))
((eq color 6)(setq color 16711935))
((eq color 7)(setq color 16777215))
(t(setq color 1))
)
(vla-put-ModelCrosshairColor
(vla-get-display
(vla-get-Preferences
(vlax-get-acad-object)
)
)
color
)
)

 

Henrique

EESignature

0 Likes
Message 7 of 20

gpcattaneo
Advocate
Advocate

Also...

 

(defun c:ccch ( / c )
    (if (setq c (acad_colordlg 7 nil))
        (setenv "XhairPickboxEtc" (itoa (LM:ACI->OLE c)))
    )
    (princ)
)

 

Message 8 of 20

Lee_Mac
Advisor
Advisor
gpcattaneo wrote:

Also...

 

(defun c:ccch ( / c )
    (if (setq c (acad_colordlg 7 nil))
        (setenv "XhairPickboxEtc" (itoa (LM:ACI->OLE c)))
    )
    (princ)
)

 

 

Well found GP - I was looking for that registry key before posting! Smiley Happy

0 Likes
Message 9 of 20

Anonymous
Not applicable

Lee Mac, your lisp is something what I dreamed about. Great respect.

But even more I would like lisp for "Change Color of selected Objects with the DialogBox 'Select Color'".

So it would be something like you just did for the CrossHair, but it would be for Objects.

 

Soon for a long time I wanted a lisp for it. When I had to change the colour of some Object, I had to go in the Properties Palette (Ctrl+1, remember)

and there I clicked in specified cell and exclusively in this moment I could change its color.

And imagine how much time I wasted this way ... Just because I hadn't possibility to change selected Objects' color with help of DialogBox 'Select Color'.

 

So here is my request: Could you write such lisp?

 

0 Likes
Message 10 of 20

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:

Lee Mac, your lisp is something what I dreamed about. Great respect.

 

Thank you damian.

 

damian.wrobel wrote:

But even more I would like lisp for "Change Color of selected Objects with the DialogBox 'Select Color'".

So it would be something like you just did for the CrossHair, but it would be for Objects.

 

Soon for a long time I wanted a lisp for it. When I had to change the colour of some Object, I had to go in the Properties Palette (Ctrl+1, remember)

and there I clicked in specified cell and exclusively in this moment I could change its color.

 

Such a program could quite easily be written, but I see no need for the program -

 

Why not make a selection of objects & simply use the Object Colour drop-down?

 

cecolor.png

0 Likes
Message 11 of 20

Anonymous
Not applicable

First of all, I don't use Ribbon. I use only MenuBar (I set System Variable called MENUBAR to 1). Just in case I wrote lisp

(DEFUN C:RB  () (COMMAND "_RIBBON"))
(DEFUN C:RBB () (COMMAND "_RIBBONCLOSE"))

 to quickly open and close Ribbon if needed. I don't want to have to have Ribbon opened specially for that Color Tab (what is it called? Color icon?)...

 

The second thing is, I love to use keyboard. It saves time. I would rather press CRR, Enter to get DialogBox with Color Palette and have this whole Palette befor my eyes than to ride the mouse to the Properties Tab, and go into the cell with the colors, or to this icon which's screen you attached in your last post.

 

So it depends on who uses AUtoCad. Every man has his own preferences.

 

 

0 Likes
Message 12 of 20

Anonymous
Not applicable

First of all, I don't use Ribbon. I use only MenuBar (I set System Variable called MENUBAR to 1). Just in case I wrote lisp

(DEFUN C:RB  () (COMMAND "_RIBBON"))
(DEFUN C:RBB () (COMMAND "_RIBBONCLOSE"))

 to quickly open and close Ribbon if needed. I don't want to have to have Ribbon opened specially for that Color Tab (what is it called? Color icon?)...

 

The second thing is, I love to use keyboard. It saves time. I would rather press CRR, Enter to get DialogBox with Color Palette and have this whole Palette befor my eyes than to ride the mouse to the Properties Tab, and go into the cell with the colors, or to this icon which's screen you attached in your last post.

 

So it depends on who uses AutoCad. Every man has his own preferences.

 

 ;-----------

I'm sorry, there was some strange error and in order to pulish my post I clicked once, than second time to the "Post Button" and it is posted two times. But I don't know how to delete one of my messages.

 

0 Likes
Message 13 of 20

gpcattaneo
Advocate
Advocate

  Lee_Mac wrote: 

  Well found GP... 


 
Hi Lee, your LM:RGB/ACI/OLE functions are fantastic. Smiley Happy

 

0 Likes
Message 14 of 20

Anonymous
Not applicable

It is so easy to write lisp for "Change Color of selected Objects via DialogBox"? Not for me 😉

 

I tried to do it and here is what I did:

; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/system-variable-for-crosshair-color/td-p/5480926
; On ground of the lisp whichs author is gpcattaneo
; Originally it was CCCH

; CCOBJDIA = Change Color of selected OBJects via DIAlogbox
(defun c:CCOBJDIA ( / c )
;    (if 
        (setq c (acad_colordlg 7 nil))
;;;; Beginnig od part by DW:
        (setq zbior (ssget))
        (command "_CHANGE"
         zbior ""
         "_P"
         "_C"
          c
        ); command
;;;; End of part by DW ;;;;;;
;        (setenv "XhairPickboxEtc" (itoa (LM:ACI->OLE c)))
;    ); if
;; I don't need 'if' (at least I think so)
    (princ)
); defun

 

But the result is, the Color Palette is opened, I select a Color, but nothing happens.

The CHANGE command  probably is even not loaded...

There are not serious errors, because this lisp is loaded via APPLOAD without error prompts in CommandLine.

 

What I did wrong and why it doesn't work as I suspected?

 

 

0 Likes
Message 15 of 20

Anonymous
Not applicable

I changed appearance of this lisp a little bit and added second lisp. The difference between them is, one uses 'itoa' and the second doesn't.

 

; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/system-variable-for-crosshair-color/td-p/5480926
; On ground of the lisp whichs author is gpcattaneo
; Originally it was CCCH

; CCOBJDIA = Change Color of selected OBJects via DIAlogbox
(defun c:CCOBJDIA
 ( / ClrFromDia ClrAsString)
;    (if 
        (setq ClrFromDia (acad_colordlg 7 1))
        (setq ClrAsString (itoa ClrFromDia))
;;;; Beginnig od part by DW:
        (setq zbior (ssget))
        (command "_CHANGE"
         zbior ""
         "_P"
         "_C"
         ClrFromDia
;         ClrAsString
        ); command
;;;; End of part by DW ;;;;;;
;        (setenv "XhairPickboxEtc" (itoa (LM:ACI->OLE c)))
;    ); if
    (princ)
); defun

;----------

; CCOBJDIA = Change Color of selected OBJects via DIAlogbox
(defun c:CCOBJDIA2
 ( / ClrFromDia ClrAsString)
;    (if 
        (setq ClrFromDia (acad_colordlg 7 1))
;        (setq ClrAsString (itoa ClrFromDia))
;;;; Beginnig od part by DW:
        (setq zbior (ssget))
        (command "_CHANGE"
         zbior ""
         "_P"
         "_C"
         ClrFromDia
;         ClrAsString
        ); command
;;;; End of part by DW ;;;;;;
;        (setenv "XhairPickboxEtc" (itoa (LM:ACI->OLE c)))
;    ); if
    (princ)
); defun

 I don't understand, why both my lisps don't work... I searched for the lisps with 'acad_colordlg' and I found something interesting.

Here it is. It is a lisp which creates new Layer. The user is asked for entering name for the new Layer, and he chooses new Layer's color via DialogBox!

I proof, it works. And in this lisp there is no 'itoa'.

 

So what's wrong with my lisps?

0 Likes
Message 16 of 20

gpcattaneo
Advocate
Advocate

Try this:

 

(defun c:CCOBJDIA ( / ClrFromDia zbior)
    (setq ClrFromDia (itoa (acad_colordlg 7 1)))
    (setq zbior (ssget))
    (command "_CHANGE" zbior "" "_P" "_C" ClrFromDia "")
    (princ)
)

 

0 Likes
Message 17 of 20

Anonymous
Not applicable

It's great, thanks!

But I would like to switch (vahnge) order of the prompts so first will be "Select objects: " and DialogBox with Color Palette will be the second one.

And I don't know how to do it.
Maybe I should use the "while" function?

0 Likes
Message 18 of 20

gpcattaneo
Advocate
Advocate

Maybe...

 

533.gif

 

 

Message 19 of 20

Anonymous
Not applicable

Thank you. I thought about it before I post, but I didn't believe it might be working.

I forgot that before '(setq zbior (ssget))' there is a prompt "Select objects: ".

I thought it will not be prompted.

 

By the way, gpcattaneo's lisp for "Change CrossHair Color via DialogBox" works very good, so on ground of it I wanted to write lisp for "Change Background Color via DialogBox".

On http://www.afralisp.net/archive/lisp/enviro.htm I found, that the good expression is "Background".

So I thought, that in gpcattaneo's lisp I shoul change "XhairPickboxEtc" to "Background".

And I did so. Here is this lisp:

 

 

; Displays ColorPalette, but doesn't apply the chosen color
; to the BackGround color.

; http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/system-variable-for-crosshair-color/td-p/5480926

; On ground of lisp "Change CrossHair Color via DialogBox" by gpcattaneo
; Originally, there was CCCH

; CCBGGP = Change Color BackGround GPcattaneo
(defun c:CCBGGP ( / c )
    (if (setq c (acad_colordlg 7 nil))
        (setenv "Background" (itoa (LM:ACI->OLE c)))
    )
    (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; by Lee Mac ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; http://lee-mac.com/colourconversion.html ;;;;;;;;;;;;;;;
;;;; Colour Conversion Functions              ;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ACI -> OLE  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->OLE ( c )
    (apply 'LM:RGB->OLE (LM:ACI->RGB c))
)

;; RGB -> OLE  -  Lee Mac
;; Args: r,g,b - [int] Red, Green, Blue values

(defun LM:RGB->OLE ( r g b )
    (logior (fix r) (lsh (fix g) 8) (lsh (fix b) 16))
)

;; ACI -> RGB  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->RGB ( c / o r )
    (if (setq o (vla-getinterfaceobject (LM:acapp) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
        (progn
            (setq r
                (vl-catch-all-apply
                   '(lambda ( )
                        (vla-put-colorindex o c)
                        (list (vla-get-red o) (vla-get-green o) (vla-get-blue o))
                    )
                )
            )
            (vlax-release-object o)
            (if (vl-catch-all-error-p r)
                (prompt (strcat "\nError: " (vl-catch-all-error-message r)))
                r
            )
        )
    )
)

;; Application Object  -  Lee Mac
;; Returns the VLA Application Object

(defun LM:acapp nil
    (eval (list 'defun 'LM:acapp 'nil (vlax-get-acad-object)))
    (LM:acapp)
)

(vl-load-com) (princ)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; CCBLGGP = Change Color Layout BackGround GPcattaneo
(defun c:CCLBGGP ( / c )
    (if (setq c (acad_colordlg 7 nil))
        (setenv "Layout background" (itoa (LM:ACI->OLE c)))
    )
    (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; by Lee Mac ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; http://lee-mac.com/colourconversion.html ;;;;;;;;;;;;;;;
;;;; Colour Conversion Functions              ;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ACI -> OLE  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->OLE ( c )
    (apply 'LM:RGB->OLE (LM:ACI->RGB c))
)

;; RGB -> OLE  -  Lee Mac
;; Args: r,g,b - [int] Red, Green, Blue values

(defun LM:RGB->OLE ( r g b )
    (logior (fix r) (lsh (fix g) 8) (lsh (fix b) 16))
)

;; ACI -> RGB  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->RGB ( c / o r )
    (if (setq o (vla-getinterfaceobject (LM:acapp) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
        (progn
            (setq r
                (vl-catch-all-apply
                   '(lambda ( )
                        (vla-put-colorindex o c)
                        (list (vla-get-red o) (vla-get-green o) (vla-get-blue o))
                    )
                )
            )
            (vlax-release-object o)
            (if (vl-catch-all-error-p r)
                (prompt (strcat "\nError: " (vl-catch-all-error-message r)))
                r
            )
        )
    )
)

;; Application Object  -  Lee Mac
;; Returns the VLA Application Object

(defun LM:acapp nil
    (eval (list 'defun 'LM:acapp 'nil (vlax-get-acad-object)))
    (LM:acapp)
)

(vl-load-com) (princ)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; CCLCHGP = Change Color Layout Crosshair GPcattaneo
(defun c:CCLCHGP ( / c )
    (if (setq c (acad_colordlg 7 nil))
        (setenv "LayoutXhairPickboxEtc" (itoa (LM:ACI->OLE c)))
    )
    (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;; by Lee Mac ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; http://lee-mac.com/colourconversion.html ;;;;;;;;;;;;;;;
;;;; Colour Conversion Functions              ;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ACI -> OLE  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->OLE ( c )
    (apply 'LM:RGB->OLE (LM:ACI->RGB c))
)

;; RGB -> OLE  -  Lee Mac
;; Args: r,g,b - [int] Red, Green, Blue values

(defun LM:RGB->OLE ( r g b )
    (logior (fix r) (lsh (fix g) 8) (lsh (fix b) 16))
)

;; ACI -> RGB  -  Lee Mac
;; Args: c - [int] ACI (AutoCAD Colour Index) Colour (1<=c<=255)

(defun LM:ACI->RGB ( c / o r )
    (if (setq o (vla-getinterfaceobject (LM:acapp) (strcat "autocad.accmcolor." (substr (getvar 'acadver) 1 2))))
        (progn
            (setq r
                (vl-catch-all-apply
                   '(lambda ( )
                        (vla-put-colorindex o c)
                        (list (vla-get-red o) (vla-get-green o) (vla-get-blue o))
                    )
                )
            )
            (vlax-release-object o)
            (if (vl-catch-all-error-p r)
                (prompt (strcat "\nError: " (vl-catch-all-error-message r)))
                r
            )
        )
    )
)

;; Application Object  -  Lee Mac
;; Returns the VLA Application Object

(defun LM:acapp nil
    (eval (list 'defun 'LM:acapp 'nil (vlax-get-acad-object)))
    (LM:acapp)
)

(vl-load-com) (princ)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

But it doesn't work.

Can you tell me why?

 

Generally, I will be write such lisp for "Layout background", "XhairPickboxEtc", too.

0 Likes
Message 20 of 20

Lee_Mac
Advisor
Advisor
gpcattaneo wrote:
Lee_Mac wrote

  Well found GP... 

Hi Lee, your LM:RGB/ACI/OLE functions are fantastic. Smiley Happy

 

Thanks GP! Smiley Happy

0 Likes