woodman78 Posted May 18, 2011 Share Posted May 18, 2011 I am using Leemac's Layer Director and it is brilliant. I have in loaded in the acaddoc.lsp. The problem is that for some on our system the reactor gets enabled when they open a drawing and for others it gets disabled. Is there any way around this? ;;-------------------=={ Layer Director }==-------------------;; ;; ;; ;; Uses a command reactor to automatically set the layer ;; ;; upon the user invoking certain commands. ;; ;; ;; ;; Layer settings are stored in the list at the top of the ;; ;; program. The first entry in the list is the command on ;; ;; which the reactor will trigger, it may use wildcards. ;; ;; The second entry is the designated layer for the command ;; ;; entered, this layer will be created if non-existent. ;; ;; The third entry is the layer colour that will be used if ;; ;; the layer is to be created in the drawing. ;; ;; ;; ;; The Reactor is enabled upon loading the program - it may ;; ;; be toggled on and off by typing 'LD' at the command line. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (defun c:LD nil (LM:LayerDirector)) (defun LM:LayerDirector nil (vl-load-com) (setq *LayerData* '( ("*TEXT" "TEXT" 2) ("*DIM*,*QLEADER" "DIMENSIONS" 2) ("*VPORT*" "DEFPOINTS" 7) ) ) ( (lambda ( data callback1 callback2 / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor ) ) ) (cdar (vlr-reactors :vlr-command-reactor)) ) ) (if (vlr-added-p react) (vlr-remove react) (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandWillStart callback1) (cons :vlr-commandEnded callback2) (cons :vlr-commandCancelled callback2) ) ) ) ) (if (and react (vlr-added-p react)) (princ "\n<< Layer Director Enabled >>" ) (princ "\n<< Layer Director Disabled >>") ) ) "LayerDirector" 'LayerDirectorSet 'LayerDirectorReset ) (princ) ) (defun LayerDirectorSet ( reactor params / layerdetails layer ) (vl-load-com) (if (and (setq params (strcase (car params)) layerdetails (vl-some (function (lambda ( x ) (if (wcmatch params (car x)) (cdr x)) ) ) *LayerData* ) ) (LM:MakeLayer (setq layer (car layerdetails)) (cadr layerdetails)) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" layer) ) ) ) ) ) (progn (setq *oldlayer* (getvar 'CLAYER)) (setvar 'CLAYER layer) ) ) (princ) ) (defun LayerDirectorReset ( reactor params ) (vl-load-com) (if (and (not (wcmatch (strcase (car params)) "*UNDO")) *oldlayer* (tblsearch "LAYER" *oldlayer*) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" *oldlayer*) ) ) ) ) ) (progn (setvar 'CLAYER *oldlayer*) (setq *oldlayer* nil) ) ) (princ) ) (defun LM:MakeLayer ( name colour ) (or (tblsearch "LAYER" name) (entmakex (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 62 colour) (cons 70 0) ) ) ) ) (princ) (LM:LayerDirector) (princ) Thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 18, 2011 Share Posted May 18, 2011 Hi Woodman, Firstly, bear in mind that there is a function call at the end of the code: (LM:LayerDirector) Which will start the program as soon as it is loaded. It sounds like you have a separate function call after this one which would disable the reactor (since the reactor is coded as a toggle). On a side note: Moderator: what is up with the code formatting? Is it the code itself or are we being hacked again? Lee Quote Link to comment Share on other sites More sharing options...
woodman78 Posted May 23, 2011 Author Share Posted May 23, 2011 I have checked the code and I don't seem to have an extra call at the end of the code. Would you gbe able to create a turn ON and turn OFF routine instead of a toggle. I'm still having the problem with some users? Thanks LeeMac Quote Link to comment Share on other sites More sharing options...
Arin9916 Posted May 24, 2011 Share Posted May 24, 2011 i have same trouble too...^^ Quote Link to comment Share on other sites More sharing options...
woodman78 Posted May 24, 2011 Author Share Posted May 24, 2011 Arin9916, I sorted it out. I just commented out the line to toggle if off so that it always loads on. The code is below. If you want to create an OFF switch then just comment out the line "(vlr-add react)" below the line highlighted in red and remove the ; from the line ";(vlr-remove react)" . Should do the trick. You will also need to rename them separately. Call one LD-ON and other LD-OFF or something like that. ;;-------------------=={ Layer Director }==-------------------;; ;; ;; ;; Uses a command reactor to automatically set the layer ;; ;; upon the user invoking certain commands. ;; ;; ;; ;; Layer settings are stored in the list at the top of the ;; ;; program. The first entry in the list is the command on ;; ;; which the reactor will trigger, it may use wildcards. ;; ;; The second entry is the designated layer for the command ;; ;; entered, this layer will be created if non-existent. ;; ;; The third entry is the layer colour that will be used if ;; ;; the layer is to be created in the drawing. ;; ;; ;; ;; The Reactor is enabled upon loading the program - it may ;; ;; be toggled on and off by typing 'LD' at the command line. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - [url="http://www.lee-mac.com/"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; (defun c:LD nil (LM:LayerDirector)) (defun LM:LayerDirector nil (vl-load-com) (setq *LayerData* '( ("*TEXT" "CCC_LAYOUT_Text" 7) ("*DIM*,*QLEADER*,*MLEADER" "CCC_LAYOUT_Dimensions" 7) ("*VPORT*" "CCC_SHEET_LAYOUT_Viewport" 7) ) ) ( (lambda ( data callback1 callback2 / react ) (if (setq react (vl-some (function (lambda ( reactor ) (if (eq data (vlr-data reactor)) reactor ) ) ) (cdar (vlr-reactors :vlr-command-reactor)) ) ) (if (vlr-added-p react) [color=red] ;(vlr-remove react)[/color] (vlr-add react) ) (setq react (vlr-command-reactor data (list (cons :vlr-commandWillStart callback1) (cons :vlr-commandEnded callback2) (cons :vlr-commandCancelled callback2) ) ) ) ) (if (and react (vlr-added-p react)) (princ "\n<< Layer Director Enabled >>" ) (princ "\n<< Layer Director Disabled >>") ) ) "LayerDirector" 'LayerDirectorSet 'LayerDirectorReset ) (princ) ) (defun LayerDirectorSet ( reactor params / layerdetails layer ) (vl-load-com) (if (and (setq params (strcase (car params)) layerdetails (vl-some (function (lambda ( x ) (if (wcmatch params (car x)) (cdr x)) ) ) *LayerData* ) ) (LM:MakeLayer (setq layer (car layerdetails)) (cadr layerdetails)) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" layer) ) ) ) ) ) (progn (setq *oldlayer* (getvar 'CLAYER)) (setvar 'CLAYER layer) ) ) (princ) ) (defun LayerDirectorReset ( reactor params ) (vl-load-com) (if (and (not (wcmatch (strcase (car params)) "*UNDO")) *oldlayer* (tblsearch "LAYER" *oldlayer*) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" *oldlayer*) ) ) ) ) ) (progn (setvar 'CLAYER *oldlayer*) (setq *oldlayer* nil) ) ) (princ) ) (defun LM:MakeLayer ( name colour ) (or (tblsearch "LAYER" name) (entmakex (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 62 colour) (cons 70 0) ) ) ) ) (princ) (LM:LayerDirector) (princ) Quote Link to comment Share on other sites More sharing options...
irneb Posted May 24, 2011 Share Posted May 24, 2011 Be careful doing that! If for any reason the LSP is loaded more than once, or in this case you've typed LD more than once ... you'll get the reactor running once for every time it was started for each command you issue. So your ACad can become really slow! Lee, I usually prefer setting some data to the reactor I create: So I can step through all reactors and see if it's already turned on before turning it on again! Also it makes it easier to remove erroneous reactors if somewhere this duplicate reactor thingy crops up. (Edit: sorry I see you actually have done so). In which case couldn't you simply have a step through all reactors, turn all matching your data off and then recreate just one version? Alternatively turn off all except for one. If you don't follow one of these you'll have to stick with the toggle on/off. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 24, 2011 Share Posted May 24, 2011 That modification may cause it to add another reactor even if one is already present, and furthermore the user won't be able to turn it off. This is better: ;;-------------------=={ Layer Director }==-------------------;; ;; ;; ;; Uses a command reactor to automatically set the layer ;; ;; upon the user invoking certain commands. ;; ;; ;; ;; Layer settings are stored in the list at the top of the ;; ;; program. The first entry in the list is the command on ;; ;; which the reactor will trigger, it may use wildcards. ;; ;; The second entry is the designated layer for the command ;; ;; entered, this layer will be created if non-existent. ;; ;; The third entry is the layer colour that will be used if ;; ;; the layer is to be created in the drawing. ;; ;; ;; ;; The Reactor is enabled upon loading the program - it may ;; ;; be toggled on and off by typing 'LDON' or 'LDOFF' at the ;; ;; command line. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; (defun c:LDON nil (LM:LayerDirector T)) (defun c:LDOFF nil (LM:LayerDirector nil)) (defun LM:LayerDirector ( on / react ) (setq *LayerData* '( ("*TEXT" "TEXT" 2) ("*DIM*,*QLEADER" "DIMENSIONS" 2) ("*VPORT*" "DEFPOINTS" 7) ) ) (setq react (vl-some (function (lambda ( reactor ) (if (eq "LayerDirector" (vlr-data reactor)) reactor ) ) ) (cdar (vlr-reactors :vlr-command-reactor)) ) ) (cond ( on (if react (if (vlr-added-p react) (princ "\n--> Layer Director Already Running.") (vlr-add react) ) (progn (vlr-command-reactor "LayerDirector" (list (cons :vlr-commandWillStart 'LayerDirectorSet) (cons :vlr-commandEnded 'LayerDirectorReset) (cons :vlr-commandCancelled 'LayerDirectorReset) ) ) (princ "\n--> Layer Director Enabled.") ) ) ) ( react (vlr-remove react) (princ "\n--> Layer Director Disabled.") ) ( (princ "\n--> Layer Director Not Running.") ) ) (princ) ) (defun LayerDirectorSet ( reactor params / layerdetails layer ) (if (and (setq params (strcase (car params)) layerdetails (vl-some (function (lambda ( x ) (if (wcmatch params (car x)) (cdr x)) ) ) *LayerData* ) ) (LM:MakeLayer (setq layer (car layerdetails)) (cadr layerdetails)) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" layer) ) ) ) ) ) (progn (setq *oldlayer* (getvar 'CLAYER)) (setvar 'CLAYER layer) ) ) (princ) ) (defun LayerDirectorReset ( reactor params ) (if (and (not (wcmatch (strcase (car params)) "*UNDO")) *oldlayer* (tblsearch "LAYER" *oldlayer*) (zerop (logand 1 (cdr (assoc 70 (tblsearch "LAYER" *oldlayer*) ) ) ) ) ) (progn (setvar 'CLAYER *oldlayer*) (setq *oldlayer* nil) ) ) (princ) ) (defun LM:MakeLayer ( name colour ) (or (tblsearch "LAYER" name) (entmakex (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 name) (cons 62 colour) (cons 70 0) ) ) ) ) (princ) (vl-load-com) (LM:LayerDirector T) (princ) Quote Link to comment Share on other sites More sharing options...
woodman78 Posted May 24, 2011 Author Share Posted May 24, 2011 Ok. Thanks for the code LeeMac. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 24, 2011 Share Posted May 24, 2011 Thanks for looking over the code Irneb, and for your thoughts Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.