Jump to content

layer reactor


Lisaj98052

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...