Author Topic: Need more help with reactors  (Read 7560 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
Need more help with reactors
« on: September 15, 2003, 07:31:04 PM »
I have this piece of code that I want called when a drawing finishes opening. I tried using vlr-command-reactor, but it would crash each time I opened a drawing or if I had to hit escape. As a vlr-dwg-reactor, it doesn't do anything. Either vlr-dwg-reactor just sucks or I'm not using it correctly. Please help.
Code: [Select]
(vlr-dwg-reactor "AnthemUpdate" '((:vlr-DwgFileOpened . updatemc)))
(defun updatemc (caller cmdset)
     (if (and (/= nil
 (vl-string-search "Anthem 22" (getvar 'dwgprefix))
     )
     (= nil (ssget "x" '((2 . "HOUSE SQFT"))))
)
 (c:upmc)
     )
)
(defun c:upmc ()
     (vl-undobegin)
     (foreach item (blocksel "LOTCOVER")
 (vla-getBoundingBox item 'll 'ur)
     )
     (setq upperleft (changeElement ll 1 ur 1))
     (redefine-block
 "P:\\LOTBLOCK\\HOUSE SQFT.dwg"  upperleft
 1.0      1.0  1.0
 0.0
)
 ;move blocks to top of house sqft.dwg
     (setq hsqft (nth 0 (blocksel "HOUSE SQFT")))
     (vla-getBoundingBox hsqft 'll 'ur)
     (setq dist (- (vlax-safearray-get-element ur 1)
  (vlax-safearray-get-element ll 1)
)
     )
     (foreach item (list "SIGN" "SIGNNEW" "fencnote" "signat")
 (setq block (blocksel item))
 (foreach item block
      (vla-move item
(vla-get-insertionpoint item)
(vla-polarpoint
     (vla-get-utility (get-active-document))
     (vla-get-insertionpoint item)
     1.5708
     dist
)
      )
 (vlax-release-object item)
 )
     )
     (vl-undoend)
     (princ)
)

Here are the other functions.
Code: [Select]
;;;-------------------------------------------------------------;
;;;-change elements in a safearray ;
;;;-------------------------------------------------------------;
(defun changeElement (var index gvar gindex)
 (vlax-safearray-put-element
      var
      index
      (vlax-safearray-get-element gvar gindex)
 )
     (vlax-make-variant var)
)
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
)
(defun blocksel (bname)
     (ssget->vla-list (ssget "x" (list (cons 2 bname))))
)
(defun redefine-block (bname inspt x y z scale)
     (vla-InsertBlock
 (vla-get-modelspace
      (get-active-document)
 )
 inspt
 bname
 (vl-variant-dbl x)
 (vl-variant-dbl y)
 (vl-variant-dbl z)
 (vl-variant-dbl scale)
     )
)
(defun vl-variant-dbl (long)
     (vlax-make-variant long vlax-vbDouble)
)

daron

  • Guest
Need more help with reactors
« Reply #1 on: September 16, 2003, 07:10:37 PM »
Is anybody trying to figure this thing out? It'd be a really sweet program if I can get it working.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9195
Need more help with reactors
« Reply #2 on: September 16, 2003, 09:58:26 PM »
I copied it, but i havent been able to look at it much. I promise to do my best to get to it tomorow.

Later,
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

daron

  • Guest
Need more help with reactors
« Reply #3 on: September 17, 2003, 10:20:54 AM »
Thanks Se7en. I don't want to be pushy, just was wondering if anybody was interested in helping.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9195
Need more help with reactors
« Reply #4 on: September 17, 2003, 12:52:02 PM »
Daron, if you want this to be run when you start a dwg then put this at the bottom of you acad.lsp file.
Code: [Select]

(updatemc)
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

daron

  • Guest
Need more help with reactors
« Reply #5 on: September 17, 2003, 02:16:38 PM »
That didn't work. The file it's written in loads in appload each time, also.

Mark

  • Custom Title
  • Seagull
  • Posts: 28673
Need more help with reactors
« Reply #6 on: September 17, 2003, 02:57:39 PM »
Quotes that might help
Quote
Copy the following inside your acaddoc,lsp or acad.lsp or save it as
mylisp.lsp and use the command APPLOAD or add it in the Startup Suite.

(vl-load-com)
(vlr-dwg-reactor nil '((:vlr-beginClose . myfunc)))

(defun myfunc (arg1 arg2)
(vla-zoomall (vlax-get-acad-object))
 (vla-save (vlax-get-property (vlax-get-acad-object) 'ActiveDocument)))

 -Luis
 ArqCOM Software
 www.arqcom.com.mx

Quote
OK I got it after I posted. Didn't take too long. I neglected the callback
variables. the working functions should look like this. I added a routine
to diaplay at the end of the save as well. Maybe this will help someone
else trying to learn these things as well. Maybe we can collect all the
posts together and make a primer ourselves.  

(defun save-yas (caller llist)
(alert "It worked  --- start save")
)

(defun save-done (caller llist)
(alert "It worked  ---  End save")
)

(defun  c:goforit()
(list
(vlr-dwg-reactor nil (list (cons :vlr-beginsave (function save-yes))))
(vlr-dwg-reactor nil (list (cons :vlr-savecomplete (function save-done))))
)
)


One more thing I found out. If you are editing your program and reloading
to test it out, be sure to clear the previous reactors. I ended u getting
three then four etc.. dialogs telling me "It workled  --- start save" Not
because it was saving three four etc.. times. It had three then four
reactors attached. The fllowing code will remove the reactors to the
dwg-reactor callbacks. Just add more to the inside list as you add reactor
types.

(defun remove-reactors()
  (MAPCAR 'VLR-REMOVE-ALL
   '(:VLR-DWG-REACTOR
    )
  ) ;_ end of mapcar
) ;_ end of defun

Then modify the code for "goforit" as follows:

(defun  c:goforit()
(remove-reactors)
(list
(vlr-dwg-reactor nil (list (cons :vlr-beginsave (function save-yes))))
(vlr-dwg-reactor nil (list (cons :vlr-savecomplete (function save-done))))
)
)

Hope it helps someone somehow somewhere, I certainly could have used it a
week or two ago,
Jason

Quote
Phillip Kenewell wrote:
>
> My question regards the Visual Lisp "vlr-" reactors in
> AutoCAD 2000. Now that AutoCAD has a multiple document
> interface, I am working on using Reactors for doing
> Automatic Modification Date stamps and Drawing logs, as
> opposed to redefining all the Save, Open, and Quit commands.

Phillip - Vlr-dwg-reactor is document-specific, and when
you set a reactor in one document, it applies only to that
document, not to new ones that are opened. Hence, you are
trying to get notification from an object to tell you when
the object is created, but the problem is that you can't
tell a non-existant object to notify you about anything,
before it exists.

You need to use an editor reactor for this, not a document
reactor.


--
/*********************************************************/
/*    Tony Tanzillo     Design Automation Consulting     */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */

Tony,

Thanks for your timely response. I heeded your advice and used an Editor
Reactor with the "commandEnded" Event, and checked for the Command "OPEN" in
the callback. (NOTE: the "beginOpen" event does not work in an editor
reactor either.) This works "ok", but does not record events such as
double-clicking on a file in Explorer, etc... Any Ideas on working around
this? Again, Thank you in advance...

Phil.

You can't rely on a command reactor to detect the opening
of a drawing, since there are ways to do it without using
any commands (such as the case you noted).

You should use the :vlr-BeginDwgOpen and :vlr-EndDwgOpen
callbacks of the editor reactor.

Tony,

I have already tried using ":vlr-beginDwgOpen" and ":vlr-endDwgOpen" with an
editor reactor (not a Dwg reactor) and it hasn't worked for me. Do I need to
load the programs in a separate namespace VLX or something like that?

I just tried, and can't get either of these two
notifications to fire under any circumstance,
including from a separate namespace VLX, and with
(vlr-set-notification <reactor> 'all-documents).

Perhaps someone at Autodesk can explain why.
TheSwamp.org  (serving the CAD community since 2003)

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9195
Need more help with reactors
« Reply #7 on: September 18, 2003, 09:59:12 AM »
Ok im getting a bit confused here, so I started from the begining. I started with your first function and here are some Questions i have.

Code: [Select]

(defun updatemc (caller cmdset)
  (if
    ;; I dont understand the use of And here.
    (and
      ;; Are you looking for a folder or a drawing?
      (/= nil (vl-string-search "Anthem 22" (getvar 'dwgprefix)))
      (= nil (ssget "x" '((2 . "HOUSE SQFT"))))
      )
    (c:upmc)
    )
  )
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

daron

  • Guest
Need more help with reactors
« Reply #8 on: September 18, 2003, 12:11:31 PM »
7, What's going to happen is if the user opens a drawing and the folder to that drawing happens to contain the phrase Anthem 22 AND the drawing has no block called "HOUSE SQFT", then run the upmc function. It is a function that in time, for this subdivision, will become obsolete. All we're doing is making it so the person that opens a drawing file in said folder, won't have to remember to place the said block in. I call it laziness and I like it.

Mark, do your quotes mean that some reactors don't work or are you saying that I've use the wrong reactor?

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9195
Need more help with reactors
« Reply #9 on: September 18, 2003, 12:18:09 PM »
Hes saying that this reacotor dosent work right.

Ill see what i can come up with D. But i have to warn you that i'm still a bit rusty with those damn reactors. (Their a handfull arnt they?)
“Common sense is not so common.” ~Voltaire

--> Donate to TheSwamp.org <--

daron

  • Guest
Need more help with reactors
« Reply #10 on: September 18, 2003, 03:27:38 PM »
Handful? More like a headache. It'd be nice if they just WORKED.