AutoCAD Command as Trigger for AutoLISP Execution

Discussion in 'AutoCAD' started by Sunburned Surveyor, Oct 28, 2004.

  1. Is there a way to run an AutoLISP file every time a particular AutoCAD command is executed by the user? For example, I want to run CHECKMOVE.LSP when ever the user executes the "Move" command. Any ideas how this can be done? (I am hoping for a solution I can implement with AutoLISP.)

    Thanks,

    Landon
     
    Sunburned Surveyor, Oct 28, 2004
    #1
  2. Sunburned Surveyor

    CJ Follmer Guest

    Try Undefining the Move command and replace it with your own which includes
    your lisp.

    (command ".undefine" "move")

    (defun c:move ()

    ;;your code here

    )

    cj


    command is executed by the user? For example, I want to run CHECKMOVE.LSP
    when ever the user executes the "Move" command. Any ideas how this can be
    done? (I am hoping for a solution I can implement with AutoLISP.)
     
    CJ Follmer, Oct 28, 2004
    #2
  3. Thanks for the tip CJ.

    Is there a way to reset a refined command to its original state in case I mess something up? Or is this automatically done when a new AutoCAD session is started?

    Thanks Again,

    The Sunburned Surveyor
     
    Sunburned Surveyor, Oct 28, 2004
    #3
  4. Sunburned Surveyor

    Tom Smith Guest

    (command "redefine" <commandname)

    Even when a command is redefined, you can always run the original version by
    prefixing it with a period, e.g. (command ".move"). That's why it's
    recommended that all lisps or menu macros which run commands should use the
    period-prefixed forms -- so the normal command will run even if it gets
    redefined for some reason.

    And any redefinitions are only in effect in the document session in which
    you did it. Reopen the drawing and the normal command is back You can't
    permanently mess up the built-in commands.
     
    Tom Smith, Oct 28, 2004
    #4
  5. Sunburned Surveyor

    CJ Follmer Guest

    typically you redefine the command in your startup functions, either in
    acaddoc.lsp, acad.lsp or your mnl file. That way it's set everytime you load
    a drawing.

    if you need to have the original back, use (command ".redefine" "move")

    cj


    mess something up? Or is this automatically done when a new AutoCAD session
    is started?
     
    CJ Follmer, Oct 28, 2004
    #5
  6. You may want to check into reactors, and run your code when the command
    is complete.

    Perhaps if you explained what you want to do (after the move).

    Terry
     
    Terry W. Dotson, Oct 29, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.