bradb Posted May 26, 2009 Posted May 26, 2009 I have wrote a series of commands for autocad. I would like to know if there is a way i can use one of my commands in another command that i am trying to write. When I try it, it say it is a unknown command. I have the command in my startup suite and it works when I type it at the command prompt? Is this possible. I also tryed put a "-" and a "_" in front of the command name in the new lisp but that didn't work. Quote
Freerefill Posted May 26, 2009 Posted May 26, 2009 Try (c:command), such as: (defun c:something( / ) (princ "Hello, World!") ) (defun c:somethingelse( / ) (c:something) ) This also works with Express tools, since they're LISPs as well. Quote
bradb Posted May 26, 2009 Author Posted May 26, 2009 here is the code I am trying with FIT the command I have already wrote (defun c:test () (setq OD (getdist "\nEnter OD: ") ID (getdist "\nEnter ID: ") );end setq (command "fit" OD pause pause) (command "fit" ID pause pause) );end defun Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 Why not make the fit function a sub-function and call it with arguments? Quote
bradb Posted May 26, 2009 Author Posted May 26, 2009 I not that advance yet. but i have a book i am reading with the lisp commands and what they do so I'll see what I can do. I kind of know what you mean with arguments Quote
bradb Posted May 26, 2009 Author Posted May 26, 2009 Why not make the fit function a sub-function and call it with arguments? I don't think this is going to work for me for two reasons 1) I don't want it a sub-function because I still want to use FIT as a stand alone command. 2) I can't seem to figure out how to call it with arguments and have run the command with the predetermined sizes. (I have it now going to the fit command but its just executing it. It is not run it with the sizes provide by the get- functions) Quote
Lee Mac Posted May 26, 2009 Posted May 26, 2009 I'm not sure how else you may approach this - as, when you call the other LISP function, it takes control, and I don't think you can submit data to it whilst it is running. Quote
bradb Posted May 26, 2009 Author Posted May 26, 2009 I'm not sure how else you may approach this - as, when you call the other LISP function, it takes control, and I don't think you can submit data to it whilst it is running. Thats what I was afraid of. Thanks for info Quote
BIGAL Posted May 27, 2009 Posted May 27, 2009 You need to call your defun before running the command should work. I think your trying to do a command within a command what does FIT do ? Please paste here. Maybe make FIT into two parts one that is run as a command FIT and the second where it uses the new defun from inside the fit.lsp I had a master lisp program that had all my defuns (30+) for an architectural package it gets loaded first this way I only had to call the defun also set my defuns to C:aaa() variables passed both ways ok The package always used the same defuns saved a lot of coding where lots of layer manipulation was involved. It is common practice to have a library of defuns if you have a common theme of drafting/design ensures consistency in you drafting standard. Most lisps shown here on the forum are not like this as they have say external defuns included in them making sharing info easier. If in doubt just paste FIT into the other lisp code while you figure out a better way. FIT (command someautocadcommand OD pause pause) Quote
bradb Posted May 27, 2009 Author Posted May 27, 2009 If in doubt just paste FIT into the other lisp code while you figure out a better way. FIT (command someautocadcommand OD pause pause) I tryed this but no luck (defun FIT (/ OLDDIA SP EP ANG UANG DANG LANG RAD P1 P2 P3 P4 OSM LAY) (if(not fit:dia)(setq fit:dia 0.0)) (setq OLDDIA fit:dia FIT:DIA (getdist(strcat "\nEnter DIA of FIT <" (rtos fit:dia) ">: ")) ) (if(null fit:dia)(setq fit:dia olddia)) (setq SP (getpoint "\nEnter START of FIT: ") EP (getpoint sp "\nEnter END of FIT: ") ANG (angle sp ep) UANG (+ ang (/ pi 2)) DANG (+ ang (* pi 1.5)) LANG (+ ang pi) RAD (/ fit:dia 2) P1 (polar sp uang rad) P2 (polar ep uang rad) P3 (polar sp dang rad) P4 (polar ep dang rad) ) (setvar "cmdecho" 0) (setq osm (getvar "osmode") lay (getvar "clayer") ) (setvar "osmode" 0) (command "line" p1 p2 "" "line" p3 p4 "") (setvar "osmode" osm) (setvar "cmdecho" 1) (princ) ) (defun c:test () (setq OD (getdist "\nEnter OD: ") ID (getdist "\nEnter ID: ") ) (command "fit" OD pause pause) (command "fit" ID pause pause) ) Quote
bradb Posted May 27, 2009 Author Posted May 27, 2009 Ok Its working like this (defun FIT (/ SP EP ANG UANG DANG LANG RAD P1 P2 P3 P4 OSM LAY) (setq SP (getpoint "\nEnter START of FIT: ") EP (getpoint sp "\nEnter END of FIT: ") ANG (angle sp ep) UANG (+ ang (/ pi 2)) DANG (+ ang (* pi 1.5)) LANG (+ ang pi) RAD (/ od 2) P1 (polar sp uang rad) P2 (polar ep uang rad) P3 (polar sp dang rad) P4 (polar ep dang rad) ) (setvar "cmdecho" 0) (setq osm (getvar "osmode") lay (getvar "clayer") ) (setvar "osmode" 0) (command "line" p1 p2 "" "line" p3 p4 "") (setvar "osmode" osm) (setvar "cmdecho" 1) (princ) ) (defun c:test () (setq OD (getdist "\nEnter OD: ") ) (fit) ) But I now realize it won't work for what I am doing. Sorry and thanks for all the help. Quote
Lee Mac Posted May 27, 2009 Posted May 27, 2009 I haven't really had time to take a proper look at this, but you could change it to something like this: (defun c:FIT (/ *error vlst ovar sp ep ang uang dang lang rad p1 p2 p3 p4) (defun *error* (msg) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\n<< Error: " msg " >>")) (princ "\n<<-- Cancelled -->>")) (princ)) (setq vlst '("CMDECHO" "OSMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0 0)) (or fit:dia (setq fit:dia 0.0)) (or (and (or OD ID) (setq fit:dia (if OD OD ID))) (or (not (setq tmp (getdist (strcat "\nEnter Diameter <" (rtos fit:dia) "> : ")))) (setq fit:dia tmp))) (setq SP (getpoint "\nEnter START of FIT: ") EP (getpoint sp "\nEnter END of FIT: ") ANG (angle sp ep) UANG (+ ang (/ pi 2)) DANG (+ ang (* pi 1.5)) LANG (+ ang pi) RAD (/ fit:dia 2) P1 (polar sp uang rad) P2 (polar ep uang rad) P3 (polar sp dang rad) P4 (polar ep dang rad)) (command "line" p1 p2 "" "line" p3 p4 "") (mapcar 'setvar vlst ovar) (princ)) (defun c:test (/ OD ID) (if (setq OD (getdist "\nEnter OD: ")) (c:fit)) (princ)) 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.