Author Topic: reactor question *solved*  (Read 1737 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
reactor question *solved*
« on: August 04, 2006, 04:16:07 PM »
So the code below is working....kinda...when I issue a command it sets the layer, when I cancel it puts the layer back....but then it errors:

Quote
Dim: *Cancel*
; error: bad function: T

Updated code below:

Code: [Select]
(if (not *rjp-CommandReactors*)
  (setq *rjp-CommandReactors*
(vlr-command-reactor
   nil
   '((:vlr-commandWillStart . startCommand)
     (:vlr-commandEnded . endCommand)
     (:vlr-commandCancelled . cancelCommand)
     (:vlr-commandFailed . failedCommand)
    )
)
  )
)
(defun startCommand
       (calling-reactor startcommandInfo / thecommandstart)
  (setq thecommandstart (nth 0 startcommandInfo))
  (cond
    ((wcmatch (strcase thecommandstart)
      (strcase "Dim*")
     )
     (setq *lay* (getvar 'clayer))
     (rjp-addclayer "dim" 2)
    )
  )
)
(defun endCommand (calling-reactor endcommandInfo / thecommandend)
  (setq thecommandend (nth 0 endcommandInfo))
  (cond
    ((wcmatch (strcase thecommandend) (strcase "Dim*"))
     (setvar "clayer" *lay*)
    )
  )
)
(defun cancelCommand
       (calling-reactor cancelCommandInfo / thecommandcancel)
  (setq thecommandcancel (nth 0 cancelCommandInfo))
  (cond
    ((wcmatch (strcase thecommandcancel) (strcase "Dim*"))
     (setvar "clayer" *lay*)
    )
  )
)
(defun failedCommand
       (calling-reactor failedCommandInfo / thecommandfailed)
  (setq thecommandfailed (nth 0 failedCommandInfo))
  (cond
    ((wcmatch (strcase thecommandfailed) (strcase "Dim*"))
     (setvar "clayer" *lay*)
    )
  )
)
(defun rjp-addclayer (layName clr / doc lay lays)
  (setq doc  (vla-get-activedocument (vlax-get-acad-object))
lays (vla-get-layers doc)
  )
  (vla-add lays layName)
  (vlax-for lay (vla-get-layers
  (vla-get-activedocument (vlax-get-acad-object))
)
    (if (wcmatch (strcase (vla-get-name lay)) (strcase layName))
      (progn
(vl-catch-all-error-p
  (vl-catch-all-apply 'vla-put-color (list lay clr))
)
(if (= (vla-get-freeze lay) :vlax-true)
  (vla-put-freeze lay :vlax-false)
)
(if (= (vla-get-layeron lay) :vlax-false)
  (vla-put-layeron lay :vlax-true)
)
      )
    )
  )
  (vlax-put-property doc 'ActiveLayer (vla-add lays layName))
  (princ)
)
« Last Edit: August 04, 2006, 05:22:25 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

LE

  • Guest
Re: reactor question
« Reply #1 on: August 04, 2006, 04:54:11 PM »
Do not know if I want to impose a solution here, but I had used in the past something like this:

http://www.theswamp.org/index.php?topic=9441.msg137293#msg137293

That appears to work, just fine. - With very little changes to suit your needs.

LE

  • Guest
Re: reactor question *solved*
« Reply #2 on: August 04, 2006, 08:12:03 PM »
I see that you have your code working now, anyway here is another approach:

Code: [Select]

;; updated for theSwamp!

;; by default having the ability ON
(if (or (eq (getenv "RunSetLayerReactor") nil)
(eq (getenv "RunSetLayerReactor") ""))
  (setenv "RunSetLayerReactor" "1"))

(defun setlayer (reactor params)
  (if (eq (getenv "RunSetLayerReactor") "1")
    (progn
      (if (not
    (wcmatch
      (getvar "cmdnames")
      "UNDO,U,REDO,OOPS,STYLE,COPYCLIP,COPYBASE,CUTCLIP"))
(progn
  (if (and
(wcmatch (strcase (car params)) "*DIM*")
dim_enames)
    (progn
      (foreach obj  (mapcar 'vlax-ename->vla-object
    dim_enames)
(vla-put-layer obj "A-DIM"))
      (setq dim_enames nil)))))
      (setq dim_enames nil))))

(defun commandcancelled (reactor params)
  (if (and (eq (getenv "RunSetLayerReactor") "1")
   (wcmatch (strcase (car params)) "*DIM*"))
    (setq dim_enames nil)))

(defun objectappended  (reactor params)
  (if
    (and
      (eq (getenv "RunSetLayerReactor") "1")
      (not
(wcmatch
  (getvar "cmdnames")
  "UNDO,U,REDO,OOPS,STYLE,COPYCLIP,COPYBASE,CUTCLIP,NEW,QNEW,OPEN,*LAYOUT*,MOVE,COPY,*STRETCH*")))
     (cond
       ((and
  (wcmatch (getvar "cmdnames") "*DIM*")
  params
  (entget (cadr params))
  (wcmatch (cdadr (entget (cadr params))) "DIMENSION")
  (not
    (vl-position (cadr params) dim_enames)))
(setq dim_enames
       (cons (cadr params) dim_enames))))))

(if (not editor_reactor)
  (setq editor_reactor
(vlr-set-notification
   (vlr-editor-reactor
     "editor"
     '((:vlr-commandended . setlayer)
       (:vlr-commandcancelled . commandcancelled)))
   'active-document-only)))

(if (not acdb_reactor)
  (setq acdb_reactor
(vlr-set-notification
   (vlr-acdb-reactor
     "acdb"
     '((:vlr-objectappended . objectappended)))
   'active-document-only)))

(princ)