NoelStalker Posted November 5, 2008 Posted November 5, 2008 Hello everyone, I wanted to make a lisp file to hide all viewports in one command rather than type mview hide on all Here is what I have but it does not appear to work: (defun c:mvh () (command "mview" "h" "on" "all" "" (princ)) ) This is the error it returns: Command: mvh ; error: bad argument value: AutoCAD command: Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 Noel, You are learning well to know that you need a (princ) at the end of a LISP to end cleanly, but it can't be within an AutoCAD command, otherwise CAD will regard the (princ) as one of the arguments of the command. Try this: (defun c:mvh (/ tab) (setvar "cmdecho" 0) ; [b][color=blue]turn the command echo off [/color][/b] (setq tab (getvar "ctab")) ; [b][color=Blue]retrieve tab information[/color][/b] (if (/= tab "Model") ; [color=Blue][b]If you are not in the Model Tab.... do the following[/b][/color] (command "mview" "h" "on" "all" "" ) ; [b][color=Blue]run the AutoCAD command[/color][/b] (alert "Cannot be Performed in Model Space.") ; [b][color=Blue]If you are in the Model Tab, do this.[/color][/b] ) ; [b][color=Blue]end if[/color][/b] (setvar "cmdecho" 1) ; [color=Blue][b]turn the command echo back on[/b][/color] (princ) ; [color=Blue][b]exit cleanly[/b][/color] ) ; end program Hope this helps somewhat... Quote
neekcotrack Posted November 5, 2008 Posted November 5, 2008 LISP (DEFUN C:MVH () (COMMAND "MVIEW" "H" "ON" "ALL" "" (PRINC)) ) DIESEL MACRO TILEMODE;0;MVIEW;H;ON;ALL;; This can be used in a custom button or in the tool pallete. Quote
NoelStalker Posted November 5, 2008 Author Posted November 5, 2008 LeeMac, That worked perfectly. Thanks for the princ clarification. Question: What does "(/ tab)" mean? neekcotrack, Wouldn't that freeze all my layers? Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 Hi Noel, Most LISPs will be in the format: (defun c:XXX () [color=Blue][i] ......... (commands and stuff)..........[/i][/color] ) ; <<---<< end of program Inside the brackets after the "c:XXX" you should localize your variables and arguments, i.e. (defun dtr ([color=Red][b]a[/b][/color]) (* pi (/ a 180.0)) ) The above will convert degrees into radians. It requires one argument "a", and hence, this argument goes inside the brackets. In my example, I used one variable "tab": (setq tab (getvar "ctab"))and so my LISP began with: (defun c:mvh (/ [b][color=Red]tab[/color][/b]) ..... As "tab" is a variable and not an argument, I use the forward slash. One more example: (defun dtr ([b][color=Red]a / ans[/color][/b]) (setq ans (* pi (/ a 180.0)) ) ; end setq (alert (rtos ans)) ) This program will take an argument "a", convert it into radians and then display the result in a dialog box. I use "ans" to store the result of the calculation, and so this is my variable to be localized. Also, if I am correct, I think localizing the variables and arguments erases all previous values for these variables & arguments every time the LISP is run, so that the LISP can retrieve new values for them. But not confident with that last bit... Quote
NBC Posted November 5, 2008 Posted November 5, 2008 Lee - where is the princ in that last code you posted, that you mentioned is so vital in lisp programs, in an earlier post ? Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 haha, nice one NBC That last LISP post: (defun dtr (a / ans) (setq ans (* pi (/ a 180.0)) ) ; end setq (alert (rtos ans)) ) begins: (defun xxx () ... and not: (defun c:xxx () ... and so would probably run within another LISP program, therefore it would not require a (princ) term as the last term evaluated may not be from this program... :wink: Quote
NoelStalker Posted November 5, 2008 Author Posted November 5, 2008 I am new to lisp files so all of those parethesis have me slightly confused. In your dtr function, you have an argument "a". How does your program know what "a" is in order to insert it into the formula? Or is that just not shown here because, as you said, this would be a subset of a lisp file? Quote
neekcotrack Posted November 5, 2008 Posted November 5, 2008 LeeMac,That worked perfectly. Thanks for the princ clarification. Question: What does "(/ tab)" mean? neekcotrack, Wouldn't that freeze all my layers? Oops sorry. I fixed the code in my origanal post. Quote
NoelStalker Posted November 5, 2008 Author Posted November 5, 2008 neekcotrack, Cool - simple, elegant coding. Quote
Lee Mac Posted November 5, 2008 Posted November 5, 2008 Hi Noel, Yes you are correct, for instance in a code I posted earlier today: (defun c:tanx (/ ans ang ang2) (initget "Deg Rad") (setq ans (getkword "\nInput in Degrees or Radians? [Deg/Rad]: ")) (setq ang (getreal "Specify Angle: ")) (if (= ans "Deg") (setq ang [color=Red]([b]dtr ang[/b])[/color]) ) (setq ang2 (/ (sin ang) (cos ang))) (alert (rtos ang2)) (princ) ) ; end tanx [b][color=Red](defun dtr (a) (* pi (/ a 180.0)) )[/color][/b] ; end dtr Hope this helps! 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.