Author Topic: Command reactor  (Read 1177 times)

0 Members and 1 Guest are viewing this topic.

Dan113

  • Mosquito
  • Posts: 5
Command reactor
« on: March 16, 2017, 08:54:09 AM »
I am trying to modify an invisible attribute in a block. I am trying to do this using vlr-commandended but im unsure how to get the ENAME of the block on exiting either block editor or ref editor. Im new to reactors and struggling a little. All i need is the ename of the block but its driving me mad trying to work it out. Can anyone point me in the right direction?

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Command reactor
« Reply #1 on: March 16, 2017, 12:54:39 PM »
I think that you have to use vlr-acdb-reactor with :vlr-ObjectModified event, so in the callback function you should get the block's ename as an argument.
But I'm also a reactor newbie so I'm not sure.
Perhaps elaborate more what reactor you currently use and what you're trying to achieve.
(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)
  )
)
vevo.bg

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Command reactor
« Reply #2 on: March 16, 2017, 12:58:51 PM »
That's essentially correct - react to the database change by logging the entity that was modified.  Then in the command-ended reactor read the logged entity ID, disable the database reactor (so you don't loop), change it, then re-enable the database reactor.

Note that you can run into problems when entities can be direct-edited without issuing a command e.g. editing block attributes via the Properties panel.
If you are going to fly by the seat of your pants, expect friction burns.

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

Dan113

  • Mosquito
  • Posts: 5
Re: Command reactor
« Reply #3 on: March 17, 2017, 07:13:15 AM »
Here is what i have so far, all im trying to do is add an invisible attribute to the block. Whether its been modified or not, its just an indication of modifications or potential modifications.

All im managing to get is the block record ename, im not entirely sure if its possible to add an attribute to that?

initial starting test code from a lee mac post

Code: [Select]
(defun c:test nil

  (if (not *react*)
    (setq *react*
      (vlr-command-reactor nil
        (list
          (cons :VLR-commandWillStart 'callback)
        )
      )
    )
    (progn
      (vlr-remove *react*)
      (setq *react* nil)
    )
  )

  (princ)
)

(defun callback ( reactor parameters )

  (cond
    ((or
       (= (car parameters) "BEDIT")
       (= (car parameters) "REFEDIT")
     )
     (alert
       (strcat
"Reactor: " (vl-prin1-to-string reactor)
"\nList: "    (vl-prin1-to-string parameters)
       )
     )
     (setq *dbreact*
      (vlr-acdb-reactor nil
        (list
          (cons :vlr-ObjectModified 'omcallback)
        )
      )
     )
     (setq *cereact*
      (vlr-command-reactor nil
        (list
          (cons :VLR-commandended 'cecallback)
        )
      )
     )
    )
    (t
     (princ
       (strcat
"\nNot block edit\n"
       )
     )
    )
  )

  (princ)
)
 
(defun omcallback ( reactor parameters )

  (setq obj-ename (cadr parameters))
  (vlr-remove *dbreact*)
  (setq *dbreact* nil)
)

(defun cecallback ( reactor parameters )

  (cond
    ((or
       (= (car parameters) "BCLOSE")
       (= (car parameters) "REFCLOSE")
     )
     (vlr-remove *cereact*)
     (setq *cereact* nil)
    )
  )

)