AutoLISP: Rectangle from the Midpoint of sides

Sidenote: there is a blog that has been stealing my content without any recognition of who actually made the content and then collecting $ off its ads. Because of this, I am going to start adding watermarks in my pictures and a direct link into my posts so that if they want to modify my posts without permission, it will be very obvious that they are stealing from this blog. http://wp.me/p1aURt-jr

https://autocadtips.wordpress.com/2011/12/08/auotlisp-rectangle-from-the-midpoint-of-sides/ ‎

If you need create any type of lines (cable, wire, piping…) this may be a helpful routine. It simply lets you create a rectangle by picking to points that define the midpoints of the opposing sides and then define the length of those sides. the great thing is that it works at any angle.

Here’s how:

  • RECT3V <enter> to start
  • Specify the midpoint of the 1st side
  • Specify the midpoint of the 2nd side
  • Specify the overall length of the side (which will apply to both sides)

; David Bethel

; found at http://www.cadtutor.net/forum/showthread.php?63494-Lisp-for-rectangle

; Creates a rectangle from the mid points of opposing sides and then specify the length of the sides

(defun c:rect3v (/ p1 p2 d1 c1 c2 c3 c4)

(initget 1)

(setq p1 (getpoint "\nCenter Of 1st Side: "))

(initget 1)

(setq p2 (getpoint p1 "\nCenter Of 2nd Side: "))

(grdraw p1 p2 2 1)

(initget 7)

(setq d1 (getdist "\nOpposing Width: "))

(setq c1 (polar p1 (+ (angle p1 p2) (* pi 0.5)) (* d1 0.5))

c2 (polar p1 (+ (angle p1 p2) (* pi -0.5)) (* d1 0.5))

c3 (polar p2 (+ (angle p2 p1) (* pi 0.5)) (* d1 0.5))

c4 (polar p2 (+ (angle p2 p1) (* pi -0.5)) (* d1 0.5)))

(entmake (list (cons 0 "POLYLINE")(cons 66 1)(cons 70 1)(list 10 0 0 0)))

(foreach v '(c1 c2 c3 c4)

(entmake (list (cons 0 "VERTEX")

(cons 10 (eval v)))))

(entmake (list (cons 0 "SEQEND")))

(prin1))
Advertisements

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: Creating, Polylines. Bookmark the permalink.

2 Responses to AutoLISP: Rectangle from the Midpoint of sides

  1. rafiq says:

    i need lisp program for a rectangle with slot cut in it. we can change as per our dimension that is it should be lke a shim.

  2. sean says:

    If I try this lisp routine it only works from points clicked on the screen, what about if I wanted to use a point number instead of clicking on the screen? I tried typing ‘PN but I get an error message that says “invalid point” even when the points are flattened to the 0 elevation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s