Author Topic: Changing VLA in a Reactor Lisp  (Read 1941 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Changing VLA in a Reactor Lisp
« on: November 19, 2013, 03:31:32 PM »
I have found some code that does work when I close out a drawing. Its basic. So when I close a drwing it will zoom extents and then pops up a window saying "Command Close was issed." (Press ok) then Save file and exits.

I would like to find the call / command to (uncheck the Display Plot Styles) in the page setup window.

Hopefully that is an easy change... But I do now know.

Code: [Select]
;;=======================================================================
;; CLOSE reactor
;;=======================================================================
(vl-load-com)
(defun smart-command-reactor (commands StartCallback EndCallback / ended)
  (vl-load-reactors)
  (setq ended
    (vlr-command-reactor nil
     '(
        (:vlr-commandEnded . internal-commandEnded)
        (:vlr-commandCancelled . internal-commandEnded)
        (:vlr-commandFailed . internal-commandEnded)
      )
    )
  )
  (vlr-remove ended)
  (vlr-command-reactor
    (list
      ended
      StartCallback
      EndCallback
      (if (listp commands)
        (mapcar 'strcase commands)
        (list (strcase commands))
      )
    )
    '((:vlr-commandWillStart . internal-commandWillStart))
  )
)
;;=======================================================================
(defun internal-commandWillStart (reactor args / data result)
  (setq data (vlr-data reactor))
  (if
    (and
      (member (car args) (last data))
      (setq result (apply (cadr data) (list (car args))))
    )
    (progn
      (vlr-data-set
        (car data)
        (list (caddr data) result)
      )
      (vlr-add (car data))
    )
  )
)
;;=======================================================================
(defun internal-commandEnded (reactor args / data)
  (setq data (vlr-data reactor))
  (vlr-remove reactor)
  (apply
    (car data)
    (list
      reactor
      (vlr-current-reaction-name)
      (car args)
      (cadr data)
    )
  )
)
;;=======================================================================
(if *my-smart-close-reactor* (vlr-remove *my-smart-close-reactor*))
;;=======================================================================
(setq *my-smart-close-reactor*

  (smart-command-reactor

    ;; command(s) as list
    '("CLOSE")

    ;; StartCallback (called when CLOSE starts)
    (function
      (lambda (cmdname)
        ;;;===================================================
        ;;; *** from here
        ;;;===================================================
(vla-ZoomExtents (vlax-get-acad-object))
(alert "Command CLOSE was issued.")
        ;;;===================================================
        ;;; *** to here
        ;;;===================================================
      )
    )

    ;; EndCallback (called when CLOSE ends)
    (function
      (lambda (data)
        (setvars data)
        (sssetfirst nil)
        (setq app nil adoc nil)
      )
    )
  )
)
;;=======================================================================
(defun setvars (data)
  (mapcar
    (function
      (lambda (v / r)
        (setq r (getvar (car v)))
        (setvar (car v) (cdr v))
        (cons (car v) r)
      )
    )
    data
  )
)
;;=======================================================================
(princ "\nCLOSE reactor enabled.")
;;=======================================================================
(princ)
;;=======================================================================
Civil3D 2020

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Changing VLA in a Reactor Lisp
« Reply #1 on: November 19, 2013, 03:49:23 PM »
If you add this just above the zoomextents line:
(vla-put-showplotstyles
  (vla-get-activelayout
    (vla-get-activedocument
      (vlax-get-acad-object)))
  :vlax-false)

it should do what you want.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Changing VLA in a Reactor Lisp
« Reply #2 on: November 19, 2013, 04:00:03 PM »
Works! Sweet. Ill ask one more thing... What if I wanted to add this to the reactor script as well.

Code: [Select]
(defun c:foo (/ i)
  (if (= (strcase (getenv "username")) "YOU")
    (setq i -1)
    (setq i 0)
  )
  (vlax-for l (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if (zerop (vlax-get l 'modeltype))
      (vlax-put l 'showplotstyles i)
    )
  )
  (princ)
)
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing VLA in a Reactor Lisp
« Reply #3 on: November 19, 2013, 04:09:00 PM »
Maybe this will shed some light :)

Code: [Select]

(or *commandreactors*
    (setq *commandreactors*
      (vlr-command-reactor
        nil
        '((:vlr-commandwillstart . strtcmd)
          (:vlr-commandended . endcmd)
          (:vlr-commandcancelled . cnclcmd)
          (:vlr-commandfailed . faldcmd)
         )
      )
    )
)
;; Resets all tabs to not show plot styles on close
(defun strtcmd (calling-reactor strtcmdinfo)
  (if (wcmatch (strcase (car strtcmdinfo) t) "close,closeall")
    (vlax-for l   (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
      (if (zerop (vlax-get l 'modeltype))
   (vlax-put l 'showplotstyles 0)
      )
    )
  )
)
« Last Edit: November 19, 2013, 04:48:55 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Changing VLA in a Reactor Lisp
« Reply #4 on: November 19, 2013, 04:23:45 PM »
Guess what... I remembered something you helped me with:

http://www.theswamp.org/index.php?topic=45449.15

Guess what again. It works now. I do not know why it does now, but all that matters is it does.

This will make alot of people (not mad at me). lol

Thanks for all your time and help with me again:)
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing VLA in a Reactor Lisp
« Reply #5 on: November 19, 2013, 04:51:26 PM »
Glad to help out  8)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC