# LISP routine for Rectangle from Center using Dimensions with specific Angle.

## Recommended Posts

Hi.

I am complete newbie to AUTOCAD lisp routines. Been scouring the forums for this specific routine.

Need to draw a rectangle with center as the starting point then input the dimensions & lastly set the rotation angle.

Have found this routine online (attached below) but it doesn't include rotation specification. Any help would be appreciated.

##### Share on other sites

```(defun c:pp()
(setq c (getpoint "center point ")
a (getdist "side1 ")
b (getdist "side2 ")
rot (getangle "rotation? ")
)

(setq angs (list (setq ang1 (atan b a)) (- PI ang1 )(+ PI ang1) (- ang1))
l (* 0.5 (sqrt(+ (* a a) (* b b))))
plist nil
i -1)
(repeat 4
(setq plist (cons (cons 10 (polar c (+ rot (nth (setq i (1+ i)) angs)) l)) plist)))
(entmake (append (list  '(0 . "LWPOLYLINE")(cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") '( 90 . 4) '(70 . 1)) plist))
)```

See here a quick one. It could be improved a lot

Welcome in the forum!

##### Share on other sites

It works perfectly !

Much appreciated on the swift response.

##### Share on other sites

@afroze9 Thanks for the appreciation.

You could change the name to a relevant one. Also *you* could add some functionalities. If the user enters a value for the first side, that value could be offered as default for the next input. If you need a square, at the second side just press enter and the second side will be like the first one.

Also if the desired rotation angle is zero, you could press just enter - zero should be the default value.

We would be happy to see your progress!

##### Share on other sites

Oh, and I forgot the one modification I should have mention first: localize the variables!

##### Share on other sites

Will definitely update as per these suggestions! Thanks again.

##### Share on other sites

Multi GETVALS.lspLook into using my Multi getvals.lsp for input as fuccaro has suggested can have default values preset, like angle at 0.0. Can save the values in current session so next time ran they will be the default values, but maybe a different angle etc.

Edited by BIGAL
##### Share on other sites

A Google search would show this has been done before several times. I like this dynamic example from Lee Mac.

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

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.