Problem in drawTwoRectangles

Problem in drawTwoRectangles

jaimuthu
Advocate Advocate
818 Views
15 Replies
Message 1 of 16

Problem in drawTwoRectangles

jaimuthu
Advocate
Advocate
(defun c:drawTwoRectangles ()
  (setq pt1 (getpoint "\nSpecify the first corner of the first rectangle: "))
  (setq pt2 (getcorner pt1 "\nSpecify the opposite corner of the first rectangle: "))

  (setq width1 (distance pt1 pt2))
  (setq width2 0.46)

  (command "_rectang" pt1 (polar pt1 (angle pt1 pt2) width1) width1)
  (command "_rectang" pt1 (polar pt1 (angle pt1 pt2) width2) (+ width2 width1))

  (princ)
)
i pick two points two rectangle will be come but error i attached file in detail
0 Likes
Accepted solutions (3)
819 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant

Your RECTANG commands are giving three points, but should give only two.  Can you re-post the drawing with an indication of what locations would be pt1 and pt2?  If they're really opposite corners, then the length of the rectangle 1 will not be the distance between them -- that distance would be the diagonal, and greater than the rectangle's length.  Or should your "opposite corner" in the prompt really be "other end of the long edge"?

Kent Cooper, AIA
0 Likes
Message 3 of 16

jaimuthu
Advocate
Advocate

i want only pick two points p1 and p2 

0 Likes
Message 4 of 16

ВeekeeCZ
Consultant
Consultant

Ok, try this.

 

