Author Topic: Problem with vlr-object-reactor  (Read 3414 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Problem with vlr-object-reactor
« on: February 26, 2012, 05:44:06 AM »
Hello everyone,
I have big problems to understand the reactor, I can not understand their logic.  :ugly:
I hope to understand it with your help.

At this time I wrote this code:

Code: [Select]
(defun c:test ()
  (setq OGG1 (car (entsel)))

  (setq collegaReactor
    (vlr-object-reactor (list (vlax-ename->vla-object OGG1)) "NOMEAPP"
      '(
        ;(:vlr-erased . reactor_namedefun1)
        ;(:vlr-cancelled . reactor_namedefun2)
        (:vlr-modified . reactor_namedefun3)
        ;(:vlr-openedForModify . reactor_namedefun4)
       )
    )
  )
  (vlr-pers collegaReactor)
)

OGG1 is a polyline that I stretch using the grips.
My problem is to derive the coordinates of the first vertex of the polyline before it is modified by the operation of stretching.
I then wrote:

Code: [Select]
(defun reactor_namedefun3 (notifier-object reactor-object parameter-list / )
      (if (OR (= (getvar "CMDNAMES") "STRETCH")(= (getvar "CMDNAMES") "GRIP_STRETCH"))
        (progn
          (setq OGG1 (vlax-vla-object->ename notifier-object))
          (setq P (vall 10 OGG1)) ;<--------------------------------------------------------------------------
        )
      )
)
     
(defun vall (x ent)(if (/= ent nil)(cdr (assoc x (entget ent)))))

If I stretch the polyline using a vertex other than the first which has been generated "P" is correct, but if I stretch the polyline using the first vertex with which it was generated the result of P are the target coordinates.
How can I obtain the coordinates of "P" before they are changed!? :-o

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with vlr-object-reactor
« Reply #1 on: February 26, 2012, 11:43:16 AM »
I add that I noticed that I can use with "vlr-modified" also ":vlr-copied".

:vlr-copied, in fact, is started before the change of the polyline and thus the coordinates of "P" are calculated correctly.

But if I decide to remove a vertex using the context menu that appears after selecting grips the event: vlr-copied does not start  :realmad:

Do you have any advice?
it is from this morning that I try to solve the problem. :-(

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with vlr-object-reactor
« Reply #2 on: February 27, 2012, 06:36:03 AM »
Nobody can help me?  :cry:  :cry:
Please, have hours and hours turn around this seemingly simple problem ...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Problem with vlr-object-reactor
« Reply #3 on: February 27, 2012, 07:45:19 AM »
It is quiet here over the weekends as we are out Fishing, Boating and playing tennis.  8-)

Not sure of your intent but you can not modify an object from a call to an Object Reactor.
If you want to prevent a stretch by modifying a pline after the stretch that is stretching it back
to it's original position you must use a Command Reactor.

Note: if there is a method to use an Object Reactor in this way I have not seen it or forgot it. :-)
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.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with vlr-object-reactor
« Reply #4 on: February 28, 2012, 01:30:02 AM »
Hello CAB,
Thank you for your reply.
Unfortunately, if I want to bring to eat at home I have to work on Sunday too :cry:
However, sometimes I'm going to fish :lol:


It seems to me that the reactors is a powerful tool, but they always stop at the crucial moment :?
Initially I tried with the command reactors, but I had to stop to the problem I have indicated in this post:

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

I hope you can help me understand how these reactors, I would love
learn it!

Tararykov

  • Guest
Re: Problem with vlr-object-reactor
« Reply #5 on: February 28, 2012, 07:21:33 AM »
Sorry for my bad English. Lupo76, if I understood your question
How can I obtain the coordinates of "P" before they are changed!? :-o

