### Author Topic: WHAT IS WRONG IN CODE ??? afralisp  (Read 1754 times)

0 Members and 1 Guest are viewing this topic.

#### Sam

• Bull Frog
• Posts: 201
##### WHAT IS WRONG IN CODE ??? afralisp
« on: May 27, 2016, 02:16:19 PM »
DEAR ALL
WHAT IS WRONG IN CODE
Code: [Select]
`AUTOCAD 2016, WINDOWS 10, 64 BIT`
Quote
(defun c:retan (/ pl p2 p3 p4)
(setq pl (getpoint "\nfirst corner of rectangle: "))
(setq p3 (getcorner "\nsecond corner of rectangle: "))
(setq p2 (list (car pl)(cadr p3)))
(setq p4 (list (car p3)(cadr pl)))
(command "line" pl p2 p3 p4 "c")
(princ)
)

Quote
Command: RETAN

first corner of rectangle: ; error: base point is required

http://www.afralisp.net/autolisp/tutorials/quick-start.php
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

#### ChrisCarlson

• Guest
##### Re: WHAT IS WRONG IN CODE ??? afralisp
« Reply #1 on: May 27, 2016, 02:20:39 PM »
Try adding _non and the base point for p3. Also I changed pl to p1 for clarity.

Code - Auto/Visual Lisp: [Select]
1. (defun c:retan (/ p1 p2 p3 p4)
2. (setq p1 (getpoint "\nfirst corner of rectangle: "))
3. (setq p3 (getcorner p1 "\nsecond corner of rectangle: "))
4. (setq p2 (list (car p1)(cadr p3)))
5. (setq p4 (list (car p3)(cadr p1)))
6. (command "line" "_non" p1 "_non" p2 "_non" p3 "_non" p4 "c")
7. )

Quote
The getcorner function takes a base point argument, based on the current UCS, and draws a rectangle from that point as the user moves the crosshairs on the screen.

#### BKT

• Newt
• Posts: 27
##### Re: WHAT IS WRONG IN CODE ??? afralisp
« Reply #2 on: May 27, 2016, 02:49:08 PM »
As a point of interest, I've noticed that some of the code on AfraLISP mixes lower case "L" with the numeral "1", so you have to pay special attention if you're doing a cut/paste from the examples.  The result is that it "looks" (as in this case) like "P1" but it's actually "Pl".

It shouldn't affect the OP's code any - just bringing it up because it will cause problems if you don't notice this and try to use the variable later on, but enter it incorrectly.

#### CAB

• Global Moderator
• Seagull
• Posts: 10401
##### Re: WHAT IS WRONG IN CODE ??? afralisp
« Reply #3 on: May 27, 2016, 03:01:04 PM »
Chris's code should work fine but I prefer additional steps to catch errors.
Code - Auto/Visual Lisp: [Select]
1. (defun c:retan (/ p1 p2 p3 p4)
2.   (if (and
3.         (setq p1 (getpoint "\nfirst corner of rectangle: "))
4.         (setq p3 (getcorner p1 "\nsecond corner of rectangle: "))
5.         (setq p2 (list (car p1) (cadr p3)))
6.         (setq p4 (list (car p3) (cadr p1)))
7.       )
8.     (command "line" "_non" p1 "_non" p2 "_non" p3 "_non" p4 "c")
9.   )
10.   (princ)
11. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970