Lisaj98052 Posted October 14, 2017 Share Posted October 14, 2017 I was wondering if anyone has an example of a layer eractor that switches layers base on the layout tab. my idea is to place text on different layers base on the tab the active tab. Example I have one file with 5 layout so I want to place text on layer anno-text-sheet 1, or anno-text-sheet 2 and so on. any help would be great. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted October 14, 2017 Share Posted October 14, 2017 Why don't you VPFreeze layers? Quote Link to comment Share on other sites More sharing options...
Lisaj98052 Posted October 15, 2017 Author Share Posted October 15, 2017 I use to have a lisp or reactor that when I witch layouts and keyed in txt is made a layer named c-anno-tabname-text (say c-anno-C005-text and then all I had to do was vpfreeze C-ANNO-C004-text and C-ANNO-C006-text layers. But I lost it some where. Quote Link to comment Share on other sites More sharing options...
PDuMont Posted October 16, 2017 Share Posted October 16, 2017 Hi Lisaj. This relies on your layout tabs having correct naming: i.e. C001, C002, etc. Briefly tested. (defun c:TabNameOn () (vl-load-com) (if (not com:react) (progn (setq com:react (vlr-command-reactor nil '((:vlr-commandWillStart . ComReactBegin) (:vlr-commandEnded . ComReactEnd) (:vlr-commandCancelled . ComReactCancel)))) (princ "\n<<< Command reactor Switched ON >>>") ); end progn ); end if (princ) ); end of c:TabNameOn (defun c:TabNameOff () (if com:react (progn (vlr-Remove com:react) (setq com:react nil) (princ "\n<<< Command reactor Switched OFF >>> ") ); end progn ); end if ); end of c:TabNameOff (defun ComReactBegin (react args / layname comLst nLay) (setq layname (getvar 'ctab)) (setq layname (strcase (strcat "C-ANNO-" layname "-TEXT"))) (setq comLst '(((layname 3) "MTEXT" "DTEXT" "TEXT" "EATTEXT" "QLEADER" "MLEADER" "LEADER" "REVCLOUD" "TABLE" "DATAEXTRACTION" ) ) ; end comLst ) ; end setq (foreach itm comLst (if (member (car args) itm) (progn (if (not (tblsearch "LAYER" layname)) (progn (setq nLay (vla-Add (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) layname)) (vla-put-Color nLay (cadar itm)) (setq com:resFlg T) ); end progn ); end if (setq com:oldLay (getvar 'clayer) com:resFlg T) (setvar 'clayer layname) ); end progn ); end if ); end foreach (princ) ); end of ComReactBegin (defun ComReactEnd(react args) (if com:resFlg (progn (setq com:resFlg nil) (setvar 'clayer com:oldLay) ); end progn ); end if (princ) ); end of ComReactEnd (defun ComReactCancel(react args) (if com:resFlg (progn (setq com:resFlg nil) (setvar 'clayer com:oldLay) ); end progn ); end if (princ) ); end of ComReactCancel (princ "\nType TABNAMEON to switch-on and TABNAMEOFF switch-off command reactor! ") (c:TabNameOn) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 16, 2017 Share Posted October 16, 2017 Hi, Try this; (vl-load-com) ;; Tharwat - 16.Oct.2017 ;; (defun SetLayerApp () (or *SetLayerReactor* (setq *SetLayerReactor* (vlr-sysvar-reactor nil '((:vlr-sysVarChanged . SetLayer)))) ) ) (defun SetLayer (e p / l) (if (or (eq (car p) "CLAYOUT") (eq (car p) "CTAB")) (and (or (tblsearch "LAYER" (setq l (strcat "anno-text-" (setq *currenttab* (getvar 'CTAB))))) (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) l)) (setvar 'CLAYER l) ) ) ) (SetLayerApp) Quote Link to comment Share on other sites More sharing options...
PDuMont Posted October 16, 2017 Share Posted October 16, 2017 Very concise Tharwat! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted October 16, 2017 Share Posted October 16, 2017 Very concise Tharwat! Thank you Philip. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 16, 2017 Share Posted October 16, 2017 Probably easier to use the vlr-layoutswitched event... (vl-load-com) (foreach rtr (cdar (vlr-reactors :vlr-miscellaneous-reactor)) (if (= "layout-text-reactor" (vlr-data rtr)) (vlr-remove rtr)) ) (vlr-miscellaneous-reactor "layout-text-reactor" '((:vlr-layoutswitched . layout-text-reactor-callback))) (defun layout-text-reactor-callback ( rtr arg / lyn ) (if (/= "model" (strcase (car arg) t)) (progn (vla-put-freeze (vla-add (cond (layout-text-reactor-layers) ((setq layout-text-reactor-layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))) ) (setq lyn (strcat "anno-text-" (car arg))) ) :vlax-false ) (setvar 'clayer lyn) ) ) (princ) ) 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.