Author Topic: vlr-commandWillStart  (Read 17021 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
vlr-commandWillStart
« on: March 14, 2011, 03:58:38 PM »
What am I am I doing wrong?

I have spent all day trying to undrstand this, the help menu does not give me an example and the forums are too complicated for me to understand.

How would I create the most basic of simplist 'command-reactor'?

Here is my mangled code:

Code: [Select]
(vl-load-com)

  (vlr-command-reactor
    "Load Plot Setup from Template" '((:vlr-commandWillStart . PlotSetup))
  )

  (setq
    acadObject (vlax-get-acad-object)
    acadActiveDocument (vla-get-ActiveDocument acadObject)
    acadPlotConfigurations (vla-get-PlotConfigurations acadActiveDocument)
    
  )

;-----------------------------------------------------------------------------------------

    (vla-StartUndoMark acadActiveDocument) ;Start of UNDO

;-----------------------------------------------------------------------------------------




;-----------------------------------------------------------------------------------------

(defun PlotSetup ( / )

  (setq cmd (strcase "PLOT"))

  (cond
    ((wcmatch cmd "PLOT"))
  
  (vlax-for eachPlotConfig acadPlotConfigurations
  
      (if
 (wcmatch (vla-get-name eachPlotConfig) "Oce_TDS600 ANSI D 22x34,Oce_TDS600 Arch D 24x36,Oce_TDS600 Arch E1 30x42,PDF_995 ANSI A 8.5x11,PDF_995 ANSI B 11x17,PDF_995 ANSI D 22x34,PDF_995 Arch D 24x36,PDF_995 Arch E1 30x42")

 (vla-delete eachPlotConfig)
      )
  )
  

  (command "-psetupin" "FilePath")

  )

  
  
;-----------------------------------------------------------------------------------------

    (vla-EndUndoMark acadActiveDocument) ;End of UNDO

;-----------------------------------------------------------------------------------------

    (princ)
)

Thanks for any assistance
« Last Edit: March 15, 2011, 09:46:46 AM by cadman6735 »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: vlr-commandWillStart
« Reply #1 on: March 14, 2011, 04:08:06 PM »
Hi,

You cannot use the 'command' function within a reactor callback sub routine.
Speaking English as a French Frog

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: vlr-commandWillStart
« Reply #2 on: March 14, 2011, 04:19:03 PM »
Just load all page setups at startup and/or put them in your template.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cadman6735

  • Guest
Re: vlr-commandWillStart
« Reply #3 on: March 14, 2011, 04:31:12 PM »
Hi AlanJT

Sorry that would be the easy way to do it and I would learn how command reactors work...  Plus my template is already setup.

I tried adding the "plotsetup" command call into my acaddoc folder but it failed but I didn't spend any time to wonder why, I went straight to "trying" to learn command reactors, seemed to be more fun and challanging.  (challanging to say the least)



------------------------------------------------------------


Hi Gile

Yes, I have read this but didn't get the point...  How does one write a command reactor without specifying which command to react to....  (I am lost in translation)   :laugh:

Here I have found an example from Andrea

with the last bit of her code:

Code: [Select]
;;Reactor on ended ERASE
(defun *EraseEnded* (call-reactor scI / ERE)
  (setq ERE (nth 0 scI))
  (if (= ERE "ERASE")
    (checkIFdeleted)
  )
)

I am guessing that the

Code: [Select]
(setq ERE (nth ) scI)is the command call?
But unclear how it works



PS  once you paste code into this forum the text editor becomes hard to use... :pissed:


cadman6735

  • Guest
Re: vlr-commandWillStart
« Reply #4 on: March 14, 2011, 04:32:34 PM »
I ment to say, woudn't learn how command reactors work

not

would learn

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: vlr-commandWillStart
« Reply #5 on: March 14, 2011, 04:51:26 PM »
Hi AlanJT

Sorry that would be the easy way to do it and I would learn how command reactors work...  Plus my template is already setup.

I tried adding the "plotsetup" command call into my acaddoc folder but it failed but I didn't spend any time to wonder why, I went straight to "trying" to learn command reactors, seemed to be more fun and challanging.  (challanging to say the least)


Then just load the pagesetups on startup. Straight out of our acaddoc.LSP ...
Code: [Select]
(defun CES_PageSetups (/)
  (if (findfile "CES-PAGESETUPS.dwg")
    (progn (command "_.psetupin" "CES-PAGESETUPS" "*")
           (while (wcmatch (getvar "cmdnames") "*PSETUPIN*") (command "_y"))
    )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: vlr-commandWillStart
« Reply #6 on: March 14, 2011, 05:14:42 PM »
Hi CADMan,

When using a command reactor, the callback function is called with two arguments - from the Help:

Quote from: ACAD Dev Help
callbacks
A list of pairs of the following form:

(event-name . callback_function)

where event-name is one of the symbols listed in the “Command reactor events” table below, and callback_function is a symbol representing a function to be called when the event fires. Each callback function accepts two arguments:

reactor_object The VLR object that called the callback function.

list A list containing a single element, the string identifying the command.


To perhaps understand what I mean, try this example:

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 )
  (alert
    (strcat
      "Reactor: " (vl-prin1-to-string reactor)
      "\nList: "    (vl-prin1-to-string parameters)
    )
  )
  (princ)
)

Type 'test' to start and stop the reactor. When started, type any command and you will be presented with the values held by the callback arguments.

Lee

cadman6735

  • Guest
Re: vlr-commandWillStart
« Reply #7 on: March 14, 2011, 05:19:56 PM »
Thanks Alan

I could of written it 'something' like yours, but in my own coding way.  Doing it the way you did it I could have done too but...

I really want to do it via command reactor.

I am trying to learn to program and even though every new adventure I take in programming I get hung up on, I can honestly say every example I gain from these forums I use over and over again and have learned to manipulate the code given to me to my advantage.

I want the code to be loaded when plot is called because it seemed like a good example for me to play with command call reactors.

I also want to be able to run this command from the command line when ever I want as well.

I have many different reasons why I am perticular in why I want to do it my way for issue that plague me on a daly basis.

but my main reason is I just want to learn to program lisp, regarless of easier or more logical ways to do it.

sorry if that was blunt but I read somewhere in the rules that the more straight forward I am the more help I will get.

and Alan I always appriciate your time.

Thanks

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: vlr-commandWillStart
« Reply #8 on: March 14, 2011, 05:26:13 PM »
To butt in - reactors are one of the *worst* places to start learning LISP.  Simple, linear, non-VLA applications are far better.  Reactors require knowing about callbacks, VLA- programming, function layout (to prevent looping), order of events, function arguments, symbols vs. variables...
If you are going to fly by the seat of your pants, expect friction burns.

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

cadman6735

  • Guest
Re: vlr-commandWillStart
« Reply #9 on: March 14, 2011, 05:29:46 PM »
Hi lee

Thanks for the example but it errored on me

Quote
Command:
Command: test
Command:
Command: line
; error: An error has occurred inside the *error* functioninvalid AutoCAD
command: nil

cadman6735

  • Guest
Re: vlr-commandWillStart
« Reply #10 on: March 14, 2011, 05:39:25 PM »
Hi dgorsman

I am sure there are always good and bad places to start learning something.  As long as one starts to learn all should be ok.

I ask my questions because I am curiouse and I let my understanding dictate my direction.

but for now all I am interested in is a simple example of vlr-commandWillStart, with full knowledge that I will totaly screw something up.  And I will deal with that issue when I get to it.  See my learning process...   8-)

