Author Topic: linked/synchronized/ entities and objects  (Read 5657 times)

0 Members and 1 Guest are viewing this topic.

ozimad

  • Guest
linked/synchronized/ entities and objects
« on: August 23, 2010, 02:24:50 PM »
Hi everyone!
I am searching articles, tutorial and help in creation of linked/synchronized/ entities and objects.
For example how to get text linked to the polyline, when i move polyline text moves along.
Or moving one block another block follows first, by linking insertion points.
i think the idea is clear,
thanks in advance for the help.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: linked/synchronized/ entities and objects
« Reply #1 on: August 23, 2010, 02:29:15 PM »
Look into using an Object Reactor perhaps  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: linked/synchronized/ entities and objects
« Reply #2 on: August 23, 2010, 07:56:27 PM »
Some examples 8-)
Code: [Select]
http://www.theswamp.org/index.php?topic=29153.0  Align Text to Curve by Lee Mac
http://www.cadtutor.net/forum/showthread.php?37646-Align-Text-to-Curve
http://www.theswamp.org/index.php?topic=33735.0  Slinky Text by Lee Mac
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ozimad

  • Guest
Re: linked/synchronized/ entities and objects
« Reply #3 on: August 24, 2010, 03:52:37 AM »
Code: [Select]
(defun c:rtc2 (/ c1 c2 objlst obj_reactor p1 p2 rad vgad vgao vgms)
(vl-load-com)
(setq vgao (vlax-get-acad-object))
(setq vgad (vla-get-activedocument vgao))
(setq vgms (vla-get-modelspace vgad))
(setq p1 '(0 0 0))
(setq p2 '(5 5 0))
(setq rad 0.5)
(setq c1 (vla-addCircle vgms (vlax-3d-point p1) rad))
(vla-put-color c1 acred)
(setq c2 (vla-addline vgms (vlax-3d-point p1) (vlax-3d-point p2) ))
(vla-put-color c2 acblue)
(setq objlst (list c1 c2))
(setq obj_reactor (vlr-object-reactor
objlst
nil
'((:vlr-modified . callback2))))
)

(defun callback2 (notifier-object obj_reactor parameter-list
/ objlist newcenter)
(setq objlist (vlr-owners obj_reactor))
(print (setq newcenter (vlax-safearray->list (vlax-variant-value (vla-get-center notifier-object)))))
(if
(= notifier-object (nth 0 objlist))
(vla-put-startpoint (nth 1 objlist)  (vlax-3d-point newcenter))
(vla-put-center (nth 0 objlist)   (vlax-3d-point newcenter))
))
I found some code and trying to find out how thinks work, I want line start point to follow circle center point, and circle centre point to follow line startpoint.
Can some body please show me my mistake  :-)
Thanks a lot!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: linked/synchronized/ entities and objects
« Reply #4 on: August 24, 2010, 07:39:32 AM »
You will need two reactors, one for each object.
When the line is modified the line reactor should move the circle.
When the circle is moved the circle reactor should modify the line.
If both are Moved then nothing should be done, as you can not modify a the object tied to the reactor
as that would fire the reactor again and again.

I am off to work so I can't look for the "Circle Line Reactor" example. I have it some where.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: linked/synchronized/ entities and objects
« Reply #5 on: August 24, 2010, 08:03:38 AM »
I remember Kerry posted something a while back - either using two reactors, or perhaps adding both objects to the owner list and identifying which called the reactor by the object argument in the callback function.

Lee

ozimad

  • Guest
Re: linked/synchronized/ entities and objects
« Reply #6 on: August 24, 2010, 08:16:29 AM »
i difined 2 reactors.
How can i save them?
When i close drawing ther are not active anymore.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: linked/synchronized/ entities and objects
« Reply #7 on: August 24, 2010, 02:45:23 PM »
i difined 2 reactors.
How can i save them?
When i close drawing ther are not active anymore.

Transcient reactors are not active after the drawing closes. Persistent reactors will be, but I would advise against these. Most people rebuild the reactor using handles stored in perhaps xData or lData, or a dictionary.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: linked/synchronized/ entities and objects
« Reply #8 on: August 24, 2010, 04:44:37 PM »
i difined 2 reactors.
How can i save them?
When i close drawing ther are not active anymore.

Transcient reactors are not active after the drawing closes. Persistent reactors will be, but I would advise against these. Most people rebuild the reactor using handles stored in perhaps xData or lData, or a dictionary.

Object reactors are a cool idea in theory, but are a serious PITA to manage.  Especially true when drawings go out of your control or you have to manage more than a few per drawing.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ozimad

  • Guest
Re: linked/synchronized/ entities and objects
« Reply #9 on: November 05, 2010, 04:25:35 AM »
It took time to learn reactors, a nice and powerful tool...  :-)
Now its time to learn how to remove them!  :pissed: it looks like a cannot simply delete elements used by reactors. I think need to remove the reactor and then the element.
Anyone to help? How to do that? there is a lack of info on the net, about reactors, especially in examples.
Thanks in advance!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: linked/synchronized/ entities and objects
« Reply #10 on: November 05, 2010, 05:15:49 AM »
I've just started working with reactors myself.
To remove reactors try this:
Code: [Select]
(mapcar 'vlr-pers-release (vlr-pers-list)) ; make all persistent reactors transient
(vlr-remove-all) ; deactivates all reactors

ozimad

  • Guest
Re: linked/synchronized/ entities and objects
« Reply #11 on: November 05, 2010, 05:34:09 AM »
But i need to remove some of them, not all

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: linked/synchronized/ entities and objects
« Reply #12 on: November 05, 2010, 06:30:31 AM »
If you store a reference to the reactor object in a (global) variable:
Code: [Select]
<snip>
  (setq *obj_reactor*
    (vlr-object-reactor
      objlst
      nil
      '((:vlr-modified . callback2))
    )
  )
<snip>
You can do this:
Code: [Select]
<snip>
  (vlr-remove *obj_reactor*) ; deactivate the reactor
<snip>
  (vlr-add *obj_reactor*); reactivate the reactor
<snip>

If you want to disable a certain category of reactors you can do something like this:
Code: [Select]
<snip>
  (mapcar
    'vlr-remove
    (setq allCommandReactors (apply 'append (mapcar 'cdr (vlr-reactors :VLR-Command-Reactor))))
  )
<snip>
  (mapcar 'vlr-add allCommandReactors)
<snip>

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: linked/synchronized/ entities and objects
« Reply #13 on: November 05, 2010, 07:34:34 AM »
I tend to manipulate the reactors using the reactor data (vlr-data), as IMO, this is more reliable than a global variable - hence, to retrieve a specific reactor object, I use such functions as:

Code: [Select]
;;----------------=={ Get Reactor Object }==------------------;;
;;                                                            ;;
;;  Returns the reactor object of the specified type          ;;
;;  associated with the application data supplied             ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  data - reactor application data                           ;;
;;  typ  - Type of reactor to query, eg :vlr-object-reactor   ;;
;;------------------------------------------------------------;;
;;  Returns: VLA Reactor Object, else nil                     ;;
;;------------------------------------------------------------;;

(defun _GetReactorObject ( data typ )
  (vl-some
    (function
      (lambda ( reactor )
        (if (eq data (vlr-data reactor)) reactor)
      )
    )
    (cdar (vlr-reactors typ))
  )
)

Then release the reactor returned.

This method is demonstrated in this thread:

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


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: linked/synchronized/ entities and objects
« Reply #14 on: November 05, 2010, 08:09:09 AM »
@ Lee Mac:
Of course several reactors of the same type can have the same (e.g. nil) data...

BTW: like Lee I should have used cdar as well...
Old:
Code: [Select]
    (setq allCommandReactors (apply 'append (mapcar 'cdr (vlr-reactors :VLR-Command-Reactor))))New:
Code: [Select]
    (setq allCommandReactors (cdar (vlr-reactors :VLR-Command-Reactor)))