Jump to content

Recommended Posts

Posted

Hello
P1 and P2: Will they always be indicated in the drawing with two x-shaped lines?

Posted

Simplest

 

(defun c:DrawRect ( / Pt1 Pt2 Rect)
  (setq Pt1 (Getpoint "Select Point 1"))
  (setq Pt2 (Getpoint "Select Point 2"))
  (command "Rectangle" Pt1 Pt2)
  (entlast)
)

 

Not sure as it is whether this adds much where you could just do rectangle command, might be that you are doing something else.

Posted

@Steven P

 

I think the @Mountain_XD want to draw a rectangle between two selected points in that way the rectangle will be drawn inside the yellow polylines (I think that is walls) at desired height (T) in total length between two selected points. I think I understand correctly based on drawing.

  • Like 1
Posted
8 hours ago, Mountain_XD said:

Help me to Draw Rectang by Window P1-P2

Maybe something like that:

(defun c:Off-Rect ( / pt1 pt2 offsetDistance newPt1 newPt2 newPt3 newPt4)

  (setq pt1 (getpoint "\nSpecify the first point: "))
  (setq pt2 (getpoint "\nSpecify the second point: "))
  
  (setq offsetDistance (getdist "\nEnter the offset distance on the X-axis: "))
  
  (setq newPt1 (list (- (car pt1) offsetDistance) (cadr pt1) (caddr pt1)))  
  (setq newPt2 (list (+ (car pt2) offsetDistance) (cadr pt1) (caddr pt1)))  
  (setq newPt3 (list (+ (car pt2) offsetDistance) (cadr pt2) (caddr pt2)))  
  (setq newPt4 (list (- (car pt1) offsetDistance) (cadr pt2) (caddr pt2)))  

  (command "_.PLINE" newPt1 newPt2 newPt3 newPt4 "_C")
  
  (princ "\nThe rectangle has been successfully drawn.")
  (princ)
)

 

Posted (edited)

Not quite Nikon, I think the OP want the width of the rectangle to be 'T' in the sample drawing, where your width depends on the points chosen? I'd also add a "_non" in for each point. Think you also need to work out which point is left and right in case the user selects right to left or left to right,

 

So back to the OP, it isn't quite as simple as selecting an area and automatically drawing the rectangle. If you are happy with your selection being a top corner and the opposite bottom corner of the cut out that makes things easier:

 

An negative offset will leave a gap, no overlap, with the new rectangle and the walls

 

(defun c:Off-Rect ( / Offset Old_Snap pt1 pt2 pta ptb ptc ptd pta1 pta2 ptb1 ptb2)
  (setq Offset (getdist "\nSet the X axis offset distance: "))  ;; Get the offset distance. User cancels here, no snap changes
  (setq Old_Snap (getvar 'OSMODE))                              ;; Record current snap setting
  (setvar 'OSMODE 1)                                            ;; Set snap to end point. If cancel stays at end point. Add error checks
  (setq pt1 (getpoint "Select a TOP corner"))                   ;; Get a corner
  (setq pt2 (getpoint pt1 "Select the Opposite LOWER corner"))  ;; Get 2nd corner
  (setvar 'OSMODE Old_Snap)                                     ;; Reset snap

  (setq pta (car pt1))                                          ;; X and Y values for the coordinates
  (setq ptb (cadr pt1))
  (setq ptc (car pt2))
  (setq ptd (cadr pt2))

  (setq pta1 (list (+ (min pta ptc) -125) (max ptb ptd)))       ;; Top Left corner
;;  (setq pta2 (list (min pta ptc) (min ptb ptd)))  ;; just for completion ;; Bottom Left Corner
;;  (setq ptb1 (list (max pta ptc) (max ptb ptd)))  ;; Just for completion ;; Top Right Corner
  (setq ptb2 (list (+ (max pta ptc) 125) (min ptb ptd)))        ;; Bottom Right corner

  (command "rectangle" "_non" pta1 "_non" ptb2 )                ;; Draw Rectangle
  (princ_) ;; Exit quietly
)

 

 

Edited by Steven P
Posted (edited)

My $0.05 a different approach, you can pick a line/pline near an end point, you do this twice for the p1 p2 points, you enter a offset value and new rectang is drawn. A lot more code but works out the correct p1 p2 etc based on direction and distance from end of a line or pline segment. Matches your dwg picking p1 p2. You can have different offsets if you want for each side.

 

A manual test is draw a circle with set radius from 2 corner points, then use the points as selected via intersection snap to draw the rectang.

 

Edited by BIGAL
Posted

Thanks to GLAVCVS, Steven P, Saxlle, Nikon, BIGAL for responding to help me, but you misunderstood my intention, the purpose is to draw the lintel by expanding the window to select through two points p1 and p2. The yellow line is the wall, T is the wall thickness, the purple line is the rectangent to draw, that is the lintel beam, the value 250 is entered by the user. The lintel thickness is equal to the wall thickness. I have attached a new file. Please help me fix the code. Thank you very much.

How to Draw Rectang by Window P1-P2 (Re).dwg

Posted

Thanks to GLAVCVS, Steven P, Saxlle, Nikon, BIGAL for responding to help me, but you misunderstood my intention, the purpose is to draw the lintel by expanding the window to select through two points p1 and p2. The yellow line is the wall, T is the wall thickness, the purple line is the rectangent to draw, that is the lintel beam, the value 250 is entered by the user. The lintel thickness is equal to the wall thickness. I have attached a new file. Please help me fix the code. Thank you very much.

How to Draw Rectang by Window P1-P2 (Re).dwg

Posted

@SLW210

Please keep this in the same thread. not create a new one asking the same question.

 

Posted
23 minutes ago, mhupp said:

@SLW210

Please keep this in the same thread. not create a new one asking the same question.

 

Thank you for reminding

Posted (edited)

That is what I was suggesting, you can get an end point by just pick near it. Then add the 250 offset and work out the points. Just posted a similar answer at another forum. If you use plines for the yellow wall need to add some more code to get to same point.

image.png.4cf19a7e6541763eb784fd3b5f0d7ffb.png

 

; Simple draw rectang based on two points
; By AlanH March 2025

(defun c:lintel ( / pt1 pt2 pt3 pt4 ang1 ang2)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'clayer "Import_columns")
(setq off 250) ; change this to a getreal if want different offset.
(setvar 'clayer "Import_columns")
(defun whichend ( / )
(setq ent (entsel "\nSelect line near end "))
  (setq ename (entget (car ent)))
  (setq pt (cadr ent))
  (setq pt1 (cdr (assoc 10 ename)))
  (setq pt2 (cdr (assoc 11 ename)))
  (setq ang2 (angle pt1 pt2))
  (setq d1 (distance pt pt1))
  (setq d2 (distance pt pt2))
  (if (> d1 d2)
   (setq tmp pt1
     pt1 pt2
     pt2 tmp)
  )
(princ)
)

(whichend)
(setq ang (angle pt1 pt2))
(setq pt3 (polar pt1 ang off))
(whichend)
(setq ang (angle pt1 pt2))
(setq pt1 (polar pt1 ang off))

(command "rectang" pt1 pt3)

(setvar 'osmode oldsanp)
(princ)

 

 

Did find a bug, will fix, its a hiccup with using "Rectang" will change code to draw a 4 point pline so angle is not a problem.

image.png.8e48e188cd87cd5fbe590b2533c215bd.png

Edited by BIGAL
Posted

Thank you so much BIGAL !

Posted

I merged the 2 threads. Please keep just one thread for your topic.

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

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

×
×
  • Create New...