Jump to content

Help with vlr functions.


Costinbos77

Recommended Posts

Sorry for my language.

I am new in VLR Functions and I want to make a 2 reactors between a polyline and a acad table with coordinates of polyline . When I modify the polyline , polyline reactor modify de coordinates in table . If I change the coordinates in acad table , table reactor modify the polyline vertices . How can I stop the cycling executed reactions ? Because when I modify one of this tow objects , opposite reactor react in consequence and I don’t want to. Below , I put my lisp code .

 

 

;;; make a 2 reactors between a polyline and a acad table with coordinates of polyline
;;; Version : 1 . 11 . 2012 ;
;;; [email="costinbos@yahoo.com"]costinbos@yahoo.com[/email]
(defun FReaPlin (nmvr revr ppp) ; Functie Reactor PoliLinie ! V : 30 . 10 . 2012 .
(princ "\n   FReaPlin  ;")
(if (and (not keypl1) (vlax-read-enabled-p nmvr)) ; vlax-write-enabled-p
 (progn
  (or (vl-load-com))
  (defun FEnd () ; Functie de Incheiere ! V : 15 . 09 . 2012 .
   (setq keypl1 nil  keytab nil  keypl2 nil) ;_ end of setq
  ) ;_ end of defun FEnd !
  (FAlReact "Reactor Tabel") ; Functie Alegere Reactor ! nmobvl vlobjw

  (if (and nmobvl vlobjw)
   (progn
    (setq keypl1 nil  keytab T  keypl2 nil  nmobpv (vlax-vla-object->ename nmvr)
          lent (entget nmobpv)  tip (strcase (cdr (assoc 0 lent)))  lcoo nil) ;_ end of setq

    (princ (strcat "\n   Functia  :  FReaPlin  =  " tip "  ;"))

    (foreach el lent (if (member (car el) '(10 11)) (setq lcoo (cons (cdr el) lcoo)) ) ) ;_ end of f
    (setq lcoo (reverse lcoo)  llcoo (length lcoo)  i 2  row (- (vla-get-Rows vlobjw) 2) ) ;_ end of setq
    (cond ((> llcoo row) (progn (vla-InsertRows vlobjw (+ row 2) (vla-GetRowHeight vlobjw 2) (- llcoo row)) ))
          ((< llcoo row) (progn (vla-DeleteRows vlobjw (+ row 0) (- row llcoo)) ))
    ) ;_ end of c

    (vla-put-RegenerateTableSuppressed vlobjw :vlax-false)

    (foreach el lcoo
     (vla-setText vlobjw i 0 (itoa (1- i)))
     (vla-setText vlobjw i 1 (rtos (car el) 2 3))
     (vla-setText vlobjw i 2 (rtos (cadr el) 2 3))
     (vla-setText vlobjw i 4 (rtos (if (> i 2) (distance p1 el) 0) 2 3))
     (setq p1 el)

     (setq i (1+ i)) ;_ end of setq
    ) ;_ end of f el
   ) ;_ end of prog then
   (alert (strcat "   Valori  NULE  Pentru  Obiecte   :  nmobvl  ,  vlobjw   !!!\n\n   Descriere  Reactor  :  " "desrea" "  .")) ;_ end of a
  ) ;_ end of if (and nmobvl vlobjw)
  (FEnd) ; Functie de Incheiere !
  (princ)
)) ;_ end of if (not keypl1)
(princ "\n   FReaPlin  :  End  !") ; Depanare !
) ;_ end of defun FReaPlin
; ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
(defun FAlReact (desrea / i j lisrea llisrea) ; Functie Alegere Reactor ! V : 31 . 10 . 2012 .
(princ (strcat "\n   FAlReact  :  " desrea)) ;_ end of p ; Depanare !
(if (setq nmobvl nil  vlobjw nil  lisrea (vlr-reactors :vlr-object-reactor)) ;_ end of setq
 (progn
;;;_  (vlr-type replin) ; :VLR-Object-Reactor
  (setq i 0  llisrea (length lisrea)) ;_ end of setq
  (while (< i llisrea)
   (setq lreact (nth i lisrea)  j 1  llreact (length lreact) ) ;_ end of setq
   (while (< j llreact)
    (setq nreact (nth j lreact)) ;_ end of setq
    (if (= (vlr-data nreact) desrea) ; Cauata Descrierea
     (if (setq i llisrea  j llreact  vlobjw (car (vlr-owners nreact)) ) ;_ end of setq
      (setq nmobvl (vlax-vla-object->ename vlobjw)) ;_ end of setq
     ) ;_ end of if vlobjw
    ) ;_ end of if =
    (setq j (1+ j)) ;_ end of setq
   ) ;_ end of wh (< pas llisrea)
   (setq i (1+ i)) ;_ end of setq
  ) ;_ end of wh (< pas llisrea)
 ) ;_ end of prog then
 (alert (strcat "   Lista  Reactori  Pentru  Obiecte  GOALA   !!!\n\n   Descriere  Reactor  :  " desrea "  .")) ;_ end of a
) ;_ end of if (not keypl1)
(princ "\n   FAlReact  :  End  !") ;_ end of p ; Depanare !
) ;_ end of defun FAlReact
; ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
(defun FReaTab (nmvr revr ppp) ; Functie Reactor Tabel ! V : 31 . 10 . 2012 .
(princ "\n   FReaTab  ;") ; Depanare !
(if (and (not keytab) (vlax-read-enabled-p nmvr))
 (progn
  (or (vl-load-com))
  (defun FEnd () ; Functie de Incheiere ! V : 15 . 09 . 2012 .
   (setq keypl1 nil  keytab nil  keypl2 nil) ;_ end of setq
  ) ;_ end of defun FEnd !
  (FAlReact "Reactor PoliLinie") ; Functie Alegere Reactor ! nmobvl vlobjw

  (if (and nmobvl vlobjw)
   (progn
    (setq keypl1 T  keypl2 T  lentpl (reverse (entget nmobvl))  tip (strcase (cdr (assoc 0 lentpl)) )
          rnd (vla-get-Rows nmvr)  i 2  lpct nil  lver nil) ;_ end of setq
    (princ (strcat "\n   Functia  :  FReaTab  =  " tip "  ;"))
    (while (< i rnd)
     (setq nmp (vla-getText nmvr i 0)
           e (atof (vla-getText nmvr i 1))
           n (atof (vla-getText nmvr i 2))
           h (atof (vla-getText nmvr i 3))
           lpct (cons (list nmp e n h) lpct)
           lver (cons (list 10 e n) lver)
     ) ;_ end of setq
     (setq i (1+ i)) ;_ end of setq
    ) ;_ end of wh
    (if (and lpct lver)
     (progn
      (setq lpct (reverse lpct)  lver (reverse lver)
            loplb (reverse (member (assoc 39 lentpl) lentpl))
            lcoon (append loplb lver)  ) ;_ end of setq
;;;       (command "zoom" "o" nmobvl "")
      (entmod lcoon) (entupd lcoon)
      (alert "\n   Obiect  Polilinie  Modificat  de  TABEL   !")
     ) ;_ end of prog then
     (alert "Functia  :  FReaTab  !\n\n  Lista  'lpct'  cu  COORDONATE  din  Tabel  este  GOALA   !") ;_ end of 
    ) ;_ end of if lpct
   ) ;_ end of prog then
   (alert "Functia  :  FReaTab  !\n\n   NU  S-au  Determinat  :  Nume Obiect  si  Variant  !\n\n  NU  se  va  Modifica  Planimetria   !") ;_ end of 
  ) ;_ end of if (and nmobvl vlobjw)
  (FEnd) ; Functie de Incheiere !
  (princ)
)) ;_ end of if (not keytab)
(princ "\n   FReaTab  :  End  !") ; Depanare !
) ;_ end of defun FReaTab

;;; 5 . 10 **********   **********   **********   ***   Start  ***
(defun C:ProCond ()
(or (vl-load-com))
(if (not (setq obtpl (car (entsel "\n   Select  PolyLine  :   Enter  =  Defyne  : "))) )
 (progn
  (command "pline")
  (while (setq p (getpoint (if p p '(0 0)) "\n   Defyne  PolyLine  :    Enter  =  Stop  ;    < Pick > ;"))
   (command (list (car p) (cadr p))) ) ;_ end of wh
  (command "") ;_ end of c
  (setq obtpl (entlast) ) ;_ end of setq
) )  ;_ end of if not obtpl
(setq rnd (cdr (assoc 90 (entget obtpl))) ) ;_ end of setq Nr Vertexuri
(command "style" "Arial" "Arial" "0" "1" "0" "N" "N") ;_ end of c
(command "_table" 8 rnd '(0 0 0)) ;_ end of c
(princ "\n   CORNER  Top - Left  Table  Coordonates  :  < Pick > :  ") ;_ end of p
(command "move" (entlast) "" '(0 0 0) pause) ;_ end of c
(setq vmypol (vlax-ename->vla-object obtpl)  lu (vla-get-Length vmypol) ; lisco (vla-get-Coordinates vmypol)
      vmytab (vlax-ename->vla-object (entlast) )  ) ;_ end of setq
(setq acmCol (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2)))) ; Proprietate Culoare
(vla-put-RegenerateTableSuppressed vmytab :vlax-false) ; Regenerare Tabel Activa
(vla-setTextStyle vmytab (+ acDataRow acHeaderRow acTitleRow) "Arial") ; "Standard"
(vla-put-TitleSuppressed vmytab :vlax-false)
(vla-setText vmytab 0 0 "Tabel cu Coordonate")
(vla-put-HeaderSuppressed vmytab :vlax-false) ; :vlax-true
(vla-setText vmytab 1 0 "Name") (vla-setText vmytab 1 1 "E [ m ]") (vla-setText vmytab 1 2 "N [ m ]") (vla-setText vmytab 1 3 "Hr [ m ]")
(vla-setText vmytab 1 4 "D [ m ]") (vla-setText vmytab 1 5 "Panta o/oo") (vla-setText vmytab 1 6 "Ht [ m ]") (vla-setText vmytab 1 7 "Adâncime [ m ]")
(setq replin (vlr-object-reactor (list vmypol) "Reactor PoliLinie" '((:vlr-objectClosed . FReaPlin))) ) ; :vlr-modified ; :vlr-objectClosed
(setq retab (vlr-object-reactor (list vmytab) "Reactor Tabel" '((:vlr-objectClosed . FReaTab))) ) ; :vlr-modified ; :vlr-objectClosed
(FReaPlin vmypol replin T) ; Completeaza Initial Tabelul

(vlr-pers replin) (vlr-pers retab) ; Devine Persistent
(setq lreper (vlr-pers-list)) ; (vlr-pers-list :vlr-object-reactor)
(princ "\n   END  C:ProCond  .")

(FEnd) ; Functie de Incheiere !

) ;_ end of DEFUN C:ProCond  !
;;; 5 . 10 ***********************     END     **************

Edited by Costinbos77
added [CODE] tags
Link to comment
Share on other sites

How can I stop the cycling executed reactions? Because when I modify one of this tow objects , opposite reactor react in consequence and I don’t want to.

 

I don't have time to look through your code, but to prevent the infinite callback loop you can temporarily disable a reactor using vlr-remove from within the appropriate reactor callback function (note that you will need to ensure that all owners of the Object Reactor are write-enabled for the reactor to be successfully disabled), then re-enable the reactor following modification using the vlr-add function.

Link to comment
Share on other sites

I don't have time to look through your code, but to prevent the infinite callback loop you can temporarily disable a reactor using vlr-remove from within the appropriate reactor callback function (note that you will need to ensure that all owners of the Object Reactor are write-enabled for the reactor to be successfully disabled), then re-enable the reactor following modification using the vlr-add function.

 

Tanks’ for your answer .

You have an example with 2 reactors interdependent ? Because I cannot made it.

When I modify the polyline object, immediately activates table reactor.

 

Costin

Edited by Costinbos77
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...