Author Topic: Wanted: reactor example code  (Read 4109 times)

0 Members and 1 Guest are viewing this topic.

Didge

  • Bull Frog
  • Posts: 211
Wanted: reactor example code
« on: March 01, 2006, 09:08:11 AM »
Hi Guys,

Hopefully this is an easy one for somebody to answer.

While surfing the web a while back I came across a great tutorial code for using reactors, the function in question consisted of a 'dwg' of 2 circles with a single line drawn between each circle's centre point. Reactors were set-up to redraw the connecting line when either of the circles were  moved.

Does anybody know of a link to this code, or alternatively a link to any similar examples?

Many thanks in advance,
Didge.
Think Slow......

LE

  • Guest
Re: Wanted: reactor example code
« Reply #1 on: March 01, 2006, 09:38:42 AM »
Didge;

Have a look into the samples I have on my web site, in the downloads section... HTH

www.geometricad.com

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
Re: Wanted: reactor example code
« Reply #2 on: March 01, 2006, 09:39:29 AM »
Heres a link: http://www.geometricad.com/free.php?p=9&lang=en

BTW, you can thank our very own member LE for that code.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10627
Re: Wanted: reactor example code
« Reply #3 on: March 01, 2006, 09:40:05 AM »
Oops, sorry LE. You beat me to it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Didge

  • Bull Frog
  • Posts: 211
Re: Wanted: reactor example code
« Reply #4 on: March 01, 2006, 10:41:59 AM »
LOL, 2 links for the price of 1 :-)

This reactor stuff seems somewhat heavy going for a Vanilla chappy like myself - but essential reading over this coming weekend.

I've never had such trouble drawing a line before

Many thanks Guys, your assistance is much appreciated.
Think Slow......

LE

  • Guest
Re: Wanted: reactor example code
« Reply #5 on: March 01, 2006, 10:49:32 AM »
Remember that now on A2006 exist the DBlocks... apparently you can do the same and more... with less stress [that's what others are saying]

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Wanted: reactor example code
« Reply #6 on: March 01, 2006, 11:16:46 AM »
Here is a link to a swamp thread that Luis was grateful enough to help walk me through my first real attempt.

Thanks again Luis.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Didge

  • Bull Frog
  • Posts: 211
Re: Wanted: reactor example code
« Reply #7 on: March 01, 2006, 12:42:17 PM »
Thanks for that thread, it makes for some very interesting (albeit serious) reading.

I've grabbed LE's tutorials and I've managed to track down the "circle-joining" example I mentioned earlier (author unknown). Thats me all set for some weekend experimentations, thanks muchly guys.


Code: [Select]
;; C:CONNECT - demonstrates simple reactor system based on Visual LISP.
;; Draw two circles, then run the connect routine. A line
;; will be drawn between the two circles. If either circle
;; is modified, the line is regenerated. More than one
;; set of circles can be related and one circle can be
;; related to a group of circles.
;; This function set merely demonstrates the basics involved
;; in building a reactor system in Visual LISP.

(defun c:connect ()
  (setq en1          (car (entsel "\nPick a circle: "));<-- get the 1st circle within block
        en2          (car (entsel " and another: "));<-- get the 2nd circle within block
        rcnt         (if rcnt (1+ rcnt) 1)
        connect_flag 't
  )
  (if (and en1 en2)
    (progn
      (vl-load-com)
      (setq en3 (connection en1 en2)
            en3 (vlax-ename->vla-object en3)
            en1 (vlax-ename->vla-object en1)
            en2 (vlax-ename->vla-object en2)
      )
      (vlr-object-reactor
        (list en1 en2 en3)
        (strcat "Connect Circles " (itoa rcnt))
        '((:vlr-modified . connectfix)
          ;;(:vlr-erased . ConnectKill)
         )
      )
    )
  )
)
;; Drawing a line between circles
(defun connection (en1 en2 / el1 el2)
  (setq en1 (if (= (type en1) 'ename) en1 (vlax-vla-object->ename en1))
        en2 (if (= (type en2) 'ename) en2 (vlax-vla-object->ename en2))
        el1 (entget en1)
        el2 (entget en2)
        r1  (cdr (assoc 40 el1))
        r2  (cdr (assoc 40 el2))
        p1  (cdr (assoc 10 el1))
        p2  (cdr (assoc 10 el2))
        a1  (angle p1 p2)
        p1  (polar p1 a1 r1)
        p2  (polar p2 (+ a1 pi) r2)
  )
  (entmake (list
             '(0 . "LINE")
             (assoc 8 el1)
             (cons 10 p1)
             (cons 11 p2)
           )
  )
  (entlast)
)
;; Entity Object Callback function
(defun connectfix (not_obj   ;caused notification
                   re_obj    ;reactor object
                   plist     ;parameters list
                   / objlist ;objects in reactor set
                   vobj      ;VLA object
                   en        ;Entity name
                   el        ;Entity list
                   enl       ;Entity list for line
                   p1        ;Center/end point 1
                   p2        ;Center/end point 2
                   r1        ;Radius 1
                   r2        ;Radius 2
                   skipit    ;Process change flag
                  )
  ;;
  (if connect_flag
    (progn
      (setq connect_flag nil)
      (setq objlist (vlr-owners re_obj))
      (foreach vobj objlist
        (setq en (vlax-vla-object->ename vobj)
              el (entget en)
        )
        (cond
          ((= (cdr (assoc 0 el)) "LINE")
           (if (eq not_obj vobj) (setq skipit 't))
           (setq enl el)
          )
          ('t
           (set (if (boundp 'p1) 'p2 'p1) (cdr (assoc 10 el)))
           (set (if (boundp 'r1) 'r2 'r1) (cdr (assoc 40 el)))
          )
        )
      )
      (setq aa  (angle p1 p2)
            p1  (polar p1 aa r1)
            p2  (polar p2 (+ aa pi) r2)
            enl (subst (cons 10 p1) (assoc 10 enl) enl)
            enl (subst (cons 11 p2) (assoc 11 enl) enl)
      )
      (if (null skipit)
        (entmod enl) ;update the line
        (prompt "\nConnection broken.")
      )
      (setq connect_flag 't)
    )
  )
)

Reformatted Code, Hope you don't mind. CAB
« Last Edit: March 01, 2006, 01:12:59 PM by CAB »
Think Slow......

LE

  • Guest
Re: Wanted: reactor example code
« Reply #8 on: March 01, 2006, 12:44:36 PM »
That's Bill Kramer code...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Wanted: reactor example code
« Reply #9 on: March 01, 2006, 12:50:06 PM »
FYI...
You are missing one of the functions "ConnectKill" which you need incase one gets erased.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.