Jump to content

Looking for 2 click centerline rectangle


Tom Matson
 Share

Recommended Posts

I searched for a routine but couldn't find any. 

Looking to draw a rectangle similar to a rich line. Where I can click 2 points and draw a rectangle through the centerline. 

I use mostly 2 widths so the rectangle width would would be predetermined in the lisp routine. I will create a button to initiate the routine. 

Thanks in advance 

Tom

Link to comment
Share on other sites

Yeah, sure.

 

Command TCCR.

 

I let you first enter the width.

Then, since you need that width multiple times I put the rest in a while loop.

 

Of course you can hard code the width and remove the while if you want.

 

;; degrees to rad
(defun deg2rad (deg / )
  (/ (* deg pi ) 180)
)

;; draws a polyline
(defun drawLWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))
				   
;; TCCR for: Two Click Centerline Rectangle
(defun c:TCCR ( / w ang p1 p2 bl br tl tr)
	(setq w (getreal "\nWidth: "))
	
	(while (setq p1 (getpoint "\nPoint 1:"))
		(setq p2 (getpoint "\nPoint 2:" p1))
		;; calculate bottom/left, bottom/right,... 
		(setq ang (angle p1 p2))
		
		(setq bl (polar p1 (- ang (deg2rad 90.0)) (/ w 2.0)))
		(setq tl (polar p1 (+ ang (deg2rad 90.0)) (/ w 2.0)))
		(setq br (polar p2 (- ang (deg2rad 90.0)) (/ w 2.0)))
		(setq tr (polar p2 (+ ang (deg2rad 90.0)) (/ w 2.0)))
		
		(drawLWPoly (list bl br tr tl) 1)
	)
)

 

  • Like 4
Link to comment
Share on other sites

Wow

Works perfect thanks!

Good idea to specify the width first, I didn't think about that.

Thanks Again

Tom

  • Like 1
Link to comment
Share on other sites

Are the widths fixed size if so look at my Multi radio buttons.lsp can have the sizes pre programmed.

 

(setq ans (atoi(ah:butts ahdef "V" '("Choose a number" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"))))

image.png.3a07819a853e036d3ad1b6d2fae69ab7.png

Multi radio buttons.lsp

Edited by BIGAL
  • Like 2
Link to comment
Share on other sites

@BIGAL

I like it.

That is what I was originally thinking.

The routine from Emmanuel gives me the option to enter the width, which I didn't realize how useful that was going to be.

Thanks

Tom

Link to comment
Share on other sites

@Emmanuel Delay

Your TCCR routine works perfectly.

Could we do another one?

Where it functions the same way but it offsets the rectangle to one side of the line?

I tried modifying your code but broke it....lol

Thanks,

Tom

Link to comment
Share on other sites

27 minutes ago, Tom Matson said:

@Emmanuel Delay

Your TCCR routine works perfectly.

Could we do another one?

Where it functions the same way but it offsets the rectangle to one side of the line?

I tried modifying your code but broke it....lol

Thanks,

Tom

 

I'm not sure what exactly you mean.

Could you explain it a bit further (maybe draw a sketch or so)?

Link to comment
Share on other sites

Right now I'm not on the computer, but basically if I have a line or Xline I would like to click 2 points just like your other routine but instead of being centered it would be drawn to one side or the other.

It would still ask me the width of the rectangle just like it does now....

 

 

Link to comment
Share on other sites

;; degrees to rad
(defun deg2rad (deg / )
  (/ (* deg pi ) 180)
)

;; draws a polyline
(defun drawLWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))
				   
;; TCCR for: Two Click Centerline Rectangle
(defun c:TCCR2 ( / w ang p1 p2 bl br tl tr)
	(setq w (getreal "\nWidth: "))
	
	(while (setq p1 (getpoint "\nPoint 1:"))
		(setq p2 (getpoint "\nPoint 2:" p1))
		;; calculate bottom/left, bottom/right,... 
		(setq ang (angle p1 p2))
		
		(setq bl p1)
		(setq tl (polar p1 (+ ang (deg2rad 90.0)) w))
		(setq br p2)
		(setq tr (polar p2 (+ ang (deg2rad 90.0)) w))
		
		(drawLWPoly (list bl br tr tl) 1)
	)
)

@Emmanuel Delay

I figured it out!!

Having your code helped quite a bit.

thanks again.

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...