Code - Auto/Visual Lisp: [Select]
  1. (defun commandWillStart(reac data / nbr obj ed)
  2.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  3.     (if (setq nbr (cadr (ssgetfirst)))
  4.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "LWPOLYLINE")
  5.         (setq p (cdr (assoc 10 ed))) ; first vertex before change
  6.         )
  7.       )
  8.     )
  9. )
  10.  
  11. (defun commandEnded(reac data / nbr obj ed)
  12.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  13.     (if (setq nbr (cadr (ssgetfirst)))
  14.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "LWPOLYLINE")
  15.         (setq p (cdr (assoc 10 ed))); first vertex after change
  16.         )
  17.       )
  18.     )
  19. )
  20.  
  21. (setq Cmnd_Reac (vlr-command-reactor "Command reactor: "
  22.                   (list '(:VLR-commandWillStart . commandWillStart)
  23.                         '(:VLR-commandEnded . commandEnded)
  24.                         )
  25.                   )
  26.       )
  27.  

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with vlr-object-reactor
« Reply #6 on: February 28, 2012, 08:06:03 AM »
Sorry, your code will only work if I change the polylines with the grips, but if I use the command "STRETCH" is not working.  :cry:
Do you have any solution for this problem?

ribarm

  • Gator
  • Posts: 3304
  • Marko Ribar, architect
Re: Problem with vlr-object-reactor
« Reply #7 on: February 28, 2012, 09:14:00 AM »
Yes it doesn't work with "STRETCH" command, but I've managed to make it work with "GRIP_STRETCH" applied on picked grip (can be any - not only start one), and one more limitation : LWPOLYLINE must be closed so when changing of start vertex of pline is applied, if pline is closed it doesn't change its shape...

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun commandWillStart(reac data / nbr obj ed p)
  3.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  4.     (if (setq nbr (cadr (ssgetfirst)))
  5.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "LWPOLYLINE")
  6.         (progn
  7.           (setq p (cdr (assoc 10 ed))) ; first vertex before change
  8.           (princ p)
  9.         )
  10.       )
  11.     )
  12.   )
  13. )
  14.  
  15. (defun commandEnded(reac data / nbr obj ed p)
  16.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  17.     (if (setq nbr (cadr (ssgetfirst)))
  18.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "LWPOLYLINE")
  19.         (progn
  20.           (setq p (cdr (assoc 10 ed))); first vertex after change
  21.           (princ p)
  22.         )
  23.       )
  24.     )
  25.   )
  26. )
  27.  
  28. (setq Cmnd_Reac (vlr-command-reactor "Command reactor: "
  29.                   (list '(:VLR-commandWillStart . commandWillStart)
  30.                         '(:VLR-commandEnded . commandEnded)
  31.                   )
  32.                 )
  33. )
  34.  
  35. (defun c:STPLVERT ( / E EC ED EDD EDDD EDDD1 EDDD2 EDDD3 I M N NEWED PT Q )
  36. (setq e (entsel "\nPick vertex you want to stretch on LWPOLYLINE - MUST BE CLOSED PLINE"))
  37. (setq pt (cadr e))
  38. (setq pt (osnap pt "_end"))
  39. (setq ed (entget (car e)))
  40. (setq edd nil)
  41. (setq q -1)
  42. (while (< q 0)
  43. (setq ec (car ed))
  44. (setq ed (cdr ed))
  45. (if (eq (car ec) 10) (progn (setq ed (cons ec ed)) (setq edd (reverse edd)) (setq q 1)) (setq edd (cons ec edd)))
  46. ))
  47. (setq eddd nil)
  48. (setq eddd1 nil)
  49. (setq eddd2 nil)
  50. (setq eddd ed)
  51. (setq n (* m 4))
  52. (setq i 0)
  53. (foreach ec eddd
  54. (setq i (+ i 1))
  55. (if (<= i n)
  56. (setq eddd1 (cons ec eddd1))
  57. )
  58. (if (> i n)
  59. (setq eddd2 (cons ec eddd2))
  60. )
  61. ))
  62. (setq eddd1 (reverse eddd1))
  63. (setq eddd2 (cdr eddd2))
  64. (setq eddd2 (reverse eddd2))
  65. (setq eddd3 '((210 0.0 0.0 1.0)))
  66. (setq newed (append edd eddd2 eddd1 eddd3))
  67. (entmod newed)
  68. (entupd (car e))
  69. )
  70.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3304
  • Marko Ribar, architect
