Results 1 to 10 of 10

Thread: Define 2 key commands inside a routine that will run another routine

  1. #1
    100 Club jonathanschade's Avatar
    Join Date
    2015-11
    Posts
    130
    Login to Give a bone
    0

    Cool Define 2 key commands inside a routine that will run another routine

    I am trying to define, and load, 2 key commands inside of a lisp routine (ACADDOC.LSP) that will define another lisp routine, or a script routine.

    Is this possible? I am putting together an office menu, and I need to be able to define multiple methods of inputting commands. I have created the individual commands, and gotten them to work in the CUI. There I have created both pull down menu's and tool bars. I just don't know how to create 2 key commands that call other lisp (or scripts).

    Anyone out there done this?

    Thanks

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    I don't think I understand what you are talking about. You can define functions in other functions.
    Code:
    (defun c:Test ()
    
    (defun c:Test2 ()
    (prompt "\n This is test 2 function.")
    (princ)
    )
    
    (prompt "\n This is test function.")
    (princ)
    )
    You just have to call the main one first. In this case 'test' has to be called before 'test2'.
    Command: test2
    Unknown command "TEST2". Press F1 for help.

    Command: test

    This is test function.
    Command:
    Command: test2

    This is test 2 function.
    Does this help?

  3. #3
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    Or do you mean access a function with a two key function like:

    Code:
    (defun c:TestFunction ()
       (princ "This is a test")
    )
    
    (defun c:TF ()
    (c:TestFunction)
    )

  4. #4
    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: Define 2 key commands inside a routine that will run another routine

    or are you looking for something like this?

    Code:
     
    (setq logan (getvar "loginname"))
    (if (wcmatch logan "arch")
    (load "Architecture.lsp")
    );end if architecture
    ;(if (wcmatch logan "")
    ;(load "survey.lsp")
    ;)
    (if (wcmatch logan "Chris")
    (load "Engineering.lsp")
    );end if engineering

  5. #5
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    Hi,
    What do I normally do is define the functions with full name in a compiled files and create another file, with a short description to the function and shortcut command, which can be edited by the user. For example:
    Code:
    ;MainFunctions.LSP
    (defun c:EditAttributes (/ var1 var2)
    ....
    ) ;end defun
    (defun c:ExtractAttributes (/ )
    ...
    ) ; end defun
    Code:
    ;ShortCmds.lsp
    ; The following command is used for global attribute edit.
    (defun C:EAD ()(c:EditAttributes))
    ;The following command extracts all the attributes in the drawing to a text file.
    (defun C:AXT ()(c:ExtractAttributes))
    This will prevent the users from tampering the original code, while giving them the flexibility to edit the keyboard shortcuts according to their preference. When I call these commands from a menu, I use
    Code:
    [Extract Attributes]^p^c^c(if (not c:ExtractAttributes)(load "MainFunction.lsp"));ExtractAttributes
    so that I can make sure that the original function is called irrespective of the short command names in individual computers.

    Note: If the function is not loaded, include the code to load the file when the short command is called.

    Regards,
    AH

  6. #6
    100 Club jonathanschade's Avatar
    Join Date
    2015-11
    Posts
    130
    Login to Give a bone
    0

    Cool Re: Define 2 key commands inside a routine that will run another routine

    what I am trying to do is create an Acaddoc.lsp (for the whole office) that will load automatically. These will have shortcuts for new commands that I created for the office menu.

    I tried to do it this way - (defun C: D4() ("script" "d4") - but it did not work.

    I have about 20 script files that we run to set up layers and variables. D4 sets up all of the variables for dim style 3"=1'-0".

    Am I trying to do something that is impossible?

    Thanks for all of your help.

  7. #7
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    Since it's a script, and to issue a script its a command, you would have to do something like.
    Code:
    (command "_.script" "d4")
    edit: I don't work a lot with scripts, so I'm not sure if you need the extension, but you might want to add it plus the path to the file. Or use (findfile "ScriptName.scr") as the name and path of the script file.

  8. #8
    100 Club jonathanschade's Avatar
    Join Date
    2015-11
    Posts
    130
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    That worked GREAT!
    Thank you.

    Do you know if there is a way to call (defun) a lisp routine from inside another lisp routine.

    I am setting up some company wide standard 2 key commands, and I have not been able to figure this out.

    As an example I need to set up a two key command alias for FUDGE.LSP. I have only gotten to
    (defun C:FD() (command - so far. I have no idea how to load and then define a lisp routine this way.

    For other single line lisp routines I have just incorporated them into the ACADDOC.LSP, but I really do not like that idea. If for some reason I have to change the code, I will have to change the code in two places (the original lisp file and ACADDOC.LSP) this is not good coding.

    Thank you for all of the help.

  9. #9
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    212
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    If you're using menu, try to create .mnl-file. Place it near with a mnu(cui) file. For example:
    Code:
    mymenu.mnu
    mymenu.cui
    mymenu.mnl
    Within mymenu.mnl define all functions you need. Or anything else

  10. #10
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Define 2 key commands inside a routine that will run another routine

    Quote Originally Posted by jonathanschade
    Do you know if there is a way to call (defun) a lisp routine from inside another lisp routine.

    As an example I need to set up a two key command alias for FUDGE.LSP. I have only gotten to
    (defun C:FD() (command - so far. I have no idea how to load and then define a lisp routine this way.
    It depends on how "fudge.lsp" is defined.

    A --- If there is a defined function inside this file (say it's called fudge), then there are a few ways....


    1. Edit "fudge.lsp" and add another defun like this

    (defun c:FD () (c:fudge))


    2. Add something like this to your acaddoc.lsp:

    (defun c:FD ()
    (if (not c:fudge)(load "fudge"))
    (c:fudge)
    )


    3. Preload the lisp routine using acaddoc.lsp [with a line like this (load "fudge")], then also create a wrapper function like this

    (defun c:FD ()
    (c:fudge)
    )




    B --- If fudge.lsp just contains lisp code an no defined functions, then all you need to do is this:

    (defun c:FD ()
    (load "fudge")
    )
    R.K. McSwain | CAD Panacea |

Similar Threads

  1. Looking for lisp routine to select objects inside polyline
    By vlad_tzok133583 in forum AutoLISP
    Replies: 22
    Last Post: 2022-04-29, 05:44 AM
  2. 2015 copybase not working inside lisp routine
    By d.channon in forum AutoLISP
    Replies: 5
    Last Post: 2015-04-01, 10:40 PM
  3. How to load another routine commands
    By luislhss in forum AutoLISP
    Replies: 2
    Last Post: 2013-05-09, 04:41 PM
  4. Macro / Routine to automatically trim inside the selected window
    By joseph.117086 in forum AutoCAD Customization
    Replies: 9
    Last Post: 2006-07-17, 05:18 AM
  5. Run a LISP routine from inside another
    By mpemberton in forum AutoLISP
    Replies: 5
    Last Post: 2006-06-26, 07:12 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
  •