PDA

View Full Version : Almost sorted just need some pointers



hyposmurf
4th Jan 2004, 11:26 pm
Right I finally think I'm getting the hang of autolisp.I'm starting to see the system variables and commands in the correct order.One area Im still a bit unsure of is where the parenthesis(((())))))) are all menat to be
(defun c:fz ()
(setq old_radius (getvar "filletrad"))
(setvar "filletrad" 0)
(command ".fillet" pause pause)
(setvar "filletrad" old_radius)
)
The above is a bit of lisp code I found on the net that allows you to set the fillet radius to 0 for quicker triming of edges.I understand the command sequence,but why every (),are you meant to enclose them after every command line,that would appear in your command line editor?Why is there 2() after the (defun c:fz ?Also why is there 2 )) after "filletrad" ?Why is there "" either side of the filletrad command,is this always the case?Why is there a . next to fillet & also a _ in old_radius?

hyposmurf
4th Jan 2004, 11:53 pm
I fiddled with it again and added the multiple option for a multiple fillet.This is what I came up with.
defun c:fz ()
(setq old_radius (getvar "filletrad"))
(setvar "filletrad" 0)
(command ".fillet" "multiple" pause pause)
(setvar "filletrad" old_radius)
)
:D Cool think its slowly coming together,little things please small minds I guess :)

hendie
5th Jan 2004, 09:21 am
try thinking of the function as a whole list of "sub-functions" within the main function.
the first but...
(DEFUN C:FZ ()
bits of code here
and here
etc
)
the DEFUN notifies Acad that it is a function, the C: defines FZ as a command and the () following FZ is where you place arguments and localise variables.

As to why there are a number of ((())))'s all over the place.

(setq old_radius (getvar "filletrad"))
each parenthesis must be balanced.

the most common problem in Lisp is having a parenthesis in the wrong place, which can cause Acad to evaluate the lisp incorrectly.

hyposmurf
5th Jan 2004, 01:51 pm
:wink: Cheers thats a bit clearer now Hendie,I'll just have plumb away it some more now.Any idea why you use the "" is this to enclose a command?Also the _ is this used to perform enter?

hendie
5th Jan 2004, 02:00 pm
"" is used as an <enter> response. Normally used to terminate a command.
e.g.

(command "LINE" pause pause "")
which breaks down into...
( <<== opens the routine
command "LINE" <<== issues the "Line" command
pause pause <<== tells Acad to pause while you pick two points
"" <<== terminates the command ~ same as if you had hit <enter> or right-clicked
) <<== encloses the routine

the underscore merely enables foreign language support

hyposmurf
5th Jan 2004, 02:15 pm
:wink: Nice now I shall go and play.

fuccaro
5th Jan 2004, 03:22 pm
the underscore merely enables foreign language supportYes, when the underscore appears in a front of a command, it will translate that command (useful if the routine runs on a computer with AutoCAD in a foreign language). Example: (command "_redraw")
But I think Hyposmurf want to read about a construction like
(setvar "filletrad" old_radius)
the space is important in AutoLisp. old_radius is a variable name but writen in this way it is more clear as oldradius.
Here is an example:

&#40;setq old_radius a x 1&#41;this will assign to old_radius the value of a and to x the value 1.
but if I write:

&#40;setq old radius a x 1&#41;that means that I want to assign to old the value of radius, to a the value of x and the final 1 will produce an error message!
As I told earlier, the spaces are important.

David Bethel
5th Jan 2004, 03:39 pm
I fiddled with it again and added the multiple option for a multiple fillet.This is what I came up with.
(defun c:fz ()
(setq old_radius (getvar "filletrad"))
(setvar "filletrad" 0)
(command ".fillet" "multiple" pause pause)
(setvar "filletrad" old_radius)
)



(defun c:fz (/ old_radius) ;|declares old_radius local to this function|;
(setq old_radius (getvar "filletrad"))
(setvar "filletrad" 0)
(command ".fillet" "multiple")
(while (> (getvar "CMDACTIVE") 0)
(command pause));| pauses until a nil value is passed|;
(setvar "filletrad" old_radius)
(prin1)) ;| exits cleanly |;

As to the parenthisis, there is a shareware ALLY that does an excellant job at displaying color matching parenthisis. It also has an anyliser for checking code and variable usage. It was written for DOS but works under Windows: http://www.wascotech.com/

Flores
5th Jan 2004, 08:44 pm
As far as checking the parenthesis, use the built-in lisp editor. Enter "vlide" or "vlisp" at the command line. It has syntax coloring to help differentiate between Built-in functions, Strings, Integers, etc. By double-clicking directly in front of the Open Parenthesis, a "(", it will highlight the closing parenthesis, the ")". This helps in finding the matching parenthesis, or if it's missing one. Also, in the toolbars, there is a button with a white-sheet with a blue-checkmark on it. This is the "check edit window" button. If there is a syntax error in your coding, you will get a:
"[CHECKING TEXT yourlisp.lsp loading...]
; error: malformed list on input
; Check done.
:

Flores

hyposmurf
5th Jan 2004, 10:30 pm
Cool now Im starting to get somewhere,if I keep asking lots of silly questions in this thread maybe Ill understand it all fully :) .I've run though that "check edit window",didnt return any errors,so I tried making an error by taking out a ).Error returned "error: malformed list on input",also loaded another that contains a collection of my frequently used lisps.Returned this error too many arguments: (EVAL (QUOTE ( ... )) ZZ#T).Where would I be able to find a list of errors and remedies?Also once I step into the check edit window,how do I return back to where I was originally with just my lisp open?Can do it by just reopeing it,this right?Soz for all the questions Im determined to have a crack at autolisp,so long as I have time on my hands . :) Last time I tried I looked at some book that wasnt too clear and didnt relate to what I was doing too well so I lost interest.

David Bethel
5th Jan 2004, 10:43 pm
Autolisp errors are vauge at best. It has always been one of it's shortcomings. My personal least favorite is 'bad agrument type'

Also A2K has done away with returning the code upon a run time error. It used to be (setq *error* nil) and any error would return the offending line of code and the remaining code. I find the current error setup very annoying.

I lot of people ( myself included ) do not like the built in vlisp editor. I prefer a DOS editor. Good Luck!

Flores
7th Jan 2004, 07:30 pm
I don't know how to use the vlide to it's fullest extent, I use it as a glorified Notepad/editor. The color syntax helps out, and there are a few other things I like about it. One of the things I like is the "load active window button", which is 2 buttons to the left of the "check edit window button". Whenever you use Notepad, you have to save any changes/modifications before you can load it into ACAD. In vlide, you can load your LISP into ACAD, and if the routine, or any changes you made to it didn't work, all you have to do is "Undo" your changes. The "format edit window" is another useful tool to make your routine look "pretty". Some do not like the vlide because it is "bloated" and "complicated", but the exact same thing is said about AutoCAD. I just use what I need, and I don't care if there are tons of tools that I don't use in it.

Flores