Re: Problem with vlr-object-reactor
« Reply #8 on: February 28, 2012, 01:46:39 PM »
Here is variant with assocn sub-function... (you must nil variable "m" after execution)... No limitations - lwpolyline can be opened and start vertex is not changed...

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun commandWillStart ( reac data / nbr obj ed p )
  3.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  4.     (if (setq nbr (cadr (ssgetfirst)))
  5.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "LWPOLYLINE")
  6.         (progn
  7.           (setq p (cdr (assocn m 10 ed))) ; vertex before change
  8.           (princ p)
  9.         )
  10.       )
  11.     )
  12.   )
  13. )
  14.  
  15. (defun commandEnded ( reac data / nbr obj ed p )
  16.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  17.     (if (setq nbr (cadr (ssgetfirst)))
  18.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "LWPOLYLINE")
  19.         (progn
  20.           (setq p (cdr (assocn m 10 ed))); vertex after change
  21.           (princ p)
  22.         )
  23.       )
  24.     )
  25.   )
  26. )
  27.  
  28. (setq Cmnd_Reac (vlr-command-reactor "Command reactor: "
  29.                   (list '(:VLR-commandWillStart . commandWillStart)
  30.                         '(:VLR-commandEnded . commandEnded)
  31.                   )
  32.                 )
  33. )
  34.  
  35. (defun assocn ( n code lst )
  36.   (if (/= lst nil)
  37.     (progn
  38.       (repeat (- n 1)
  39.         (setq lst (cdr (member (assoc code lst) lst)))
  40.       )
  41.     )
  42.     (princ "\nEntity data list (DXF list) not specified")
  43.   )
  44.   (assoc code lst)
  45. )
  46.  
  47. (defun c:STPLVERT ( / e ed pt )
  48.   (setq e (entsel "\nPick vertex you want to stretch on LWPOLYLINE"))
  49.   (setq pt (cadr e))
  50.   (setq pt (osnap pt "_end"))
  51.   (setq ed (entget (car e)))
  52.   (setq m (+ (fix (vlax-curve-getparamatpoint (car e) pt)) 1))
  53. )
  54.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3304
  • Marko Ribar, architect
Re: Problem with vlr-object-reactor
« Reply #9 on: February 29, 2012, 10:23:10 AM »
Here is version for SPLINE entity... It should work on ACAD where OSMODE 16384 is supported (3DOSNAP - Knot)...

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun commandWillStart ( reac data / nbr obj ed p )
  3.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  4.     (if (setq nbr (cadr (ssgetfirst)))
  5.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "SPLINE")
  6.         (progn
  7.           (setq p (cdr (nth m ed))) ; vertex before change
  8.           (princ p)
  9.         )
  10.       )
  11.     )
  12.   )
  13. )
  14.  
  15. (defun commandEnded ( reac data / nbr obj ed p )
  16.   (if (member (car data) (list "STRETCH" "GRIP_STRETCH"))
  17.     (if (setq nbr (cadr (ssgetfirst)))
  18.       (if (= (cdr (assoc 0 (setq ed (entget (setq obj (ssname nbr 0)))))) "SPLINE")
  19.         (progn
  20.           (setq p (cdr (nth m ed))); vertex after change
  21.           (princ p)
  22.         )
  23.       )
  24.     )
  25.   )
  26. )
  27.  
  28. (setq Cmnd_Reac (vlr-command-reactor "Command reactor: "
  29.                   (list '(:VLR-commandWillStart . commandWillStart)
  30.                         '(:VLR-commandEnded . commandEnded)
  31.                   )
  32.                 )
  33. )
  34.  
  35. (defun assoccountbyvalue ( lst val / k kk )
  36.   (setq k -1)
  37.   (foreach x lst
  38.     (setq k (1+ k))
  39.     (if (and (eq kk nil) (equal (cdr x) val 1e-8)) (setq kk k))
  40.   )
  41.   kk
  42. )
  43.  
  44. (defun c:STSPLVERT ( / osm e ed pt )
  45.   (setq osm (getvar 'osmode))
  46.   (setvar 'osmode 16384)
  47.   (setq pt (getpoint "\nPick vertex you want to stretch on SPLINE"))
  48.   (setq e (ssname (ssget pt) 0))
  49.   (setq ed (entget e))
  50.   (setq m (assoccountbyvalue ed pt))
  51.   (setvar 'osmode osm)
  52. )
  53.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with vlr-object-reactor
« Reply #10 on: March 01, 2012, 01:43:11 AM »
Hello ribarm,
Thank you for your concern, but I have to create a function that can work in any situation: the STRETCH command and with the grips.
I came to mint a new solution for storing in advance the coordinates of the vertex as xdata :ugly:

I have to work a bit  :-D