View Full Version : Need help with Lisp: combining points
keelay711
2004-12-10, 03:16 AM
I just started trying to program lisp after getting my feet wet at AU. That comic was great, wasn't he? =)
So here is my dilemma... I need to create objects at a certain point relative to a point already given by the user. For simplicity's sake, I want to create a circle at that 2nd point. How do I setup the point input?
The command itself is simple. I have that much.
(command "circle" (0,0,0) "d" column_dia)
But I want to do this:
(command "circle" (0 + variable,0 + variable ,0) "d" column_dia)
Another thing I need is to move an object to the 2nd point:
(command "move" "last" "@" "@variable<0)
(command "move" "last" "@" "@variable<90)
or
(command "move" "last" "@" "@variable, variable, 0")
How do I put together the variable with the string in these cases? I'm sure strcat is needed, but it seems I am too novice to get it to work.
I have been looking though the help file, but I just haven't been able to figure it out from there. I would greatly appreciate any help you can provide.
RobertB
2004-12-10, 04:02 AM
I moved this thread into the AutoLISP forum.
Ok, let's assume you got the point and saved it to variable:
(setq pt (getpoint "\nSpecify point: "))
Now, in your example, you aren't really displacing the circle from the selected point. You are using 0,0,0 there. So the code would be:
(command "._Circle" "_Non" pt "_D" column_dia)
If you really wanted to displace the circle (I'm going to assume by predetermined displacement) then you need to perform some math on the two point lists. (mapcar) lets you perform an operation on multiple lists. So the code would be:
(setq displace (list 1.0 1.0 0.0)) ; my assumed displacement
(setq newpt (mapcar '+ pt displace)) ; calculated point
(command "._Circle" "_Non" newpt "_D" column_dia)
So for your 2nd question, you could just use the displace variable in my example:
(command "._Move" "_L" "" "" displace) ; note that I did not provide a 1st point!
Now, I gave you this sample, but in all honesty, your post was still a bit vague on exactly what you are attempting to do. I hope I helped.
rkmcswain
2004-12-10, 04:06 AM
; Set up the column diameter
(setq column_dia 1.0)
; Set up first point
(setq pt1 (list 0 0 0))
; Specify delta from first point
(setq xdelta 3.8 ydelta 2.7 zdelta 0.0)
; Create second point
(setq pt2 (list (+ (car pt1) xdelta)(+ (cadr pt1) ydelta)(+ (caddr pt1) zdelta)))
; Draw the circle
(command "._circle" pt2 "_d" column_dia)
; Create your next point
(setq pt3 (polar pt2 (* pi 0.5) 2.0))
; Move the last entity to new point
(command "._move" (entlast) "" pt2 pt3)
-------------------------------------------------------------
Oops....Roberts example is more concise. I was a little more verbose in order to illustrate more clearly what is going on. Hope the two different examples don't confuse you more....
kennet.sjoberg
2004-12-10, 12:52 PM
keelay711, You may take a look at the polar function in
[AutoLISP Reference: P Functions polar ]
(polar pt ang dist)
: ) Happy Computing !
kennet
todd.mackay
2004-12-10, 02:18 PM
I moved this thread into the AutoLISP forum.
Ok, let's assume you got the point and saved it to variable:
(setq pt (getpoint "nSpecify point: "))
Now, in your example, you aren't really displacing the circle from the selected point. You are using 0,0,0 there. So the code would be:
(command "._Circle" "_Non" pt "_D" column_dia)
If you really wanted to displace the circle (I'm going to assume by predetermined displacement) then you need to perform some math on the two point lists. (mapcar) lets you perform an operation on multiple lists. So the code would be:
(setq displace (list 1.0 1.0 0.0)) ; my assumed displacement
(setq newpt (mapcar '+ pt displace)) ; calculated point
(command "._Circle" "_Non" newpt "_D" column_dia)
So for your 2nd question, you could just use the displace variable in my example:
(command "._Move" "_L" "" "" displace) ; note that I did not provide a 1st point!
Now, I gave you this sample, but in all honesty, your post was still a bit vague on exactly what you are attempting to do. I hope I helped.
Sorry to intervene, but what is the difference between "._Circle" and "_Circle" - Also, what does "_Non" do in that same example?
stig.madsen
2004-12-10, 03:10 PM
Sorry to intervene, but what is the difference between "._Circle" and "_Circle" - Also, what does "_Non" do in that same example?
Ever worked with a German localized version of AutoCAD?
Befehl: KREIS
3P/2P/TTR/<Mittelpunkt>: Keiner von ... etc.
"KREIS" is the German CIRCLE command and "Keiner" is the None object snap. Because there are numerous localized versions out there, AutoCAD provides a way to override localized names. This is done by prefixing the native command name with an underscore. By using, say, "_CIRCLE" in an AutoLISP routine (or menumacro or VBA macro) you ensure that it will invoke the CIRCLE command no matter which localized version is being used (same thing with subcommands and object snaps such as "_none").
The dot prefix - or period - is for accessing the original command in case a command has been redefined.
A hyphen will invoke the command line version of an otherwise dialog-based command (if a command line version exists).
So, to invoke the original command line version of a LAYER command - independent of localized versions - you could use the form "._-LAYER" :)
RobertB
2004-12-10, 08:00 PM
In addition to what Stig mentioned, whenever you are providing points via the command pipeline, it would be best to temporarily disable running OSnaps. Using the None override accomplishes this without the overhead of storing the old OSMode value, toggling running OSnaps off, and restoring the original OSMode.
keelay711
2004-12-10, 11:55 PM
I thank everyone for their help in this matter. I really am just barely starting out in lisp. To clarify what I was attempting to do:
The program will
- draw a circular reservoir with its walls and footings on appropriate layers (DONE)
- draw columns with their footings at a specified spacing inside the tank (PROBLEM)
I tried following RobertB's example, but there seems to be a problem with the list and the requested point entry for the move command.
(setq offset (getreal "\nWhat is the column offset? (feet): ")) ; user input
(setq inch_offset (* 12 offset)) ; converts to inches to avoid imperial notation
(setq displace (list inch_offset inch_offset 0)) <---- CAN I DO THIS WITH LIST?
(command "move" "last" "" "" displace) <---- THIS GIVES INVALID BASE POINT
Am I missing something blatantly obvious?
rkmcswain
2004-12-11, 01:21 AM
(initget 3)
(setq offset (getreal "\nEnter column offset in feet: "))
(setq inch_offset (* 12.0 offset))
(setq displace (list inch_offset inch_offset 0))
(command "._move" "last" "" displace "")
Your input for the move command was not in the correct order.
The easiest way to figure this out is to go to the command line in AutoCAD and run the command in question, supplying the prompts in your (command) string.
As for your question "CAN I DO THIS WITH LIST?", what are you using to edit your code? If you are using the VLIDE, it's very easy to step through your code one line at a time and see the results of each operation. This would have answered your question in a few seconds.
Good luck
RobertB
2004-12-11, 03:00 AM
That's what I get for not testing each statement, no? ;-)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.