Results 1 to 9 of 9

Thread: Multiple Menu items calling the same lisp?

  1. #1
    Member
    Join Date
    2008-05
    Posts
    25

    Default Multiple Menu items calling the same lisp?

    Is it possible to have multiple menu items that run the same lisp but with different inputs (or running different parts of the same lisp)?

    Someone mentioned that I should combine all our lisps for inserting title blocks into a single lisp routine. This makes great sense, and makes my job easier, but we have 8 different title blocks and our users are used to putting selecting which one they want from a menu. I really don't want to require the user to type in the exact name of the titleblock they want, because I know this will cause errors and frustrations. If I can get separate menu items to call the same lisp, this will allow me to do this easily.

    Or do you have any other means of me accomplishing this?

    Thank you for any help!

    I should have done more looking into this before posting....
    I didn't think I had a clue how to do this, but I believe I can set up 8 different defun statements and in the .mns file to run each of the different functions.

    i.e.
    ID_TItleblock [Tb1]^C^C^PTb1
    ID_Titleblock [Tb2]^C^C^PTb2
    etc.

    Am I on the right track? (I'll keep looking into it, and sorry for posting before I had done more research. I can't figure out how to delete this thread, so I'll keep updating it as I learn more. Any input you can add would be great.)
    Last edited by stevenw00; 2009-08-06 at 06:48 PM. Reason: I'm an idiot

  2. #2
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    211

    Default Re: Multiple Menu items calling the same lisp?

    I hope I understood you... Do you mean something like
    Code:
    ID_TitleBlock1 [_Button(<...>)]^C^C^P(defun c:tb() (CallLispFunction Value1ForParam1 Value2ForParam2 ... ValueNParamN));tb;
    ID_TitleBlock2 [_Button(<...>)]^C^C^P(defun c:tb() (CallLispFunction ValueAForParam1 ValueBForParam2 ... ValueXForParamN));tb;
    Use AUTOCAD / ADT / AA 2006 / 2008 / 2010
    All i say is only my opinion
    I'm watching you! Your

  3. #3
    Member
    Join Date
    2008-05
    Posts
    25

    Default Re: Multiple Menu items calling the same lisp?

    Quote Originally Posted by kpblc2000 View Post
    I hope I understood you... Do you mean something like
    Code:
    ID_TitleBlock1 [_Button(<...>)]^C^C^P(defun c:tb() (CallLispFunction Value1ForParam1 Value2ForParam2 ... ValueNParamN));tb;
    ID_TitleBlock2 [_Button(<...>)]^C^C^P(defun c:tb() (CallLispFunction ValueAForParam1 ValueBForParam2 ... ValueXForParamN));tb;
    I think we're on the same page. What I did was:
    Code:
    ***MENUGROUP=Testing
    
    ***POP14
                   [Testing]
     
    ID_TitleBlock_Setup_0 [FAsize]^C^C^PFA
    ID_TitleBlock_Setup_0 [FBsize]^C^C^PFB
    ID_TitleBlock_Setup_0 [FCsize]^C^C^PFC 
    ID_TitleBlock_Setup_0 [FDsize]^C^C^PFD
    ID_TitleBlock_Setup_0 [SBsize]^C^C^PSB
    ID_TitleBlock_Setup_0 [SCsize]^C^C^PSC
    ID_TitleBlock_Setup_0 [SDsize]^C^C^PSD
    Currently I only have one function in my lisp, so FB works fine, but all of the others just print the print note I put at the beginning of the script to make sure it was working. Now I have to figure out how to get it to run all of the parts within the lisp no matter which function is selected, but only run the appropriate function.

    Seems like I will have 7 man functions and each of them will call one different sub-function and then a bunch of identical functions. Does this sound like I am headed the right way? I'm not sure how to set all of this up, but am looking into it now. I'm currently pulling all of my subs that have to run regardless of which titleblock I am putting in to the top of the lisp. At the bottom I believe I need a different defun to insert each of the titleblocks and insert the block specific info.

    If anyone has any examples of something similar, I would love to see them. I can't hardly understand Visual Lisp, so if you have them in basic lisp, that is what I would prefer.

  4. #4
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    211

    Default Re: Multiple Menu items calling the same lisp?

    First of all I terribly sorry for my English (it's not my own language).
    2nd: I think you have to change IDs to make them unique:
    Code:
    ***MENUGROUP=Testing
    
    ***POP14
                   [Testing]
     
    ID_TitleBlock_Setup_0 [FAsize]^C^C^PFA
    ID_TitleBlock_Setup_1 [FBsize]^C^C^PFB
    ID_TitleBlock_Setup_2 [FCsize]^C^C^PFC 
    ID_TitleBlock_Setup_3 [FDsize]^C^C^PFD
    ID_TitleBlock_Setup_4 [SBsize]^C^C^PSB
    ID_TitleBlock_Setup_5 [SCsize]^C^C^PSC
    ID_TitleBlock_Setup_6 [SDsize]^C^C^PSD
    3rd: I thought you have only 1 lisp function with some parameters, but now it's not very important (i think).
    Use AUTOCAD / ADT / AA 2006 / 2008 / 2010
    All i say is only my opinion
    I'm watching you! Your

  5. #5
    I could stop if I wanted to msretenovic's Avatar
    Join Date
    2002-02
    Location
    Galloway, Oh
    Posts
    304

    Smile Re: Multiple Menu items calling the same lisp?

    You can call a lisp function from a menu the same way you would from another lisp routine: (function param1 param2). So, something like the following should work:
    Code:
    ***MENUGROUP=Testing
    
    ***POP14
                   [Testing]
     
    ID_TitleBlock_Setup_0 [FAsize]^C^C^(function param01 param02)
    ID_TitleBlock_Setup_1 [FBsize]^C^C^(function param03 param04)
    ID_TitleBlock_Setup_2 [FCsize]^C^C^(function param05 param06) 
    ID_TitleBlock_Setup_3 [FDsize]^C^C^(function param07 param08)
    ID_TitleBlock_Setup_4 [SBsize]^C^C^(function param09 param10)
    ID_TitleBlock_Setup_5 [SCsize]^C^C^(function param11 param12)
    ID_TitleBlock_Setup_6 [SDsize]^C^C^(function param13 param14)
    Using the input to your function, you can use COND or IF statements to run different parts of the code that are applicable to each titleblock.

    HTH
    Michael K. Sretenović
    Most folks are about as happy as they make up their minds to be.
    -Abraham Lincoln (1809-1865)
    -16th president of The United States of America (1861 - 1865)

  6. #6
    Member
    Join Date
    2008-05
    Posts
    25

    Default Re: Multiple Menu items calling the same lisp?

    I've spent all of the time I can on combining these lisps. I'll list what I have, and what I need, and if someone can help that would be great. I'll test anything I need to, etc. but I don't have time to keep looking around, testing, and not figuring anything out.

    What I have:
    I have 7 lisp routines that each insert a title block into an AutoCAD drawing (in model space.) The only difference in these lisps is the filename that is being inserted, the coordinates to the upper right-hand corner of the working space (space within the border that the geometry occupies), and the block left after the file is inserted. Attached to this post is one of the original lisps that inserts a titleblock (ProESubm_FabB.lsp) and the very terrible attempt I made at setting up a lisp that would insert the appropriate titleblock based on which menu item was selected (Titleblock.lsp).

    What I need:
    I need one lisp file that will insert the appropriate titleblock, based on which of the 7 menu items are selected. The menu is set up like kpblc2000 posted above. I do believe the parameters may need passed, like the other use mentioned, however I have no clue how to do this.

    Even if someone knows of a file that works similarly and could post up an example, that would be great. I have the meat of it right, I just can't figure out the formatting.

    Thank you!
    Attached Files Attached Files

  7. #7
    AUGI Addict
    Join Date
    2006-12
    Posts
    1,503

    Default Re: Multiple Menu items calling the same lisp?

    Don't have the time to do a detailed analysis, but will give you a brief outline of how I solve similar problems. I create a series of "stub" command line function, which do nothing more than call a common support function with a different argument(s), e.g.:

    Code:
    (defun c:cmdA ()
       (if (not (runFunction "argument A"))
          (princ "\nObject A not inserted.")
       )
    )
    (defun c:cmdB ()
       (if (not (runFunction "argument B"))
          (princ "\nObject B not inserted.")
       )
    )
    
    (defun runFunction ( string_arg / return_flag )
    ;; bulk of function here
       return_flag
    )
    If I need to add more, its simple to add another stub function without needing to copy and rewrite the entire supporting code structure. If necessary, I can also override the stub functions to provide client-specific versions. Last, its a lot easier to change a LSP file than the CUI, so wherever possible I put things that might change in LSP rather than the menu item itself.

    Something else I would recommend, is using more verbose c: defuns, such as c:InsertTitleBlockA. You will have more flexibility for adding items in the future, it will be easier to read several years down the road (wait, what was "PFD" function again?), and it allows users to pick their own PGP alias' as required.
    If you are going to fly by the seat of your pants, expect friction burns.
    Windows XP is now over 10 years old, in software terms it makes Joan Collins look like the new kid on the block. - Statler
    Everyone else being wrong is not the same thing as being right.

  8. #8
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233

    Default Re: Multiple Menu items calling the same lisp?

    Give this a try. I think it should get you on the right track. You will need to pass the variable to the program when you call it form the menu. This variable is paper_size and you should pass B, C, D etc.. depending on which condition you want to fire form that button. Also you will need to update the coordinates and drawing names in each condition so the correct ones fire. Hopefully this gets you to where you need to be.

    The file is attached.
    Attached Files Attached Files

  9. #9
    Member
    Join Date
    2008-05
    Posts
    25

    Default Re: Multiple Menu items calling the same lisp?

    Thank you both for your info! I got pulled off this and onto another project this week, but hope to get to test this stuff next week. This definitely helps out.

Similar Threads

  1. Calling up LISP routine from within another LISP
    By jimmy_goodall in forum AutoLISP
    Replies: 2
    Last Post: 2010-02-01, 05:41 AM
  2. menu items not acting right
    By tomcarver in forum AutoCAD CUI Menus
    Replies: 4
    Last Post: 2009-12-07, 11:48 PM
  3. Disappearing toolbars and menu items
    By jwlucasVT in forum AutoCAD Customization
    Replies: 2
    Last Post: 2006-08-02, 04:30 PM
  4. Calling an Image Tile Menu from Pull-Down Menu
    By pinckney3 in forum AutoCAD CUI Menus
    Replies: 2
    Last Post: 2006-01-06, 05:42 PM
  5. Calling a lisp from within a lisp
    By LanceMcHatton in forum AutoLISP
    Replies: 10
    Last Post: 2005-10-16, 02:08 AM

Posting Permissions

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