Jump to content

Recommended Posts

Posted

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:

Posted

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... :)

Posted

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.

Posted

LeeMac,

That worked perfectly. Thanks for the princ clarification. Question: What does "(/ tab)" mean?

 

neekcotrack,

Wouldn't that freeze all my layers?

Posted

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...

Posted

Lee - where is the princ in that last code you posted, that you mentioned is so vital in lisp programs, in an earlier post ?

Posted

haha, nice one NBC :P

 

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:

Posted

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?

Posted
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.

Posted

neekcotrack,

Cool - simple, elegant coding.

Posted

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! :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...