nimble87 Posted April 2, 2020 Posted April 2, 2020 Hi All, I have 5 lisps that all do different forms of checks within a drawing. I want to make a main lisp file with a single "check" command to provide the user a list of the 5 lisps to choose from in the command line. After they input their choice, it will execute the chosen lisp. Can anyone please assist? snippet below of what i'm trying to do. (defun c:PECHECK ( / TYP) (load "4sl.lsp") (load "16sl.lsp") (load "16lv.lsp") (load "240lv.lsp") (load "240hv.lsp") (setq TYP (getstring t "\nSELECT ITEM TO CHECK - 4SL,16SL,16LV,240LV,240HV: " )) ;;; not sure if this is the correct way to prompt for the user input ;;; unsure on how to take the above user input and execute the corresponding lisp Thanks Quote
nimble87 Posted April 2, 2020 Author Posted April 2, 2020 Hi Hanhphuc, Thanks for taking the time to reply. The loading of the lisps is fine, I've been looking at combining all into the one lisp file to make it easier. The step I'm stuck on is executing one of the custom commands from within the main "pecheck". Break down below. -User runs the "pecheck" command -User prompted with "SELECT ITEM TO CHECK - 4SL,16SL,16LV,240LV,240HV:" -User inputs choice from above and it runs the corresponding command, eg. user input of 240LV will run the 240LV.lsp (or the 240LV command in the main lisp). Hope this makes sense Quote
Jonathan Handojo Posted April 2, 2020 Posted April 2, 2020 (edited) You don't "run" lisp, you run the functions within the LISP. Load all 5 of your LISP files into AutoCAD. Then, depending on what function is present inside your lisp. For example... if in "240lv.lsp", you have the function: (defun c:f240l ( / ) ;; Your code ) You call it by inserting the line (c:f240l) after loading 240.lsp <exactly what the function name is right after the defun>. So in your case, I'll do something like below: (defun c:pecheck ( / typ funcs) (setq funcs '( ; <--- list of pairs of functions to run ("4SL" . (c:f45l)) ; <--- function name to run (depends on how many arguments it takes, need to adjust) ("16SL" . (c:f16s)) ("16LV" . (c:f16l)) ("240LV" . (c:f240l)) ("240HV" . (c:f240h)) ) ) (initget 1 "4SL 16SL 16LV 240LV 240HV") ; <--- Initialise options for next user input (setq typ (getkword "\nSELECT ITEM TO CHECK [4SL/16SL/16LV/240LV/240HV]: ")) ; <--- Prompt user for input (eval (cdr (assoc typ funcs))) ; <--- run the function depending on user selection ) Edited April 5, 2020 by Jonathan Handojo Quote
nimble87 Posted April 5, 2020 Author Posted April 5, 2020 Hi Jonathan, Apologies for the incorrect wording, but thank you so much for your input. This was the missing piece of the puzzle I had been wrecking my head trying to resolve. Everything is now functioning as it should. Thanks again. Quote
BIGAL Posted April 6, 2020 Posted April 6, 2020 (edited) You can do a dcl that allows toggle buttons so could choose which one to run, as per Johnathon. This is full code. (if (not AH:Toggs)(load "Multiple toggles.lsp")) (setq ans (reverse (ah:toggs '("Choose " "Run option1 " "Run option2" "Run option3" "Run option4" "Run option5" )))) (if (= (nth 0 ans) 1)(c:f45l)) (if (= (nth 1 ans) 1)(c:f16s)) (if (= (nth 2 ans) 1)(c:f16l)) (if (= (nth 3 ans) 1)(c:f240l)) (if (= (nth 4 ans) 1)(c:f240l)) Multiple toggles.lsp Edited April 6, 2020 by BIGAL Quote
nimble87 Posted April 6, 2020 Author Posted April 6, 2020 Thanks BigAl, that's handy to know! I have the lisp functioning well, just one small issue when executing it in a drawing for the first time in a blank drawing. I get "Error: bad argument type: VLA-OBJECT" when picking one of the functions, when running a second time it works perfect. I'm thinking this is something to do with ssget and nothing being present in the drawing? I'm still very much learning this, so i could be completely wrong. I've attached the code in full, it piggy backs off a Lee Mac lisp (MidLenV1-0.lsp). Any help in resolving "Error: bad argument type: VLA-OBJECT" would be greatly appreciated. Thanks. PCHECK.lsp Quote
nimble87 Posted April 6, 2020 Author Posted April 6, 2020 Also another question for the experts: When executing one of the functions (eg. 240LV), is there some way to set this as the default for the next time the function is called? It would be good to be able to use right click at the end to repeat the command and already have the last function set as default. It would allow me to do multiple runs of the 240LV check with only 2 right clicks to execute instead of having to enter 240LV each time. Thanks. Quote
BIGAL Posted April 6, 2020 Posted April 6, 2020 (edited) You can set 240LV to not exit by having a while at the start that a (defun c:240LV (defun 240lvmain ) ; end 240lvmain (while ask do again or how many times (if yes (240lvmain) ) ;end while ) ; end C:240lv Edited April 6, 2020 by BIGAL Quote
Jonathan Handojo Posted April 6, 2020 Posted April 6, 2020 1 hour ago, nimble87 said: Thanks BigAl, that's handy to know! I have the lisp functioning well, just one small issue when executing it in a drawing for the first time in a blank drawing. I get "Error: bad argument type: VLA-OBJECT" when picking one of the functions, when running a second time it works perfect. I'm thinking this is something to do with ssget and nothing being present in the drawing? I'm still very much learning this, so i could be completely wrong. I've attached the code in full, it piggy backs off a Lee Mac lisp (MidLenV1-0.lsp). Any help in resolving "Error: bad argument type: VLA-OBJECT" would be greatly appreciated. Thanks. PCHECK.lsp 8.32 kB · 1 download It's kinda hard to pinpoint the issue because I can't see in any of the six commands where you need a vla object. If I know better, I never doubt Lee's codes because all that I've used from him works. At which line do you think the code starts to fail? 26 minutes ago, nimble87 said: Also another question for the experts: When executing one of the functions (eg. 240LV), is there some way to set this as the default for the next time the function is called? It would be good to be able to use right click at the end to repeat the command and already have the last function set as default. It would allow me to do multiple runs of the 240LV check with only 2 right clicks to execute instead of having to enter 240LV each time. Thanks. Certainly. You'll need to make one variable global though which I don't recommend as good practice. (defun c:pecheck ( / typ funcs) (setq funcs '( ("4SL" . (c:f45l)) ("16SL" . (c:f16s)) ("16LV" . (c:f16l)) ("240LV" . (c:f240l)) ("240HV" . (c:f240h)) ) ) (initget "4SL 16SL 16LV 240LV 240HV") ; <--- Modified and removed "1" to allow user to press enter (returning nil) (if (null pcheck:opt) (setq pcheck:opt "4SL")) ; <--- Set the global variable pcheck:opt to an option for very first time because it's nil. (setq typ (getkword (strcat "\nSELECT ITEM TO CHECK [4SL/16SL/16LV/240LV/240HV] <" pcheck:opt ">: "))) ; <--- Prompt user for input (if (null typ) (setq typ pcheck:opt)) ; If enter is pressed returning nil, set typ to the pcheck:opt value (setq pcheck:opt typ) ; update the pcheck:opt variable so (null pcheck:opt) above returns nil and pcheck:opt keeps previous variable. (eval (cdr (assoc typ funcs))) ) BIGAL's approach is better as it keeps variables local. Quote
nimble87 Posted April 6, 2020 Author Posted April 6, 2020 Thank you both for the quick replies, I'm learning more with every response. 19 minutes ago, Jonathan Handojo said: It's kinda hard to pinpoint the issue because I can't see in any of the six commands where you need a vla object. If I know better, I never doubt Lee's codes because all that I've used from him works. At which line do you think the code starts to fail? I'm quite new to debugging, but it appears to break on error at line 126-131 on the attached. it highlights the below as the error. I agree, Lees codes work perfect every time (this one included), it's definitely an error on my behalf somewhere. (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace ) ) Thanks again. PCHECKtest.lsp Quote
Jonathan Handojo Posted April 6, 2020 Posted April 6, 2020 5 minutes ago, nimble87 said: Thank you both for the quick replies, I'm learning more with every response. I'm quite new to debugging, but it appears to break on error at line 126-131 on the attached. it highlights the below as the error. I agree, Lees codes work perfect every time (this one included), it's definitely an error on my behalf somewhere. (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace ) ) Thanks again. PCHECKtest.lsp 6.93 kB · 0 downloads Well yeah, no doubt, because you modified the LM:acdoc to: (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) (command "plinewid" "0") ) Delete that (command "plinewid" "0") and it should be fine. Why was that line there in the first place? Quote
nimble87 Posted April 6, 2020 Author Posted April 6, 2020 8 minutes ago, Jonathan Handojo said: Well yeah, no doubt, because you modified the LM:acdoc to: (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) (command "plinewid" "0") ) Delete that (command "plinewid" "0") and it should be fine. Why was that line there in the first place? Thanks so much, that's solved it. I was looking for a way to revert the plinewid back to 0 after the command ends? Quote
Jonathan Handojo Posted April 6, 2020 Posted April 6, 2020 (edited) 5 minutes ago, nimble87 said: Thanks so much, that's solved it. I was looking for a way to revert the plinewid back to 0 after the command ends? Put it below the line (eval (cdr (assoc typ funcs))) at the pcheck function... that's if you're running the pcheck function straight. Otherwise, put it under each of the individual functions at the end of the functions. And rather than "command", better use "setvar", so it will be (setvar "plinewid" 0). Edited April 6, 2020 by Jonathan Handojo Quote
nimble87 Posted April 6, 2020 Author Posted April 6, 2020 Legend! You've managed to solve all of my issues, thanks so much. You've saved me many hours and headaches! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.