Author Topic: here are two questions,please help me.  (Read 635 times)

0 Members and 1 Guest are viewing this topic.

Xran

  • Guest
here are two questions,please help me.
« on: December 20, 2012, 05:06:25 AM »
hi everyone~
i'm learning Reactor programming now.
i wrote a test program to examine the response of act.
there are two questions i cant understand.
1. Can i use (vlr-pers) in :vlr-beginClose callback ?
    it always return nil.
2. my object-reactor cant work well with "undo" command,can anyone give me an example code.
thank you very much.
the code:
Code - Auto/Visual Lisp: [Select]
  1. (setq *MoSpace* (vla-get-ModelSpace *AcadDoc*))
  2. (if (not *commandreactor*)
  3.   (setq *commandreactor*
  4.          (vlr-command-reactor
  5.            nil
  6.            '(
  7.              (:vlr-commandwillstart . test:commandwillstart)
  8.              (:vlr-commandended . test:commandended)
  9.             )
  10.          )
  11.   )
  12. )
  13. (if (not *dwgreactor*)
  14.   (setq *dwgreactor*
  15.          (vlr-dwg-reactor
  16.           nil
  17.           '(
  18.             (:vlr-beginClose . test:beginClose)
  19.            )
  20.         )
  21.   )
  22. )
  23.  
  24. (defun test:beginclose (reactor para / reactorlist ret)
  25.   (setq reactorlist (cdr (assoc :vlr-object-reactor (vlr-reactors))))
  26.   (foreach ret reactorlist
  27.     (if (not (vlr-pers-p ret))
  28.       (vlr-pers ret)
  29.     )
  30.   )
  31. )
  32.  
  33.  
  34. (defun c:test (/ cenpt ocir otext)
  35.   (setq ocir (vla-addcircle *mospace* (vlax-3d-point '(0 0 0)) 2.0))
  36.   (setq
  37.     otext (vla-addtext
  38.             *mospace*
  39.             (rtos (vlax-get-property ocir 'Radius) 2 1)
  40.             (vlax-3d-point '(0 0 0))
  41.             1.0
  42.           )
  43.   )
  44.     (list ocir otext)
  45.     "test circle"
  46.     '(
  47.       (:vlr-erased . test:erased)
  48.       (:vlr-unerased . test:unerased)
  49.       (:vlr-modified . test:modified)
  50.       (:vlr-copied . test:copied)
  51.      )
  52.   )
  53. )
  54.  
  55. (defun test:undosubcommandbegin (reactor para)
  56.   (setq *undoreactor* (cons reactor *undoreactor*)
  57.         *undopara*    (cons para *undopara*)
  58.   )
  59. )
  60.  
  61. (defun test:copied (obj reactor para)
  62.   (setq *objcopied*     (cons para *objcopied*)
  63.         *reactorcopied* (cons reactor *reactorcopied*)
  64.   )
  65. )
  66.  
  67. (defun test:commandwillstart (reactor para)
  68.   (setq *reactormodified* nil
  69.         *reactortoerase*  nil
  70.         *reactorcopied*   nil
  71.         *objmodified*     nil
  72.         *objtoerase*      nil
  73.  
  74.   )
  75. )
  76.  
  77. (defun test:commandended (reactor para)
  78.   (cond
  79.     (*reactortoerase*
  80.      (test:erasereactor)
  81.     )
  82.     (*reactorcopied*
  83.      (test:copyreactor)
  84.     )
  85.     (*reactormodified*
  86.      (test:modifyreactor)
  87.     )
  88.   )
  89. )
  90.  
  91.  
  92. (defun test:modified (obj reactor para)
  93.   (setq *objmodified* (cons obj *objmodified*))
  94.   (if (not (member reactor *reactormodified*))
  95.     (setq *reactormodified* (cons reactor *reactormodified*))
  96.   )
  97. )
  98.  
  99. (defun test:erased (obj reactor para)
  100.   (setq *objtoerase* (cons obj *objtoerase*))
  101.   (if (not (member reactor *reactortoerase*))
  102.     (setq *reactortoerase* (cons reactor *reactortoerase*))
  103.   )
  104. )
  105.  
  106. (defun test:modifyreactor (/ reactor owners obj1 obj2)
  107.   (foreach reactor *reactormodified*
  108.     (setq owners (vlr-owners reactor)
  109.           obj1   (car owners)
  110.           obj2   (cadr owners)
  111.     )
  112.     (if (vlax-property-available-p obj1 'Radius)
  113.         obj2
  114.         'Textstring
  115.         (rtos (vlax-get-property obj1 'Radius) 2 1)
  116.       )
  117.         obj1
  118.         'Textstring
  119.         (rtos (vlax-get-property obj2 'Radius) 2 1)
  120.       )
  121.     )
  122.   )
  123.   (setq *reactormodified*
  124.          nil
  125.         *objmodified* nil
  126.   )
  127. )
  128. (defun test:erasereactor (/ reactor owners owner)
  129.   (foreach reactor *reactortoerase*
  130.     (setq owners (vlr-owners reactor))
  131.     (foreach owner owners
  132.       (vlr-owner-remove reactor owner)
  133.       (if (not (vlax-erased-p owner))
  134.         (vla-erase owner)
  135.       )
  136.     )
  137.   )
  138.   (setq *reactortoerase*
  139.                          nil
  140.         *objtoerase*     nil
  141.   )
  142. )
  143.  
  144.  
  145. (defun test:unerased (obj reactor para)
  146.   (setq *uneraseobjlist*
  147.          (cons obj *uneraseobjlist*)
  148.         *unerasereactorlist*
  149.          (cons reactor *unerasereactorlist*)
  150.         *uneraseparalist*
  151.          (cons para *uneraseparalist*)
  152.   )
  153. )