Author Topic: please fix this code..osmode reactor  (Read 2527 times)

0 Members and 1 Guest are viewing this topic.

paul_s

  • Guest
please fix this code..osmode reactor
« on: July 22, 2009, 09:20:33 AM »
Hello,

I need help with this code. What it does is that it changes the color of the
crosshairs to red when osnaps are "on" then back to white if there are "no"
osnaps or if "turned off" (F3 function key).

The problem is when I am in a middle of a command (ex. line, move) and I hit
the function key F3. It changes the color of the crosshair like its suppose to but
it cancels the command. What am I doing wrong or what I am not doing?

I'd like this code to work even when I am in a middle of a command..transparently.


Code: [Select]
;Reactor for osmode
(VLR-SysVar-Reactor nil'((:VLR-sysVarChanged . SysVarChanged)))
               

(defun SysVarChanged (calling-reactor SysVarChangeInfo /)
(if (wcmatch (strcase (nth 0 SysVarChangeInfo) T) "osmode")
(progn
(setq AcadObj (vlax-get-acad-object)
      AcadDoc (vla-get-ActiveDocument AcaObj)
      AcadDsp (vla-get-Display (vla-get-Preferences AcaObj))
      Cursnap (getvar "osmode")
      Curspac (getvar "tilemode")
)

(if (= Cursnap 0)(progn
                 (if (= Curspac 0) (vla-put-LayoutCrosshairColor AcaDsp  (vlax-make-variant 16777215 vlax-vbLong)))
                 (vla-put-ModelCrosshairColor AcaDsp  (vlax-make-variant 16777215 vlax-vbLong))
                 )
)
(if (> Cursnap 0)(progn
                 (if (= Curspac 0) (vla-put-LayoutCrosshairColor AcaDsp  (vlax-make-variant 255 vlax-vbLong)))
                 (vla-put-ModelCrosshairColor AcaDsp  (vlax-make-variant 255 vlax-vbLong))
                 )
)
(if (> Cursnap 16384)(progn
                 (if (= Curspac 0) (vla-put-LayoutCrosshairColor AcaDsp  (vlax-make-variant 16777215 vlax-vbLong)))
                 (vla-put-ModelCrosshairColor AcaDsp  (vlax-make-variant 16777215 vlax-vbLong))
                 )
)
)
)
)
<edit: added code tags>
« Last Edit: July 22, 2009, 09:29:53 AM by CAB »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: please fix this code..osmode reactor
« Reply #1 on: July 22, 2009, 10:49:08 AM »
Paul,
Changed the code & corrected error in var names AcaDsp should be AcadDsp  etc.
 But I think the reactor cancels the COMMAND when the display is reset.

Also the white is not a good choice for me in paper space as my background is white.
So needs mode code to test for white background and set to black in that case. (not included in this example)
Code: [Select]
;;Reactor for osmode  CAB's version
;;  if the reactor doesn't exist then create it
(or *SysVar (setq *SysVar (VLR-SysVar-Reactor nil '((:VLR-sysVarChanged . SysVarChanged)))))
;;  If the reactor has been disables then inable it
(and *SysVar (not (vlr-added-p *SysVar)) (vlr-add *SysVar))


(defun SysVarChanged (calling-reactor SysVarChangeInfo / AcadDsp)
  (if (eq (strcase (nth 0 SysVarChangeInfo)) "OSMODE")
    (progn
      (setq AcadDsp (vla-get-Display (vla-get-Preferences (vlax-get-acad-object))))
      (if (< 0 (setq cur_mode (getvar "osmode")) 16383)
        (progn ; On so set to RED
          (vla-put-LayoutCrosshairColor AcadDsp 215)
          (vla-put-ModelCrosshairColor AcadDsp 215)
        )
        (progn ; OFF so set tot WHITE
          (vla-put-LayoutCrosshairColor AcadDsp 16777215)
          (vla-put-ModelCrosshairColor AcadDsp 16777215)
        )
      )
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

paul_s

  • Guest
Re: please fix this code..osmode reactor
« Reply #2 on: July 22, 2009, 11:32:34 AM »
Cab,

Thank you for catching the mistakes. I guess
it just wont work transparently. Thank you for
looking at it.

Spike Wilbury

  • Guest
Re: please fix this code..osmode reactor
« Reply #3 on: July 22, 2009, 11:50:12 AM »
i did this routine long time ago, when i was in deep with the miserable reactors:

Code: [Select]
(vl-load-com)

(if (not this_dwg)
  (setq this_dwg
(vla-get-activedocument
   (vlax-get-acad-object))))

(defun lispWillStart  (reactor params)
  (setq current_osmode (vla-getvariable this_dwg "osmode")))

(defun lispEnded  (reactor params)
  (if current_osmode
    (vla-setvariable this_dwg "osmode" current_osmode))
  (setq current_osmode nil))

(defun lispCancelled  (reactor params)
  (if current_osmode
    (vla-setvariable this_dwg "osmode" current_osmode))
  (setq current_osmode nil))

(if (not osmode_reactor)
  (setq osmode_reactor
(vlr-lisp-reactor
   "osmode control"
   '((:vlr-lispWillStart . lispWillStart)
     (:vlr-lispEnded . lispEnded)
     (:vlr-lispCancelled . lispCancelled)))))

(defun C:TEST1 (/ pt)
  (setvar "osmode" 32)
  (if (setq pt (getpoint "\nSelect intersection: "))
    (command "_.point" pt))
  (princ))

(defun C:TEST2 (/ pt)
  (setvar "osmode" 1)
  (if (setq pt (getpoint "\nSelect endpoint: "))
    (command "_.point" pt))
  (princ))

(princ)

no idea if helps you.... the only thing i recall was to avoid the use or implementation of the sysvar reactors - only for reading some values and at the minimum.

le.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: please fix this code..osmode reactor
« Reply #4 on: July 22, 2009, 11:56:09 AM »
Code: [Select]
(vl-load-com)

(if (not this_dwg)
  (setq this_dwg
(vla-get-activedocument
   (vlax-get-acad-object))))

(defun lispWillStart  (reactor params)
  (setq current_osmode (vla-getvariable this_dwg "osmode")))

(defun lispEnded  (reactor params)
  (if current_osmode
    (vla-setvariable this_dwg "osmode" current_osmode))
  (setq current_osmode nil))

(defun lispCancelled  (reactor params)
  (if current_osmode
    (vla-setvariable this_dwg "osmode" current_osmode))
  (setq current_osmode nil))

(if (not osmode_reactor)
  (setq osmode_reactor
(vlr-lisp-reactor
   "osmode control"
   '((:vlr-lispWillStart . lispWillStart)
     (:vlr-lispEnded . lispEnded)
     (:vlr-lispCancelled . lispCancelled)))))

(defun C:TEST1 (/ pt)
  (setvar "osmode" 32)
  (if (setq pt (getpoint "\nSelect intersection: "))
    (command "_.point" pt))
  (princ))

(defun C:TEST2 (/ pt)
  (setvar "osmode" 1)
  (if (setq pt (getpoint "\nSelect endpoint: "))
    (command "_.point" pt))
  (princ))

(princ)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spike Wilbury

  • Guest
Re: please fix this code..osmode reactor
« Reply #5 on: July 22, 2009, 11:59:20 AM »
:-o

man... it's hard to make a translation my english is not at that level  :-P

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: please fix this code..osmode reactor
« Reply #6 on: July 22, 2009, 12:02:20 PM »
<Google Translator> Code quoted for the OP because the odds are pretty high you will delete it later today. </Google Translator>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Spike Wilbury

  • Guest
Re: please fix this code..osmode reactor
« Reply #7 on: July 22, 2009, 12:10:45 PM »
<Google Translator> Code quoted for the OP because the odds are pretty high you will delete it later today. </Google Translator>

oh, that's it.... i see.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: please fix this code..osmode reactor
« Reply #8 on: July 22, 2009, 02:50:18 PM »
This one deals with the White Paper space background, not model space though.
Code: [Select]
;;Reactor for osmode
;;  if the reactor doesn't exist then create it
(or *SysVar (setq *SysVar (VLR-SysVar-Reactor nil '((:VLR-sysVarChanged . SysVarChanged)))))
;;  If the reactor has been disables then inable it
(and *SysVar (not (vlr-added-p *SysVar)) (vlr-add *SysVar))


(defun SysVarChanged (calling-reactor SysVarChangeInfo / AcadDsp)
  (if (member (strcase (car SysVarChangeInfo)) '("OSMODE" "TILEMODE"))
    (progn
      (setq AcadDsp (vla-get-Display (vla-get-Preferences (vlax-get-acad-object))))
      (if (< 0 (setq cur_mode (getvar "osmode")) 16383)
        (progn ; On so set to RED
          (vla-put-LayoutCrosshairColor AcadDsp 215)
          (vla-put-ModelCrosshairColor AcadDsp 215)
        )
        (progn ; OFF so set to WHITE or Black if White background
          (if (eq (vlax-variant-value
                    (vlax-variant-change-type
                      (vla-get-graphicswinLayoutbackgrndcolor AcadDsp)vlax-vbLong))
                  16777215)
            (vla-put-LayoutCrosshairColor AcadDsp 0)
            (vla-put-LayoutCrosshairColor AcadDsp 16777215)
          )
          (if (eq (vlax-variant-value
                    (vlax-variant-change-type
                      (vla-get-graphicswinModelbackgrndcolor AcadDsp)vlax-vbLong))
                  16777215)
            (vla-put-ModelCrosshairColor AcadDsp 0)
            (vla-put-ModelCrosshairColor AcadDsp 16777215)
          )
        )
      )
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.