Author Topic: Question: Vlr-object-reactor  (Read 5687 times)

0 Members and 1 Guest are viewing this topic.

Dream.Fei

  • Guest
Question: Vlr-object-reactor
« on: April 28, 2007, 10:41:37 PM »
This's Object-reactor test.
when Circle's radius or line's endpoint changed, I want the line's startpoint chang too. but in this lisp file , only  Circle radius change can modifi line startpoint.
Need help!
Code: [Select]
(defun c:test (/ CEN CIRCLE CLA-LST ENDPOINT LINE RAD)
  (if (setq cen (getpoint "\nCenters:"))
    (if (setq rad (getdist cen "\nRadius:"))
      (if (setq
    circle (vla-addcircle *ModelSpace* (vlax-3d-point cen) rad)
  )
(setq cla-lst (cons circle cla-lst))
      )
    )
  )
  (if (setq endpoint (getpoint cen "\nLine EndPoint:"))
    (if (setq line (vla-addline
     *ModelSpace*
     (vlax-3d-point cen)
     (vlax-3d-point endpoint)
   )
)
      (setq cla-lst (cons line cla-lst))
    )
  )
  (if cla-lst
    (vlr-object-reactor
      cla-lst
      cla-lst
      '((:vlr-modified . *object-reactor*))
    )
  )
)
(defun *object-reactor*
       (obj reactor part-list / CEN CIRCLE LINE P10 P11 RAD)
  (foreach syb (vlr-data reactor)
    (if (and (eq 'VLA-OBJECT (type syb))
     (vlax-write-enabled-p syb) ; test if object can be modified
     (vlax-read-enabled-p obj) ; test if object can be read
)
      (if (vlax-property-available-p syb 'centers)
(progn
  (setq cen (vlax-safearray->list
      (vlax-variant-value (vla-get-center syb))
    )
  )
  (setq rad (vla-get-radius syb))
  (setq line (car (vlr-data reactor)))
  (setq p11 (vlax-safearray->list
      (vlax-variant-value (vla-get-endpoint line))
    )
  )
  (setq p10 (polar cen (angle cen p11) rad))
  (vla-put-startpoint line (vlax-3d-point p10))
)
(progn
  (setq circle (cadr (vlr-data reactor)))
  (setq cen (vlax-safearray->list
      (vlax-variant-value (vla-get-center circle))
    )
  )
  (setq rad (vla-get-radius circle))
  (setq p11 (vlax-safearray->list
      (vlax-variant-value (vla-get-endpoint syb))
    )
  )
  (setq p10 (polar cen (angle cen p11) rad))
  (vla-put-startpoint syb (vlax-3d-point p10))
)
      )
    )
  )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question: Vlr-object-reactor
« Reply #1 on: April 29, 2007, 12:27:24 AM »
I havenot tried your program

but ..

this looks incorrect (if (vlax-property-available-p syb 'centers)

should the property be 'center NOT 'centers ?
« Last Edit: April 29, 2007, 12:51:28 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Dream.Fei

  • Guest
Re: Question: Vlr-object-reactor
« Reply #2 on: April 30, 2007, 03:30:23 AM »
I haveed chang it to 'center.
But same, when I change EndPoint of line, can't change the StartPoint. and return error message: Automation mistake. The object is informing

« Last Edit: April 30, 2007, 03:36:21 AM by Dream.Fei »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question: Vlr-object-reactor
« Reply #3 on: April 30, 2007, 03:43:07 AM »
This's Object-reactor test.
when Circle's radius or line's endpoint changed, I want the line's startpoint chang too. but in this lisp file , only  Circle radius change can modifi line startpoint.
Need help!

Where do you want the StartPoint to change to ?

It is drawn from the center of the circle to the EndPoint.
How does changing the radius or moving the EndPoint affect the StartPoint.

I have not used your code yet. Have you tried to step through it in the VisualLisp debugger ?


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Dream.Fei

  • Guest
Re: Question: Vlr-object-reactor
« Reply #4 on: April 30, 2007, 03:54:58 AM »
Circle (radiu or center)  or Line's Endpoint changed . i want Line's startpoint change.

but now , only circle changed can modifi it . when line's Endpoint changed, return error message:
Quote
Automation mistake. The object is informing

I just started study lisp, I don't know how to Debugging in "debugger".
Quote
我希望在圆的半径或是直线的端点改变的时候,改变直线的起点.
但现在就只有在圆变化时,才能影响直线. 改变直线的端点,只返回错误信息:Automation 错误,对象正在被通知.
刚刚学LISP,还不知道如何在vl编辑器中调试.
« Last Edit: April 30, 2007, 03:59:49 AM by Dream.Fei »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question: Vlr-object-reactor
« Reply #5 on: April 30, 2007, 04:00:42 AM »
I ask again .. when you move the EndPoint, where do you WANT the StartPoint changed to ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Dream.Fei

  • Guest
Re: Question: Vlr-object-reactor
« Reply #6 on: April 30, 2007, 04:04:27 AM »
inters: line(circle's center to endpoint) circle.


I want use only one reactor (vlr-object-reactor) . don't use other reactor.
« Last Edit: April 30, 2007, 04:13:14 AM by Dream.Fei »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Question: Vlr-object-reactor
« Reply #7 on: April 30, 2007, 11:25:27 AM »
The problem is that the line object is can't be changed the way you are doing it.  Since the line is the one being changed, you can't change it by code at the same time.  What you need to do is have the object reactor make another reactor, a command ended reactor, that will change the line after the circle has changed.  Here are some links to show what I'm talking about.  Look at the code and see if you can understand it.

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

If that one doesn't help, then you can search here.  It seems that reactors have been asked about a lot here.
Tim

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

Please think about donating if this post helped you.

Dream.Fei

  • Guest
Re: Question: Vlr-object-reactor
« Reply #8 on: April 30, 2007, 12:44:48 PM »
I don't see the post what you showed to me. after read you post and try , I know what's you mean about the Line can't chang it'self by the same time.
I have done it by use vlr-editor-reactor and vlr-object-reactor.
Thank you.
Quote
Look at the code and see if you can understand it.
I can understand but I do not know how to express ~ -_-!
« Last Edit: April 30, 2007, 08:46:37 PM by Dream.Fei »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Question: Vlr-object-reactor
« Reply #9 on: April 30, 2007, 12:51:14 PM »
Glad you got it to work.  :-)
Tim

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

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Question: Vlr-object-reactor
« Reply #10 on: May 02, 2007, 02:04:11 AM »
Dream.Fei ,

It would be good if you could post your modified code so others can take advantage of what you've learnt.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Dream.Fei

  • Guest
Re: Question: Vlr-object-reactor
« Reply #11 on: May 03, 2007, 07:24:48 AM »
this is my code of this test~
Code: [Select]
(defun c:test (/ CEN CIRCLE CLA-LST ENDPOINT LINE RAD)
  (setq *ModelSpace*
(vla-get-modelspace
   (vla-get-activedocument (vlax-get-acad-object))
)
  )
  (if (setq cen (getpoint "\nCenters:"))
    (if (setq rad (getdist cen "\nRadius:"))
      (if (setq
    circle (vla-addcircle *ModelSpace* (vlax-3d-point cen) rad)
  )
(setq cla-lst (cons circle cla-lst))
      )
    )
  )
  (if (setq endpoint (getpoint cen "\nLine EndPoint:"))
    (if (setq line (vla-addline
     *ModelSpace*
     (vlax-3d-point cen)
     (vlax-3d-point endpoint)
   )
)
      (setq cla-lst (cons line cla-lst))
    )
  )
  (if cla-lst
    (vlr-object-reactor
      cla-lst
      cla-lst
      '((:vlr-modified . *object-reactor-callback*))
    )
  )
)
(defun *object-reactor-callback*
       (obj reactor part / cen rad line p11 p10)
  (if (vlax-read-enabled-p obj) ;_ Test if the object can be read
    (if (eq (vla-get-objectname obj) "AcDbCircle") ;_ if the objecat is circle
      (progn
(setq cen  (vlax-get obj "center")
      rad  (vlax-get obj "radius")
      line (car (vlr-data reactor))
      p11  (vlax-get line "EndPoint")
      p10  (polar cen (angle cen p11) rad)
)
(vla-put-startpoint line (vlax-3d-point p10));_change startpoint of line
      )
      (progn;_ if the object is "Line" Greact a Editor-reactor for it
(if (null $Line-editor-reactor)
  (setq $line-editor-reactor
(vlr-editor-reactor
   ""
   '((:vlr-commandended . *line-editor-reactor-callback*)
    )
)
  )
)
(setq *line-editor-date* (vlr-data reactor))
      )
    )
  )
  (princ)
)
(defun *line-editor-reactor-callback*
       (obj reactor / line circle cen rad p11 p10)
  (if *line-editor-date*
    (progn
      (setq line   (car *line-editor-date*);_get line
    circle (cadr *line-editor-date*);_get circle
    cen    (vlax-get circle "center");_get cetner of circle
    rad    (vlax-get circle "radius");_get reaius
    p11    (vlax-get line "EndPoint");_get line's endpoint
    p10    (polar cen (angle cen p11) rad);_New startpoint
      )
      (vla-put-startpoint line (vlax-3d-point p10))
      (vlr-remove $Line-editor-reactor);_remove Reactor
      (setq *line-editor-date* nil
    $Line-editor-reactor nil
      )
    )
  )
)
« Last Edit: May 03, 2007, 07:56:11 AM by Dream.Fei »