PDA

View Full Version : reworded question



tk2
15th Aug 2005, 03:03 pm
alright, I need some help with writting some code since this is my first time using autoLISP (it's for a summer project i've been working on). I posted a question earlier about the ucs and circle commands but I think I need to reword it.

I guess what I want to know is how to use the commands with variables.
Here is an example of what I know how to do:

(defun c:circle()
(command "circle" "2,2,2" "4"))

which of course will draw a circle at (2,2,2) with a radius of 4, which is great if all I needed to do was draw one circle...but I'm guessing there is a way to draw as many circle's as I want while changine the location and radius if i want to but I can't seem to figure out how.
for example, I've tried the following but they obviously don't work:

(defun c:circle()
(setq a 2)
(command "circle" "a,a,a" "4"))

or

(defun c:circle()
(setq a 2)
(command "circle" list(a a a) "4"))

or

(defun c:circle()
(setq a 2)
(repeat 4 (setq a (+ a 1))
(command "circle" "2,2,2" a)))

plus many other ways of trying to write it with and without quotations. so what I'm getting at is that I obviously am missing some of the fundamentals of how autoLISP works. if someone could explain how I could use this command with a variable, or more specifically with a changing variable I would really appreciate it!
thanks
troy

CADTutor
15th Aug 2005, 03:35 pm
Well, you could do this:


(defun c:round()
(setq a "2")
(setq pt (strcat a "," a "," a))
(command "circle" pt "4"))

First point to make is that you sould NEVER use an existing command name as your LISP routine name unless you specifically intend to replace that command. Notice that I've called mine "round".

In this code I assign the variable 2 as a string and then use strcat to build the x,y,z point. This is just one way of doing what you need and how you actually do it will depend on how you want the routine to develop.

To repeat a part of the routine, you should look at using a WHILE loop and test for a condition in order to end it at a particular value.