Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Command function in reactor

  1. #1
    Member
    Join Date
    2004-11
    Posts
    21
    Login to Give a bone
    0

    Default Command function in reactor

    I am attempting to write my very first reactor and am having a bit of difficulty in pulling off my desired intent. What I am trying to achieve just prior to a save or close event is the following:
    Save current layer to "0"
    run the TEXTTOFRONT and the HATCHTOBACK commands.

    I've had no problem with the first statement - but the last two are causing me some headache. Upon further investigation I have discovered that reactors disallow the use of the command function. Is there a way around this? I thought about redefining the Save and Close commands but this seems unnecessarily messy.

    Thanks ahead of time for any input. I am including my attempted code below.

    Code:
    (defun VLR_DWG-IT ()
      (vl-load-com)
      (if (not *DrawingSave*) (setq *DrawingSave* (vlr-dwg-reactor nil '((:vlr-beginsave . DoThisBeforeSave)))))
      (if (not *DrawingClose*) (setq *DrawingClose* (vlr-dwg-reactor nil '((:vlr-beginclose . DoThisBeforeSave)))))
     )
    (princ "\n*** ------ Save and Close Reactors Activated. ------ ***")
    
    ;;;;;;;;;;
    
    (defun DoThisBeforeSave (CALL CALLBACK)
      (setvar "clayer" "0")
      (dwgcleanup)
      (command ".TEXTTOFRONT" "Both"
    	   ".HATCHTOBACK")
      (princ)
     )
    
    ;;;;;;;;;;
    
    (VLR_DWG-IT)

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Command function in reactor

    you cant use COMMAND when using reactors. I'm not sure, but you may be able to use the VL-CMDF instead.

  3. #3
    Member
    Join Date
    2004-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Command function in reactor

    Disregard the previous code - there was an erroneous call to another function that is not shown - below is the corrected code.

    Thanks again in advance for any help provided.

    Code:
    (defun VLR_DWG-IT ()
      (vl-load-com)
      (if (not *DrawingSave*) (setq *DrawingSave* (vlr-dwg-reactor nil '((:vlr-beginsave . DoThisBeforeSave)))))
      (if (not *DrawingClose*) (setq *DrawingClose* (vlr-dwg-reactor nil '((:vlr-beginclose . DoThisBeforeSave)))))
     )
    (princ "\n*** ------ Save and Close Reactors Activated. ------ ***")
    ;;;;;;;;;;
    (defun DoThisBeforeSave (CALL CALLBACK)
      (setvar "clayer" "0")
      (command ".TEXTTOFRONT" "Both"
    	   ".HATCHTOBACK")
      (princ)
     )
    ;;;;;;;;;;
    (VLR_DWG-IT)

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Command function in reactor

    Quote Originally Posted by newfoundfreedom View Post
    Disregard the previous code - there was an erroneous call to another function that is not shown - below is the corrected code.
    ... You're missing the point.

    You CANNOT use Command calls with Reactors (specifically the CallBack function(s)).

    Consider using SSSetFirst + Ai_DrawOrder combo instead.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Command function in reactor

    Quote Originally Posted by newfoundfreedom View Post
    Code:
    (defun VLR_DWG-IT ()
      (vl-load-com)
      (if (not *DrawingSave*) (setq *DrawingSave* (vlr-dwg-reactor nil '((:vlr-beginsave . DoThisBeforeSave)))))
      (if (not *DrawingClose*) (setq *DrawingClose* (vlr-dwg-reactor nil '((:vlr-beginclose . DoThisBeforeSave)))))
     )
    (princ "\n*** ------ Save and Close Reactors Activated. ------ ***")
    ;;;;;;;;;;
    (defun DoThisBeforeSave (CALL CALLBACK)
      (setvar "clayer" "0")
      (command ".TEXTTOFRONT" "Both"
           ".HATCHTOBACK")
      (princ)
     )
    ;;;;;;;;;;
    (VLR_DWG-IT)
    Out of curiosity....

    Having looked at your Callback function more closely, why do you want to make changes to the drawing prior to Close?

    Wouldn't you end up saving those changes as well (potentially firing the :vlr-BeginSave event again), effectively repeating the Callback a second time?

    Just a thought; admittedly I've not tested your code. Perhaps I am mistaken.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Command function in reactor

    As an example:

    Code:
    ;;;--------------------------------------------------------------------;
    ;;; Reactor function:
    (defun VLR_DWG-IT ()
      (vl-load-com)
      (cond (*Reactor_BeginSave*)
            ((setq *Reactor_BeginSave*
                    (vlr-dwg-reactor
                      nil
                      '((:vlr-beginsave . saveCallback))))))
      (prompt "\n*** ------ Save Reactor Activated. ------ ***")
      (princ))
    ;;;--------------------------------------------------------------------;
    ;;; Callback function:
    (defun saveCallback (dataBase fileName / _Send ss)
    
      (defun _Send (ss loc)
        ;; © RenderMan, 2011
        (sssetfirst nil ss) (ai_draworder loc))
      
      (if (/= "0" (getvar 'clayer))
        (setvar 'clayer "0"))
      (if (setq ss (ssget "_x" '((0 . "DIMENSION,MTEXT,TEXT"))))
        (_Send ss "_f"))
      (if (setq ss (ssget "_x" '((0 . "HATCH"))))
        (_Send ss "_b"))
      (princ))
    ;;;--------------------------------------------------------------------;
    ;;; Autoload for named drawings:
    (if (= 1 (getvar 'dwgtitled))
      (VLR_DWG-IT))
    ;;;--------------------------------------------------------------------;
    ;;; Silent load:
    (princ)
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Member
    Join Date
    2004-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Command function in reactor

    RenderMan - thank you so much for your responses.

    - Response 1 - I didn't miss the fact that the command function couldn't be called within a reactor, I actually state that in my original post. However I was just trying to take out anything that might be confusing to someone looking at my code.

    - Response 2 - You are absolutely correct about not needing the reactor to run on a Close event. Honestly, I'm not even sure what I was thinking here.

    - Response 3 - Thank you so much for your code corrections. This is educational to me on a number of levels.
    First being the "sssetfirst" function. I have never run across it before.
    Second the way you are wrapping even simple statements like setting the current layer within an if statement. It never occurred to me to test for the current layer prior to resetting it. I like your thoroughness!
    Third - I really like the dwgtitled test at the end as well.

    A genuine thanks for all that.
    Now heres the problem. As much as I dig your code corrections - I'm having trouble getting it to work. It loads up just fine - but when I actually run it on a test drawing and perform a save - it leaves me hanging with my Dimensions and Text highlighted and gripped and reports a " invalid AutoCAD command: nil".

    Where is this going wrong. I'm lost

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Command function in reactor

    Quote Originally Posted by newfoundfreedom View Post
    RenderMan - thank you so much for your responses.
    You had many kind things to say - too many for me to comment on individually.

    Suffice it to say, that you're very welcome; I'm happy to help.

    Quote Originally Posted by newfoundfreedom View Post
    Now heres the problem. As much as I dig your code corrections - I'm having trouble getting it to work. It loads up just fine - but when I actually run it on a test drawing and perform a save - it leaves me hanging with my Dimensions and Text highlighted and gripped and reports a " invalid AutoCAD command: nil".

    Where is this going wrong. I'm lost
    Perhaps you are not going wrong, and I have overlooked something...

    First, lets check the AI_DRAWORDER function to make sure it's loaded. Try this:

    Code:
    (if ai_draworder
      (prompt "\n** Loaded ** ")
      (prompt "\n** Not loaded ** "))
    What is returned to the command line?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Command function in reactor

    Stop... I've made a terrible mistake.

    Apparently, nested within the AI_DRAWORDER function, is a Command call for the ._DRAWORDER command... which as we're already aware does not play nice with Reactors. *face palm*

    I am sorry to get your hopes up, with regard to the reactor functionality.

    However, all is not lost! You can add a custom LISP command that will accomplish this task like so:

    Code:
    (defun c:MySave  ( / _Send ss)
      (princ "\rMYSAVE ")
      (vl-load-com)
    
      (defun _Send  (ss loc)
        ;; © RenderMan, 2011
        (sssetfirst nil ss) (ai_draworder loc))
    
      (if (not ai_draworder)
        ((lambda (vrsn)
           (load (strcat "acad"
                         (cond
                           ((vl-string-search "16.2" vrsn) "2006")          ; 2006
                           ((vl-string-search "17.0" vrsn) "2007")          ; 2007
                           ((vl-string-search "17.1" vrsn) "2008")          ; 2008
                           ((vl-string-search "17.2" vrsn) "2009")          ; 2009
                           ((vl-string-search "18.0" vrsn) "2010")          ; 2010
                           ((vl-string-search "18.1" vrsn) "2011")          ; 2011
                           ((vl-string-search "18.2" vrsn) "2012"))         ; 2012
                         "doc.lsp")))
          (vlax-product-key)))
    
      (if (/= "0" (getvar 'clayer))
        (setvar 'clayer "0"))
      (if (setq ss (ssget "_x" '((0 . "DIMENSION,MTEXT,TEXT"))))
        (_Send ss "_f"))
      (if (setq ss (ssget "_x" '((0 . "HATCH"))))
        (_Send ss "_b"))
      (command "._qsave")
      (princ))
    Many, many, apologies for the confusion.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  10. #10
    Member
    Join Date
    2004-11
    Posts
    21
    Login to Give a bone
    0

    Default Re: Command function in reactor

    RenderMan, whilst I am disappointing with not being able to automate this functionality through a reactor, I really appreciate your efforts in helping me out.
    Nearly every thread I've ever read on these boards has some contribution from you. So have a my friend - for so consistently helping us noobs out.

    And, by the way - I had no idea bout the ai_commands hidden under the Acad####doc.lsp - thanks for pointing that out.

    Cheers

Page 1 of 2 12 LastLast

Similar Threads

  1. command reactor selected entity
    By Serhan_BAKIR in forum AutoLISP
    Replies: 3
    Last Post: 2012-01-13, 01:10 PM
  2. Cancel command with Visual Lisp reactor
    By vasco_rou in forum AutoLISP
    Replies: 1
    Last Post: 2011-11-24, 01:20 PM
  3. command Reactor and condtional processing
    By rklee in forum AutoLISP
    Replies: 6
    Last Post: 2009-07-24, 11:42 AM
  4. UnKnown Command Reactor
    By kerbocad in forum VBA/COM Interop
    Replies: 8
    Last Post: 2009-01-21, 04:45 PM
  5. Embed command reactor inside a drawing.
    By jrd.chapman in forum AutoLISP
    Replies: 6
    Last Post: 2005-04-25, 04:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •