Author Topic: layer reactor help  (Read 12956 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
layer reactor help
« on: April 24, 2008, 02:09:03 PM »
i found this routine on here that alan (cab) had modified. can't remember where.
anyway, i was trying to set it up, just running some tests and i noticed that when i do anything (dimension, text, etc) it will put it on the desired layer perfectly, the only problem is then it screw something up with setting layers as current. i can (command line) create and/or set a layer and it will create it, but not set it as my current. the only way i could find to set a different layer was to pick it form the layer control pulldown.

any thoughts on how to correct this issue would be greatly appreciated. thanks.

here's the routine:

<old code removed, see code fix posted below.>
« Last Edit: April 25, 2008, 04:42:38 PM by CAB »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Andrea

  • Water Moccasin
  • Posts: 2372
Re: layer reactor help
« Reply #1 on: April 24, 2008, 03:46:37 PM »
I've found that the reactor never been removed..
maybe this can be added ?


This code will remove the reactor at the start...but maybe wil be better to put it at the END !?
Code: [Select]
(defun c:vlrc_command ()
(if *vlr-CWS (vlr-remove *vlr-CWS))
(if *vlr-CE (vlr-remove *vlr-CE))
(if *vlr-CC (vlr-remove *vlr-CC))
)


(defun C:VLR_COMMAND ()
 (vl-load-com)
 
;|-> addition to prevent multi-rector session   |;
(c:vlrc_command)
;| |;

....
 
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #2 on: April 24, 2008, 04:23:25 PM »
The routine was intended to apply the designated layer based on the command and then return the current layer to the one found before the command.
Did you want it to leave the layer used by the command current?
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #3 on: April 24, 2008, 04:30:49 PM »
Actually there was a newer version by 2 days.
http://www.theswamp.org/index.php?topic=21056.msg255892#msg255892
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: layer reactor help
« Reply #4 on: April 24, 2008, 09:31:21 PM »
The routine was intended to apply the designated layer based on the command and then return the current layer to the one found before the command.
Did you want it to leave the layer used by the command current?


oh no, it does exactly what i wanted, but it won't let you -layer set (or any other way except the layer control pulldown) after you have used it.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: layer reactor help
« Reply #5 on: April 24, 2008, 09:34:52 PM »

OK, I'll ask the question ..

Why are the Dims on a hidden2 layer ??
.. piqued my curiosity.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: layer reactor help
« Reply #6 on: April 24, 2008, 09:51:00 PM »

OK, I'll ask the question ..

Why are the Dims on a hidden2 layer ??
.. piqued my curiosity.

i was just playing around with it, i don't actually make my dim layer have a linetype.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: layer reactor help
« Reply #7 on: April 24, 2008, 09:54:57 PM »

OK, I'll ask the question ..

Why are the Dims on a hidden2 layer ??
.. piqued my curiosity.

i was just playing around with it, i don't actually make my dim layer have a linetype.

 :wink:
OK, I'll be quiet then ...  :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #8 on: April 24, 2008, 11:29:48 PM »
Works fine for me. I can use Layer or -layer at the command line. Should have no affect with the LAYER command.
What version of ACAD are you using?
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: layer reactor help
« Reply #9 on: April 24, 2008, 11:35:52 PM »
i've tried it in 6, 7 and 8
if i VLR_COMMAND_OFF then it will allow me to -layer set or however just fine, but then the reactor won't work again until i VLR_COMMAND.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #10 on: April 25, 2008, 12:02:32 AM »
I just tried it in 06 (as high as I can go) and -layer worked fine. :?

I'll be out until Friday afternoon.
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: layer reactor help
« Reply #11 on: April 25, 2008, 09:52:19 AM »
I just tried it in 06 (as high as I can go) and -layer worked fine. :?

I'll be out until Friday afternoon.


i don't get it. i even added in a line that would turn off the reactor after the first time it successfully fired (that worked) but i couldn't then get it to turn back on w/o typing "vlr_command".

it's something that is preventing me from setting layers with anything but the layer control pull down. it won't even set a newly created layer as current with -layer m.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #12 on: April 25, 2008, 04:00:02 PM »
If you turn off the layer reactor then you would need to use vlr_command at the command line to turn it back on.
What happens when you enter -layer at the command line? Do you get the prompt?
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: layer reactor help
« Reply #13 on: April 25, 2008, 04:05:52 PM »
If you turn off the layer reactor then you would need to use vlr_command at the command line to turn it back on.
What happens when you enter -layer at the command line? Do you get the prompt?

regardless of it being on or off, if i -layer it goes through all the motions and even says that whatever i set to is my current layer, but it is not.
if i turn the routine off vlr_command_off then everything works fine but then i have to vlr_command to get things working again, that' not really much of an advantage.
do you think it's some setvar that i have screwed up?
the thing about that is, i have the same issue on both my work & home computer and my home computer doesn't have near the settings (company standard settings) that my work computer?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #14 on: April 25, 2008, 04:40:52 PM »
Well I finally figured out the problem. And a solution.
Try this:
Code: [Select]
;  Modified by CAB 01.25.2008
;  Modified by CAB 04.25.2008 ; bug fix
; Sets the correct layer for certain commands.
; VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003

; Vlr Command is a function that will switch the active layer in a drawing.
; The reactor checks the command that is starting and if it recognizes it
; it will switch to a specified layer. If the layer doesn't exist it will
; create it with the color, linetype, and plottable setting provided.
; To load and run this program add the lines (load "vlr_command")(c:vlr_command)
; to your acaddoc.lsp or another autoloading lisp routine.

; CAB added error trap for layer creator
;     added layer restore at command exit
;;    added code to test loaded status
;;    added code to turn reactors Off & back On again
;;    added code for different layers per user or task
;;    NOTE: set var *user* to use different layers per user
;;    Fixed bug in end & cancel command layer reset

(defun C:VLR_COMMAND ()
  (vl-load-com)
  ;; Load only once, if already loaded reactivate it if inactive
  (and *vlr-CWS (not (vlr-added-p *vlr-CWS)) (vlr-add *vlr-CWS))
  (and *vlr-CE (not (vlr-added-p *vlr-CE)) (vlr-add *vlr-CE))
  (and *vlr-CC (not (vlr-added-p *vlr-CC)) (vlr-add *vlr-CC))
  (or *vlr-CWS
     (setq *vlr-CWS (vlr-command-reactor nil '((:vlr-commandwillstart . StartCommand)))))
  (or *vlr-CE
     (setq *vlr-CE (vlr-command-reactor nil '((:vlr-commandEnded . endCommand)))))
  (or *vlr-CC
     (setq *vlr-CC (vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand)))))
  (princ "\nLayer Reactor ON")
  (princ)
)

;;  Turn the reactors off
(defun C:VLR_COMMAND_OFF ()
  (and *vlr-CWS (vlr-added-p *vlr-CWS) (vlr-remove *vlr-CWS))
  (and *vlr-CE (vlr-added-p *vlr-CE) (vlr-remove *vlr-CE))
  (and *vlr-CC (vlr-added-p *vlr-CC) (vlr-remove *vlr-CC))
  (princ "\nLayer Reactor OFF")
  (princ)
)

(defun StartCommand (CALL CALLBACK / COMLAYLST)

  ;; Examples of Command vs Layer
  ;; List of corresponding      command layerName color linetype plottable
  ;; NOTE command names must be in Upper Case
  ;; NOTE: set var *user* to use different layers per user
  (cond
    ((and *user*(= (type *user*) 'STR)(= (strcase *user*) "DAN"))
     (setq *LayUpdt* t
      LtFname nil)
     (setq COMLAYLST
            (list
              (list "DIMANGULAR" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "DIMBASELINE" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "DIMCENTER" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "DIMCONTINUE" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "DIMDIAMETER" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "DIMLINEAR" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "DIMRADIUS" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "QDIM" "I_ANNO-DIMS" 14 "continuous" :vlax-true)
              (list "LEADER" "I_ANNO-NOTE" 11 "continuous" :vlax-true)
              (list "QLEADER" "I_ANNO-NOTE" 11 "continuous" :vlax-true)
              (list "DTEXT" "I_ANNO-NOTE" 11 "continuous" :vlax-true)
              (list "MTEXT" "I_ANNO-NOTE" 11 "continuous" :vlax-true)
              (list "TEXT" "I_ANNO-NOTE" 11 "continuous" :vlax-true)
              (list "BHATCH" "I-FIXT-7" 8 "continuous" :vlax-true)
              (list "HATCH" "I-FIXT-7" 8 "continuous" :vlax-true)
              (list "MVIEW" "Z-VIEWPORT" 7 "continuous" :vlax-false)
                    ; Add your own command layer lists here....
            )
     )
    )
    ((and *user*(= (type *user*) 'STR)(= (strcase *user*) "Future Use"))
     (setq COMLAYLST '())
    )
    ((and *usermode*(= (type *usermode*) 'STR)(= (strcase *usermode*) "CAB"))
     (setq *LayUpdt* nil
      LtFname "CAB2.lin")
     (setq COMLAYLST
            (list
              (list "DIMANGULAR"  "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMBASELINE" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMCENTER"   "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMCONTINUE" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMDIAMETER" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMLINEAR"   "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMRADIUS"   "S-DIM" 5 "continuous" :vlax-true)
              (list "QDIM"        "S-DIM" 5 "continuous" :vlax-true)
              (list "LEADER"      "A-DIM" 5 "continuous" :vlax-true)
              (list "QLEADER"     "A-DIM" 5 "continuous" :vlax-true)
              (list "DTEXT"       "A-TEXT" 2 "continuous" :vlax-true)
              (list "MTEXT"       "A-TEXT" 2 "continuous" :vlax-true)
              (list "TEXT"        "A-TEXT" 2 "continuous" :vlax-true)
              (list "BHATCH"      "A-HATCH" 8 "continuous" :vlax-true)
              (list "HATCH"       "A-HATCH" 8 "continuous" :vlax-true)
              (list "POINT"       "A-POINTS" 7 "continuous" :vlax-true)
              (list "XLINE"       "A-CONST-LINES" 9 "continuous" :vlax-true)
              (list "MVIEW"       "A-VIEWPORT" 7 "continuous" :vlax-false)
              (list "TABLE"       "A-TABLE" 2 "continuous" :vlax-true)
              (list "REVCLOUD"    "A-REVCLOUD" 7 "continuous" :vlax-true)
                    ; Add your own command layer lists here....
            )
     )
    )
    (t  ; default Layer Group
     (setq *LayUpdt* nil
      LtFname "CAB2.lin")
     (setq COMLAYLST
            (list
              (list "DIMANGULAR" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMBASELINE" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMCENTER" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMCONTINUE" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMDIAMETER" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMLINEAR" "S-DIM" 5 "continuous" :vlax-true)
              (list "DIMRADIUS" "S-DIM" 5 "continuous" :vlax-true)
              (list "QDIM" "S-DIM" 5 "continuous" :vlax-true)
              (list "LEADER" "A-DIM" 5 "continuous" :vlax-true)
              (list "QLEADER" "A-DIM" 5 "continuous" :vlax-true)
              (list "DTEXT" "A-TEXT" 2 "continuous" :vlax-true)
              (list "MTEXT" "A-TEXT" 2 "continuous" :vlax-true)
              (list "TEXT" "A-TEXT" 2 "continuous" :vlax-true)
              (list "BHATCH" "A-HATCH" 8 "continuous" :vlax-true)
              (list "HATCH" "A-HATCH" 8 "continuous" :vlax-true)
              (list "POINT" "A-POINTS" 7 "continuous" :vlax-true)
              (list "XLINE" "A-CONST-LINES" 9 "continuous" :vlax-true)
              (list "MVIEW" "A-VIEWPORT" 7 "continuous" :vlax-false)
              (list "TABLE" "A-TABLE" 2 "continuous" :vlax-true)
              (list "REVCLOUD" "A-REVCLOUD" 7 "continuous" :vlax-true)
                    ; Add your own command layer lists here....
            )
     )
    )
  )

  ;; Find the Command
  (if (setq N (assoc (strcase (car CALLBACK)) COMLAYLST))
    (progn
        ;;  save current layer, restore on exit of command
        (setq *Currentlayers* (cons (getvar "CLAYER") *Currentlayers*))
    ;;  make or update layer, then make current
    (if (make_layers (cadr N) (caddr N) (cadddr N) (car (cddddr N)))
      (vla-put-activelayer
        (vla-get-activedocument (vlax-get-acad-object))
        (vlax-ename->vla-object (tblobjname "LAYER" (cadr N)))
      )
    )
    )
    ;;  flag current layer so it is NOT restored on exit of command
    (setq *Currentlayers* (cons nil *Currentlayers*))
  )
  (princ)
)


;; Make layers using activeX
;; return t if sucessful else nil
(defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ fn result LtFname NewLay)
  (or *DOC* (setq *DOC* (vla-get-activedocument (vlax-get-acad-object))))
  (setq LAYSOBJ (vla-get-layers *DOC*))
  (if (tblobjname "layer" LAY_NAM) ; layer exist
    (setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
    (setq LAYOBJ (vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
    NewLay t)
  )
  ;;(setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
  (if (vl-catch-all-error-p LAYOBJ)
    (not (print (vl-catch-all-error-message LAYOBJ)))
    (progn
      (if (= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
        (progn ; can not change current layer so make something else current
        ;;  what if "0" is frozen?
          ;;  need to thaw it then restore old layer, and freeze if thawed.
          (setvar "clayer" "0")
        )
      )
      (vla-put-lock LAYOBJ :vlax-false)
      (vla-put-layeron LAYOBJ :vlax-true)
      (vla-put-freeze LAYOBJ :vlax-false)
     
      (if (or NewLay *LayUpdt*)  ; ok to update layer color, plot, LineType
          ;; ****************************************************************
        (progn   
          (if (tblobjname "ltype" LTYPE)
            (vla-put-linetype LAYOBJ LTYPE)
            (progn
              (setq LTYPESOBJ (vla-get-linetypes *DOC*))
              (if (and LtFname (/= LtFname "")
                     (setq fn (findfile LtFname)))
                 (vl-catch-all-apply '(lambda ( ) (vla-load LTYPESOBJ LTYPE fn)
                                              (setq result t)  ; true only if load susceded
                                            ))
              )
              (if (and (not result)
                    (setq fn (findfile (if (zerop (getvar "measurement")) "acad.lin" "acadiso.lin"))))
                (vl-catch-all-apply '(lambda ( ) (vla-load LTYPESOBJ LTYPE fn)
                                             (setq result t)  ; true only if load susceded
                                           ))
              )
              (vlax-release-object LTYPESOBJ)
              (and result (vla-put-linetype LAYOBJ LTYPE))
             )
          )
          ;; ****************************************************************
          (vla-put-color LAYOBJ COLOR)
          (vla-put-plottable LAYOBJ PLOTL)
        )
      ) ; end if (or NewLay *LayUpdt*)
      t
    )
  )
)

;;  Restore curent layer
(defun endCommand (CALL CALLBACK)
  (if *Currentlayers*
    (if (car *Currentlayers*)
      (progn
        (vla-put-lock
          (vla-item
            (vla-get-layers
              (vla-get-activedocument (vlax-get-acad-object)))
            (car *Currentlayers*)
          )
          :vlax-false
        )
        (setvar "CLAYER" (car *Currentlayers*))
      )
    )
  )
  (setq *Currentlayers* (cdr *Currentlayers*))
)


;;  Restore curent layer
(defun cancelCommand (CALL CALLBACK)
  (if *Currentlayers*
    (if (car *Currentlayers*)
      (progn
        (vla-put-lock
          (vla-item
            (vla-get-layers
              (vla-get-activedocument (vlax-get-acad-object)))
            (car *Currentlayers*)
          )
          :vlax-false
        )
        (setvar "CLAYER" (car *Currentlayers*))
      )
    )
  )
  (setq *Currentlayers* (cdr *Currentlayers*))
)
(princ)

;------------------<The End>--------------------------
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: layer reactor help
« Reply #15 on: April 25, 2008, 05:05:40 PM »
I didn't wade through the code, I'm sure it's good, but the problem sounds like the reactor is firing no matter what command is ran (which it should), and as such is setting the layer back to the on before the command was invoked (even if the command is not listed in the command list, which I think is not a desired result).  It looks like Alan got it though by the code revision index.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #16 on: April 25, 2008, 05:33:55 PM »
Good catch Tim, that's exactly what was happening.  8-)
The revised code should have fixed the problem
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: layer reactor help
« Reply #17 on: April 25, 2008, 10:11:12 PM »
SUCCESS!!!

you are truely my hero!
thank you thank you thank you!
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

mig20

  • Guest
Re: layer reactor help
« Reply #18 on: September 13, 2013, 01:13:37 PM »
I know I'm resurrecting an old thread but it ALMOST does exactly what I'm looking for.

I regularly work between four different CAD standards with their own layer sets, and I use Lee Mac's LayerDirector with layer lists for each standard but have to reload the right one manually when I switch projects.

It's not the end of the world having to do this but I'd like to roll it out to other users to help enforce the correct layer usage, however I'd like it automated so they don't have to load the LayerDirector themselves.

My first thought was a variable in the drawing to identify the standard to be used (I thought PROJECTNAME would do it) and then LayerDirector would know what layer list to use, or set a project search path load the correct lisp.

Upon searching to see if it had been done already, I came across the code in this thread which pretty much does it for multiple users so I am wondering if a modification and setting an in-drawing variable would work for me?

Any advice or assistance would very welcome!

thanks :)




Well I finally figured out the problem. And a solution.
Try this:
Code: [Select]
;  ----------------

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: layer reactor help
« Reply #19 on: September 13, 2013, 03:52:35 PM »
Welcome to the Swamp. 8)
The routine can be modified to use quite a few methods of detection.
Global Variable
Black Board Variable
Drawing name
Layers already in use
Text file with Drawing name

just to name a few.

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.

mig20

  • Guest
Re: layer reactor help
« Reply #20 on: September 16, 2013, 01:01:18 PM »
Welcome to the Swamp. 8)
The routine can be modified to use quite a few methods of detection.
Global Variable
Black Board Variable
Drawing name
Layers already in use
Text file with Drawing name

just to name a few.

Thanks for the welcome, and the pointers CAB, i'll investigate those further and see what I come up with  ;-)