TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Didge 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.
-
Didge;
Have a look into the samples I have on my web site, in the downloads section... HTH
www.geometricad.com
-
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.
-
Oops, sorry LE. You beat me to it.
-
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.
-
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]
-
Here is a link (http://www.theswamp.org/forum/index.php?topic=8710.0) to a swamp thread that Luis was grateful enough to help walk me through my first real attempt.
Thanks again Luis.
-
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.
;; 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
-
That's Bill Kramer code...
-
FYI...
You are missing one of the functions "ConnectKill" which you need incase one gets erased.