(defun c:Tworecs ( / w+ p1 p2 ll ur )

  (if (and (setq w+ 0.46)
	   (setq p1 (getpoint "\nSpecify First corner: "))
	   (setq p2 (getcorner p1 "\nSpecify other corner: "))
	   (setq ll (mapcar 'min p1 p2))
	   (setq ur (mapcar 'max p1 p2))
	   )
    (command "_.rectang" "_non" ll "_non" ur
	     "_.rectang" "_non" (mapcar '+ ll (list (* w+ -0.5) (- (cadr ur) (cadr ll)))) "_non" (mapcar '+ ur (list (* w+ 0.5) w+))))
  (princ)
  )

 

This is what mapcar does, if you're interested.

(mapcar '+ '(x1  y1) '(x2  y2)) => '(x1+x2  y1+y2)

0 Likes
Message 5 of 16

komondormrex
Mentor
Mentor

like that?

 

(defun c:drawTwoRectangles ()
  (setq pt1 (getpoint "\nSpecify the first corner of the first rectangle: "))
  (setq pt2 (getcorner pt1 "\nSpecify the opposite corner of the first rectangle: "))
  (command "_rectang" "_non" pt1 "_non" pt2)
  (command "_rectang" "_non" (list (- (min (car pt1) (car pt2)) 0.23) (max (cadr pt1) (cadr pt2)))
	              "_non"(list (+ (max (car pt1) (car pt2)) 0.23) (+ 0.46 (max (cadr pt1) (cadr pt2))))
  )
  (princ)
)

 

 

0 Likes
Message 6 of 16

jaimuthu
Advocate
Advocate

Work perfect thanks but i want also pick vertical wall side this code work is horizontal wall now i attached file for your reference

0 Likes
Message 7 of 16

jaimuthu
Advocate
Advocate

Work perfect thanks but i want also pick vertical wall side this code work is horizontal wall now i attached file for your reference

0 Likes
Message 8 of 16

komondormrex
Mentor
Mentor
Accepted solution

horizontal and vertical

(defun c:drawTwoRectangles ()
  (setq pt1 (getpoint "\nSpecify the first corner of the first rectangle: "))
  (setq pt2 (getcorner pt1 "\nSpecify the opposite corner of the first rectangle: "))
  (command "_rectang" "_non" pt1 "_non" pt2)
  (if (> (distance pt1 (list (car pt2) (cadr pt1))) (distance pt1 (list (car pt1) (cadr pt2))))
	  (command "_rectang" "_non" (list (- (min (car pt1) (car pt2)) 0.23) (max (cadr pt1) (cadr pt2)))
		              "_non" (list (+ (max (car pt1) (car pt2)) 0.23) (+ 0.46 (max (cadr pt1) (cadr pt2))))
	  )
    	  (command "_rectang" "_non" (list (max (car pt1) (car pt2)) (- (min (cadr pt1) (cadr pt2)) 0.23))
		              "_non" (list (+ (max (car pt1) (car pt2)) 0.46) (+ 0.23 (max (cadr pt1) (cadr pt2))))
	  )
  )
  (princ)
)

 

0 Likes
Message 9 of 16

jaimuthu
Advocate
Advocate

its work good  thanks 

0 Likes
Message 10 of 16

calderg1000
Mentor
Mentor

Regards @jaimuthu 

Try this code...

 

(defun c:Mkr (/ p1 p2 p1x p2x)
  (setq p1  (getpoint "\nSpecify the first corner of the first rectangle: ")
        p2  (getcorner p1 "\nSpecify the opposite corner of the first rectangle: ")
        p1x (mapcar '+ (mapcar '(lambda (x y) (/ (+ x y) 2.)) p1 p2) (list (- (+ (* (abs (- (car p1) (car p2))) 0.5) 0.23)) (* (abs (- (cadr p1) (cadr p2))) 0.5) 0.))
        p2x (mapcar '- (mapcar '(lambda (x) (* x 2)) (polar (mapcar '(lambda (x y) (/ (+ x y) 2.)) p1 p2) (* pi 0.5) (+ (* (abs (- (cadr p1) (cadr p2))) 0.5) 0.23))) p1x))
  (command "_rectang" "_non" p1 "_non" p2 "_rectang" p1x p2x
          )
  (princ)
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 11 of 16

jaimuthu
Advocate
Advocate

Thanks its work one side of wall i want four side of wall i attach file in detail

0 Likes
Message 12 of 16

jaimuthu
Advocate
Advocate

Your code work its fine but it work two side of the wall i want four side of wall i attach the file in detail what i want

0 Likes
Message 13 of 16

komondormrex
Mentor
Mentor
Accepted solution

hi,

check the code below. second rectangle is drawn towards direction of minor side of first rectangle.

(defun c:drawTwoRectangles (/ pt1 pt2 pt3 pt4 delta_x_y)
  (setq pt1 (getpoint "\nSpecify the first corner of the first rectangle: "))
  (setq pt2 (getcorner pt1 "\nSpecify the opposite corner of the first rectangle: "))
  (setq delta_x_y (mapcar '- pt2 pt1))
  (command "_rectang" "_non" pt1 "_non" pt2)
  (if (apply '> (mapcar '+ '(0 0) (mapcar 'abs delta_x_y)))
	  (setq pt3 (list (+ (max (car pt1) (car pt2)) 0.23) (cadr pt2))
	        pt4 (list (- (min (car pt1) (car pt2)) 0.23)
			  (+ (cadr pt3) (* (/ (cadr delta_x_y) (abs (cadr delta_x_y))) 0.46))
		    )
          )
    	  (setq pt3 (list (car pt2) (+ (cadr pt2) (* (/ (cadr delta_x_y) (abs (cadr delta_x_y))) 0.23)))
	        pt4 (list (+ (car pt3) (* (/ (car delta_x_y) (abs (car delta_x_y))) 0.46))
			  (- (cadr pt1) (* (/ (cadr delta_x_y) (abs (cadr delta_x_y))) 0.23))
		    )  
          )
  )
  (command "_rectang" "_non" pt3 "_non" pt4)
  (princ)
)

 

0 Likes
Message 14 of 16

jaimuthu
Advocate
Advocate
thanks this is i want thanks for your reply
0 Likes
Message 15 of 16

calderg1000
Mentor
Mentor
Accepted solution

Regards @jaimuthu 

Try this code, maybe it helps some...

;;;___
(defun c:Mkrs (/ p1 p2 l h pm1 pm2 p1x p2x ss p)
  (princ "\n Top Wall...")
  (setq p1  (getpoint "\nSpecify the first corner of the first rectangle: ")
        p2  (getcorner p1 "\nSpecify the opposite corner of the first rectangle: ")
        l   (abs (- (car p1) (car p2)))
        h   (abs (- (cadr p1) (cadr p2)))
        pm1 (mapcar '(lambda (x y) (/ (+ x y) 2.)) p1 p2)
        pm2 (polar pm1 (* pi 0.5) (+ (* h 0.5) 0.23))
        p1x (mapcar '+ pm1 (list (- (+ (* l 0.5) 0.23)) (* h 0.5) 0.))
        p2x (mapcar '- (mapcar '(lambda (x) (* x 2)) pm2) p1x)
  )
  (setq ss (ssadd))
  (command "_rectang" p1 p2)
  (ssadd (entlast) ss)
  (command "_rectang" p1x p2x)
  (ssadd (entlast) ss)
  (princ "\n Botton Wall...")
  (command "_mirror" ss "" (setq p (getpoint "\nPick point in the middle of the right side wall...")) (getpoint p) "")
  (princ "\n Rigth Wall...")
  (command "_mirror" ss "" (setq p (getpoint "\nPPick a point at the top corner of the right side wall...")) (getpoint p) "")
  (princ "\n Left Wall...")
  (command "_mirror" ss "" (setq p (getpoint "\nPick a point at the top corner of the Left side wall...")) (getpoint p) "")
  (princ)
)

 

 

 

 

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 16 of 16

pbejse
Mentor
Mentor

is there a time that the rectangle is at an angle other that 0 and 90?

0 Likes