Thanks

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vlr-commandWillStart
« Reply #11 on: March 14, 2011, 05:46:17 PM »
To copy something from another drawing, you would use ObjectDBX.  There are plenty of examples of how to use it.  Once you understand how to use it, then you can plug that code into your reactor code, as that will use no command calls also.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: vlr-commandWillStart
« Reply #12 on: March 14, 2011, 05:52:24 PM »
Hi lee

Thanks for the example but it errored on me

Quote
Command:
Command: test
Command:
Command: line
; error: An error has occurred inside the *error* functioninvalid AutoCAD
command: nil

Not my error - my code doesn't even have an *error* function....

cadman6735

  • Guest
Re: vlr-commandWillStart
« Reply #13 on: March 14, 2011, 06:15:30 PM »
Quote
Not my error - my code doesn't even have an *error* function....

See, told you

I can even take a perfectly good piece code, copy and paste it, run it and screw it up...

-------------------------------------------

Thanks all

I will keep on tinkering till I get it, was only looking to find a short cut... :lol:

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: vlr-commandWillStart
« Reply #14 on: March 14, 2011, 07:23:04 PM »
Quote
Not my error - my code doesn't even have an *error* function....

See, told you

I can even take a perfectly good piece code, copy and paste it, run it and screw it up...

It looks as though you have other code running with an *error* function that isn't localised...