I want a button that opens a menu that can select scripts

Discussion in 'AutoCAD' started by mikerpt, Mar 29, 2005.

  1. mikerpt

    mikerpt Guest

    I have a bunch of scripts that insert drawings into the one im currently in. I want a button that will open a menu, and from there I can select which script I want to run and once I press ok the script will run. How do I go about doing this??? This stuff gets confusing :/
     
    mikerpt, Mar 29, 2005
    #1
  2. mikerpt

    ECCAD Guest

    Will you settle for a Dialog 'List' instead ?
    Bob
     
    ECCAD, Mar 29, 2005
    #2
  3. mikerpt

    mikerpt Guest

    well i would prefer to have a menu come up. but if its really hard to make a menu i could go with a dialog box for now
     
    mikerpt, Mar 29, 2005
    #3
  4. mikerpt

    ECCAD Guest

    Well,
    I was thinking, the Menu would have to be 'hard-coded', and that would limit 'easy' expansion. Whereas, if you do a Dialog box, will 'expand' as you add-in more scripts - the list just gets longer..no code changes..easier to maintain, etc.
    Plus, a Dialog box (can have) a OK and Cancel button, so you can pick OK to run the script, or Cancel to just (not) do the script.
    Does that sound like what you need ?

    Bob
     
    ECCAD, Mar 29, 2005
    #4
  5. mikerpt

    mikerpt Guest

    yea that would be perfect. How do I make one to run scripts?
     
    mikerpt, Mar 29, 2005
    #5
  6. mikerpt

    ECCAD Guest

    No, not hard at all. Getting the pop-in menu to appear in your
    AutoCAD Main Menu bar is a little tricky, but it can be automatically poped in there. So, lets take that route, since
    you said you would prefer to do a Menu.
    Now the questions.
    - What Version of AutoCAD, full or LT or what ?
    - Do you have at least 'some' knowledge of Lisp ?
    - What 'folder' do you keep your scripts in ? (e..g. J:/myscripts/)
    - Do you have a menu started already ?

    Typical pop-in menu file: custom.mns
    // custom menu to load and run scripts
    ***MENUGROUP=MYSCRIPTS
    **POP1
    [Run Script 1]^c^c(command "_script" "script1.scr")
    [Run Script 2]^c^c(command "_script" "script2.scr")

    Loading your pop-up:
    At command prompt:
    MENULOAD
    Browse..
    (use the dialog to locate your mns file)
    Open
    Load
    .......
    then, you place it on your Main Menu.
    Tab to "Menu Bar",
    Pull-down the MenuGroup, and highlight MYSCRIPTS
    Next, highlight "Edit" on right, and do "Insert"
    to pop it in place.

    If you want to give it a try, you can code the .mns file,
    or you can send me an E-Mail with a list of the scripts,
    and what you want to see on the Menu pop..and I can
    make up the Menu file and send it back.

    Bob
     
    ECCAD, Mar 29, 2005
    #6
  7. mikerpt

    Matt W Guest

    (defun C:Dialog ( / dlgScript)
    (setq dlgScript (getfiled "List of *.SCR Files" "E:/temp/" "scr" 8))
    (if (/= dlgScript nil)
    (progn (command "script" dlgScript) )
    (alert "You didn't select anything!")
    )
    (princ)
    )
     
    Matt W, Mar 29, 2005
    #7
  8. mikerpt

    ECCAD Guest

    It looks like we are out of sync. If you are on the Outlook Express side, go to the Web side.

    So, you want a Dialog..no problem.
    Same questions, Acad ver, where are your scripts located,
    and what names.

    E-Mail me at:

    (remove the nospam and the ".")

    Bob
     
    ECCAD, Mar 29, 2005
    #8
  9. mikerpt

    mikerpt Guest

    first off...I'm running AutoCAD Mechanical 2005. I understand how lisps work but don't understand the coding much. Right now I'm making a separate menu file b/c I don't want to mess up my main one.
    Scripts located in: C:\Documents and Settings\mike santilli\Desktop\rpt scripts

    My current menu file has:
    ***MENUGROUP=MYSCRIPTS

    **POP1
    [Run Script 1]^c^c(command "_script" "diverter.scr")
    [Run Script 2]^c^c(command "_script" "jetvac.scr")
     
    mikerpt, Mar 29, 2005
    #9
  10. mikerpt

    ECCAD Guest

    Mike,
    The code you have attempted is for the Menu.
    A dialog is (not) a part of a Menu, but is a seperate
    interface - like when you type in Layer at the command line.
    The Layer Manager is a 'Dialog'. Anyway, just give me an
    E-Mail at:

    (remove the nospam and the ".")

    By the way, no charge.

    Bob
     
    ECCAD, Mar 29, 2005
    #10
  11. mikerpt

    ECCAD Guest

    Mike,
    Here ya go. A simplified Dialog, using Matt W's example.

    If you already have a file in your autocad..\support folder called "acaddoc.lsp".
    append this line:
    (load "run-script.lsp")
    If you don't have that file, create one using notepad, and place the line above
    in it, and save as a filename 'acaddoc.lsp'...in your autocad \ support folder.
    In Notepad, paste the following lines of code, and saveas "run-script.lsp"
    in the autocad \ support folder.

    ;; run-script.lsp
    (defun C:RS ( / dlgScript); Run Script
    (setq dlgScript (getfiled "List of *.SCR Files" "C:/Documents and Settings/mike santilli/Desktop/rpt scripts/" "scr" 8))
    (if (/= dlgScript nil)
    (progn (command "script" dlgScript) )
    (alert "No Script Selected!")
    )
    (princ)
    )

    Next, If you want to run the program from a menu.. add-in a single line:
    [Run Scripts]^c^c(if (not RS)(load "run-script.lsp")) RS;

    Or, at the Command: prompt, just enter RS<Enter key>

    Let me know if you still have trouble, or if you want a 'specific' Lisp and custom Dialog
    I can provide both.

    Bob Shaw
    http://www.bobscadshop.com
     
    ECCAD, Mar 29, 2005
    #11
  12. mikerpt

    mikerpt Guest

    It works flawlessly and is exactly what I was looking for!!! Thanks a lot!!!!
     
    mikerpt, Mar 29, 2005
    #12
  13. mikerpt

    mikerpt Guest

    I was adding some scripts to my dialog box and was considering placing all the scripts on our network. I replaced the path in the run-script with the location on the network (\\Rpt-fs\dfs\Engineering\Mechanical\AutoCAD - Add-on Programs and Scripts\RPT TOOLBARS\STD COMPONENTS SCRIPTS) and when I run the program it just puts that path in the file box and won’t end up at the directory. Do you know if there a solution to this?



    It’s not the most important thing but I just wanted to make sure that if I add scripts in the future, that everyone using this program will be able to see the new scripts. Anyway here is the run-script I have now:



    ;; run-script.lsp

    (defun C:RS ( / dlgScript); Run Script

    (setq dlgScript (getfiled "List of *.SCR Files" "\\Rpt-fs\dfs\Engineering\Mechanical\AutoCAD - Add-on Programs and Scripts\RPT TOOLBARS\STD COMPONENTS SCRIPTS" "scr" 8))

    (if (/= dlgScript nil)

    (progn (command "script" dlgScript) )

    (alert "No Part Selected!")

    )

    (princ)

    )



    Thanks,
     
    mikerpt, Mar 29, 2005
    #13
  14. mikerpt

    Matt W Guest

    Try replacing the backslashes \ with forward slashes /.
     
    Matt W, Mar 29, 2005
    #14
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.