Author Topic: vlr-owner-remove doesn't work  (Read 322 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 695
vlr-owner-remove doesn't work
« on: July 03, 2019, 10:39:19 AM »
Hi guys,
I rarely deal with object reactors, so today decided to do some practice by utilising the vlr-owner* functions.. and this got me confused
From the docs : Removes an object from the list of owners of an object reactor

Manual practice/testing on a object reactor:
Code - Auto/Visual Lisp: [Select]
  1. _$ (defun CB:ObjReactor ( ownr rtr args )
  2.   (princ "\nReaction occured")
  3. ); defun
  4. >> CB:OBJREACTOR
  5.  
  6. _$ (foreach rtr (cdar (vlr-reactors :VLR-Object-Reactor)) (if (= "test" (vlr-data rtr)) (vlr-remove rtr)) )
  7. >> nil
  8.  
  9. _$ (setq *TheReactor*
  10.     ( ; Selected a LWPOLYLINE and a CIRCLE
  11.       (lambda ( / SS i L)
  12.         (if (setq SS (ssget "_:L-I"))
  13.           (repeat (setq i (sslength SS))
  14.             (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  15.           )
  16.         )
  17.         (reverse L)
  18.       ); lambda
  19.      
  20.     )
  21.     "test"
  22.     (mapcar '(lambda (x) (cons x 'CB:ObjReactor)) (vlr-reaction-names :VLR-Object-Reactor))
  23.   ); vlr-object-reactor
  24. ); setq *TheReactor*
  25. >> #<VLR-Object-Reactor>
  26.  
  27. _$ (vlr-owners *TheReactor*)
  28. >> (#<VLA-OBJECT IAcadLWPolyline 000000ed9a689968> #<VLA-OBJECT IAcadCircle 000000edf6e32c18>)
  29.  
  30. _$ ( ; Selected an ARC
  31.   (lambda ( / SS i)
  32.     (if (setq SS (ssget "_:L-I"))
  33.       (progn
  34.         (repeat (setq i (sslength SS))
  35.           (vlr-owner-add *TheReactor* (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  36.         )
  37.         (vlr-owners *TheReactor*)
  38.       )
  39.     )
  40.   ); lambda
  41. )
  42. >> Reaction occured
  43. >> (#<VLA-OBJECT IAcadArc 000000ed9da0f528> #<VLA-OBJECT IAcadLWPolyline 000000ed9a689968> #<VLA-OBJECT IAcadCircle 000000edf6e32c18>)
  44.  
  45. _$ ( ; Selected the ARC and the CIRCLE
  46.   (lambda ( / SS i)
  47.     (if (setq SS (ssget "_:L-I"))
  48.       (progn
  49.         (repeat (setq i (sslength SS))
  50.           (vlr-owner-remove *TheReactor* (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  51.         )
  52.         (vlr-owners *TheReactor*)
  53.       )
  54.     )
  55.   ); lambda
  56. )
  57. >> (#<VLA-OBJECT IAcadArc 000000ed9da0f528> #<VLA-OBJECT IAcadLWPolyline 000000ed9a689968> #<VLA-OBJECT IAcadCircle 000000edf6e32c18>)
  58.  
  59. _$ (vlr-owners *TheReactor*)
  60. >> (#<VLA-OBJECT IAcadArc 000000ed9da0f528> #<VLA-OBJECT IAcadLWPolyline 000000ed9a689968> #<VLA-OBJECT IAcadCircle 000000edf6e32c18>)
  61.  
  62.  
  63. _$ (foreach x (vlr-owners *TheReactor*) ; Alternative try
  64.   (if (member (vla-get-ObjectName x) '("AcDbArc" "AcDbCircle"))
  65.     (vlr-owner-remove *TheReactor* x)
  66.   )
  67. )
  68. >> #<VLA-OBJECT IAcadCircle 000000edf6e32c18>
  69.  
  70. _$ (vlr-owners *TheReactor*) ; the alternative doesn't work -
  71. >> (#<VLA-OBJECT IAcadArc 000000ed9da0f528> #<VLA-OBJECT IAcadLWPolyline 000000ed9a689968> #<VLA-OBJECT IAcadCircle 000000edf6e32c18>)

One could try it by himself, I'm with ACAD 2017 BTW.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

ribarm

  • Water Moccasin
  • Posts: 2122
  • Marko Ribar, architect
Re: vlr-owner-remove doesn't work
« Reply #1 on: July 05, 2019, 04:51:34 AM »
Tested on A2018... The same thing...

Code - Auto/Visual Lisp: [Select]
  1. _$ (defun CB:ObjReactor ( ownr rtr args )
  2. (_> (princ "\nReaction occured")
  3. (_> )
  4. CB:OBJREACTOR
  5. _$ (foreach rtr (cdar (vlr-reactors :VLR-Object-Reactor)) (if (= "test" (vlr-data rtr)) (vlr-remove rtr)) )
  6. nil
  7. _$ (setq *TheReactor*
  8. ((_> ( ; Selected a LWPOLYLINE and a CIRCLE
  9. (((_> (lambda ( / SS i L )
  10. ((((_> (if (setq SS (ssget "_:L-I"))
  11. (((((_> (repeat (setq i (sslength SS))
  12. ((((((_> (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  13. ((((((_> )
  14. (((((_> )
  15. ((((_> (reverse L)
  16. ((((_> ); lambda
  17. (((_> )
  18. ((_> "test"
  19. ((_> (mapcar '(lambda ( x ) (cons x 'CB:ObjReactor)) (vlr-reaction-names :VLR-Object-Reactor))
  20. ((_> ); vlr-object-reactor
  21. (_> ); setq *TheReactor*
  22. #<VLR-Object-Reactor>
  23. _$ (vlr-owners *TheReactor*)
  24. (#<VLA-OBJECT IAcadLWPolyline 0000028ce2f9f738> #<VLA-OBJECT IAcadCircle 0000028ce2f9f138>)
  25. _$ ( ; Selected an ARC
  26. (_> (lambda ( / SS i )
  27. ((_> (if (setq SS (ssget "_:L-I"))
  28. (((_> (progn
  29. ((((_> (repeat (setq i (sslength SS))
  30. (((((_> (vlr-owner-add *TheReactor* (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  31. (((((_> )
  32. ((((_> (vlr-owners *TheReactor*)
  33. ((((_> )
  34. (((_> )
  35. ((_> ); lambda
  36. (_> )
  37.  
  38. Reaction occured(#<VLA-OBJECT IAcadArc 0000028ce2de18c8> #<VLA-OBJECT IAcadLWPolyline 0000028ce2f9f738> #<VLA-OBJECT IAcadCircle 0000028ce2f9f138>)
  39. _$ ( ; Selected the ARC and the CIRCLE
  40. (_> (lambda ( / SS i )
  41. ((_> (if (setq SS (ssget "_:L-I"))
  42. (((_> (progn
  43. ((((_> (repeat (setq i (sslength SS))
  44. (((((_> (vlr-owner-remove *TheReactor* (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  45. (((((_> )
  46. ((((_> (vlr-owners *TheReactor*)
  47. ((((_> )
  48. (((_> )
  49. ((_> ); lambda
  50. (_> )
  51. (#<VLA-OBJECT IAcadArc 0000028ce2de18c8> #<VLA-OBJECT IAcadLWPolyline 0000028ce2f9f738> #<VLA-OBJECT IAcadCircle 0000028ce2f9f138>)
  52. _$ (vlr-owners *TheReactor*)
  53. (#<VLA-OBJECT IAcadArc 0000028ce2de18c8> #<VLA-OBJECT IAcadLWPolyline 0000028ce2f9f738> #<VLA-OBJECT IAcadCircle 0000028ce2f9f138>)
  54. _$ (foreach x (vlr-owners *TheReactor*) ; Alternative try
  55. (_> (if (member (vla-get-ObjectName x) '("AcDbArc" "AcDbCircle"))
  56. ((_> (vlr-owner-remove *TheReactor* x)
  57. ((_> )
  58. (_> )
  59. #<VLA-OBJECT IAcadCircle 0000028ce2f9f138>
  60. _$ (vlr-owners *TheReactor*) ; the alternative doesn't work -
  61. (#<VLA-OBJECT IAcadArc 0000028ce2de18c8> #<VLA-OBJECT IAcadLWPolyline 0000028ce2f9f738> #<VLA-OBJECT IAcadCircle 0000028ce2f9f138>)
  62. _$
  63.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2122
  • Marko Ribar, architect
Re: vlr-owner-remove doesn't work
« Reply #2 on: July 05, 2019, 07:27:40 AM »
All I could find out is to reconstruct reactor :

Code - Auto/Visual Lisp: [Select]
  1. (defun CB:ObjReactor ( owner reactor lstename )
  2.   (princ "\nReaction occured")
  3. )
  4.  
  5. (setq *TheReactor*
  6.     (
  7.      (lambda ( / SS i L )
  8.        (if (setq SS (ssget "_:L-I"))
  9.          (repeat (setq i (sslength SS))
  10.            (setq L (cons (vlax-ename->vla-object (ssname SS (setq i (1- i)))) L))
  11.          )
  12.        )
  13.        (reverse L)
  14.      )
  15.     )
  16.     "test"
  17.     (mapcar '(lambda ( x ) (cons x 'CB:ObjReactor)) (vlr-reaction-names :VLR-Object-Reactor))
  18.   )
  19. )
  20.  
  21. (princ "\n")
  22. (princ (vlr-owners *TheReactor*))
  23.  
  24. (defun _setq-reactor-vlr-owner-remove ( reactor owner / owners data typ reactions )
  25.   (setq owners (vlr-owners reactor))
  26.   (setq owners (vl-remove owner owners))
  27.   (setq data (vlr-data reactor))
  28.   (setq typ (vlr-type reactor))
  29.   (if (= (type data) 'str)
  30.     (setq reactions (vlr-reactions reactor))
  31.   )
  32.   (vlr-remove reactor)
  33.   (if (= (type data) 'str)
  34.     ((eval (read (substr (vl-prin1-to-string typ) 2))) owners data reactions)
  35.     ((eval (read (substr (vl-prin1-to-string typ) 2))) owners data)
  36.   )
  37. )
  38.  
  39. (setq *TheReactor* (_setq-reactor-vlr-owner-remove *TheReactor* (setq *owner* (car (vlr-owners *TheReactor*)))))
  40.  
  41. (princ "\n")
  42. (princ (vlr-owners *TheReactor*))
  43.  
  44. (vlr-owner-add *TheReactor* *owner*)
  45.  
  46. (princ "\n")
  47. (princ (vlr-owners *TheReactor*))
  48.  

So if you firstly selected 3 entities, *TheReactor* should have after calling sub 2 owners, as first one is removed and then at the end global variable *owner* is added with (vlr-owner-add) function which works well...
HTH., M.R.
« Last Edit: July 05, 2019, 10:20:42 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2122
  • Marko Ribar, architect
Re: vlr-owner-remove doesn't work
« Reply #3 on: July 05, 2019, 10:39:27 AM »
I've updated sub function to be better... No need for callback function as argument... It's just like it should be : reactor and owner as arguments...

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

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 695
Re: vlr-owner-remove doesn't work
« Reply #4 on: July 06, 2019, 09:18:35 PM »
Thanks for confirming, Marco -
Looks like there are few threads over here, regarding this vlr-owners-remove function, where I participated but haven't noticed that this function actually doesn't work.
 http://www.theswamp.org/index.php?topic=52995.msg578082#msg578082
 http://www.theswamp.org/index.php?topic=52970.msg577851#msg577851
 http://www.theswamp.org/index.php?topic=53048.msg578824#msg578824

So for my other test program, I had to substitute my previous code block..
Code - Auto/Visual Lisp: [Select]
  1. ( ; vlr-owner-remove doesn't work - http://www.theswamp.org/index.php?topic=55299.0
  2.   (lambda ( / SS rtr )
  3.     (if
  4.       (and
  5.         (setq rtr (vl-some (function (lambda (x) (if (= rtrnm (vlr-data x)) x))) (cdar (vlr-reactors :VLR-Object-Reactor))))
  6.         (setq SS (ssget "_:L-I"))
  7.       )
  8.       (
  9.         (lambda (SS / i)
  10.           (repeat (setq i (sslength SS))
  11.             (vlr-owner-remove rtr (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  12.           )
  13.         ); lambda
  14.         SS
  15.       )
  16.     ); if SS
  17.   ); lambda
  18. )

..with this one..

Code - Auto/Visual Lisp: [Select]
  1. ( ; vlr-owner-remove doesn't work, hence redefine the reactor
  2.   (lambda ( / rtr notifiers SS )
  3.     (if
  4.       (and
  5.         (setq rtr (vl-some (function (lambda (x) (if (= rtrnm (vlr-data x)) x))) (cdar (vlr-reactors :VLR-Object-Reactor))))
  6.         (setq notifiers (vlr-owners rtr))
  7.         (setq SS (ssget "_:L-I"))
  8.       )
  9.       (progn
  10.         (foreach rtr (cdar (vlr-reactors :VLR-Object-Reactor)) (if (= rtrnm (vlr-data rtr)) (vlr-remove rtr)) )
  11.         (vlr-object-reactor
  12.           (vl-remove-if '(lambda (x) (ssmemb (vlax-vla-object->ename x) SS)) notifiers)
  13.           rtrnm
  14.           (mapcar '(lambda (x) (cons x 'CB:ObjReactor)) (vlr-reaction-names :VLR-Object-Reactor))
  15.         ); vlr-object-reactor
  16.       ); progn
  17.     ); if SS
  18.   ); lambda
  19. )

Basically reconstructing the reactor like you did - although the point is regarding the vlr-owners-remove function.  :|
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)