Create rectangle with different offsets of sides form the polyline.

Create rectangle with different offsets of sides form the polyline.

geoferoze
Participant Participant
2,168 Views
10 Replies
Message 1 of 11

Create rectangle with different offsets of sides form the polyline.

geoferoze
Participant
Participant

How to create rectangle using a polyline (rectangle with different offsets of sides form the polyline) using LIPS.rec_offsets.jpg

 

0 Likes
Accepted solutions (1)
2,169 Views
10 Replies
Replies (10)
Message 2 of 11

DGRL
Advisor
Advisor

Hi

 

Pls be more specific

Do you want a fixed size?

Do you want user input?

How many rectangles do you need to create?

.......

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 3 of 11

Kent1Cooper
Consultant
Consultant

Another question that comes to mind, if the white center-line object is the original Polyline you're starting from:  Will it always be orthogonal?  The task would be much easier if it would always be [whether horizontal or vertical], but it could be worked out if it might be diagonal.  

Kent Cooper, AIA
0 Likes
Message 4 of 11

geoferoze
Participant
Participant

Thanks for your response...

 

Do you want a fixed size?

No, my rectangle based on the length of polyline/line.

 

Do you want user input?

Yes, offsets from polyline in 4 direction to be specified by the user after draw a polyline/ line.

  

How many rectangles do you need to create?

Each polyline/line separate rectangle.

0 Likes
Message 5 of 11

geoferoze
Participant
Participant

The white line is diagonal or any directions.

 


@Kent1Cooperwrote:

Another question that comes to mind, if the white center-line object is the original Polyline you're starting from:  Will it always be orthogonal?  The task would be much easier if it would always be [whether horizontal or vertical], but it could be worked out if it might be diagonal.  


 

0 Likes
Message 6 of 11

ВeekeeCZ
Consultant
Consultant

Maybe like this?

 

(vl-load-com)

(defun c:RectangPl (/ ensel p1 p2)

  (if (setq ensel (entsel "\nSelect polyline closed to 0.25-offset end: "))
    (progn
      (setq p1 (trans (vlax-curve-getStartPoint (car ensel)) 0 1)
            p2 (trans (vlax-curve-getEndPoint (car ensel)) 0 1))
      (if (< (distance p1 (cadr ensel))
             (distance p2 (cadr ensel)))
        (command "_.rectang"
                 "_none" (polar p1 (+ (angle p1 p2) (* 0.75 pi)) (sqrt 0.125))
                 "_r" (angtos (angle p1 p2) (getvar 'AUNITS) 12)
                 "_none" (polar p2 (+ (angle p1 p2) (* 1.75 pi)) (sqrt 0.5)))
        (command "_.rectang"
                 "_none" (polar p2 (+ (angle p2 p1) (* 0.75 pi)) (sqrt 0.125))
                 "_r" (angtos (angle p2 p1) (getvar 'AUNITS) 12)
                 "_none" (polar p1 (+ (angle p2 p1) (* 1.75 pi)) (sqrt 0.5)))
        )
      (initget "Yes")
      (if (getkword "\nMirror? [Yes] <no>: ")
        (command "_.mirror" "_l" "" "_none" p1 "_none" p2 "_Yes" ))))
  (princ)
)
0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@geoferoze wrote:

.... 

Do you want a fixed size?

No, my rectangle based on the length of polyline/line.

Do you want user input?

Yes, offsets from polyline in 4 direction to be specified by the user after draw a polyline/ line.

....


How about this?

(defun C:RAL ; = Rectangle Around Line
  (/ ent p1 p2 ang off1 off2 off3 off4)
  (setq
    ent (entlast); for use immediately after drawing Line or 1-line-segment Polyline
    p1 (vlax-curve-getStartPoint ent)
    p2 (vlax-curve-getEndPoint ent)
    ang (angle p1 p2)
    off1 (getdist "\nOffset back from start of Line/Polyline: ")
    off2 (getdist "\nOffset past end of Line/Polyline: ")
    off3 (getdist "\nOffset to left of drawn direction of Line/Polyline: ")
    off4 (getdist "\nOffset to right of drawn direction of Line/Polyline: ")
  ); setq
  (command "_.pline"
    "_none" (polar (polar p1 (+ ang pi) off1) (+ ang (* pi 1.5)) off4)
    "_none" (polar (polar p2 ang off2) (+ ang (* pi 1.5)) off4)
    "_none" (polar (polar p2 ang off2) (+ ang (/ pi 2)) off3)
    "_none" (polar (polar p1 (+ ang pi) off1) (+ ang (/ pi 2)) off3)
    "_close"
  ); command
  (princ)
); defun

It could be adjusted to include the drawing of the Line/Polyline inside it, and/or to apply the same offsets to make rectangles around any number of selected Lines/Polylines, and probably some other things. 

Kent Cooper, AIA
0 Likes
Message 8 of 11

geoferoze
Participant
Participant

Thanks, its working....


@Kent1Cooperwrote:

@geoferozewrote:

.... 

Do you want a fixed size?

No, my rectangle based on the length of polyline/line.

Do you want user input?

Yes, offsets from polyline in 4 direction to be specified by the user after draw a polyline/ line.

....


How about this?

(defun C:RAL ; = Rectangle Around Line
  (/ ent p1 p2 ang off1 off2 off3 off4)
  (setq
    ent (entlast); for use immediately after drawing Line or 1-line-segment Polyline
    p1 (vlax-curve-getStartPoint ent)
    p2 (vlax-curve-getEndPoint ent)
    ang (angle p1 p2)
    off1 (getdist "\nOffset back from start of Line/Polyline: ")
    off2 (getdist "\nOffset past end of Line/Polyline: ")
    off3 (getdist "\nOffset to left of drawn direction of Line/Polyline: ")
    off4 (getdist "\nOffset to right of drawn direction of Line/Polyline: ")  ); setq
  (command "_.pline"
    "_none" (polar (polar p1 (+ ang pi) off1) (+ ang (* pi 1.5)) off4)
    "_none" (polar (polar p2 ang off2) (+ ang (* pi 1.5)) off4)
    "_none" (polar (polar p2 ang off2) (+ ang (/ pi 2)) off3)
    "_none" (polar (polar p1 (+ ang pi) off1) (+ ang (/ pi 2)) off3)
    "_close"
  ); command
  (princ)
); defun

It could be adjusted to include the drawing of the Line/Polyline inside it, and/or to apply the same offsets to make rectangles around any number of selected Lines/Polylines, and probably some other things. 


Thanks, its working....

0 Likes
Message 9 of 11

nkohut
Explorer
Explorer

Kent,

 

Very cool lisp, I've been looking for something like this for a while now.

 

Couple questions:

1. Could this lsp be modified to prompt the user to select the line to be offset rather than the most recent line drawn?

 

2. Could it be modified to prompt the user for a single distance so the distance is the same on all sides?

 

Thanks Kent, this is very cool!

0 Likes
Message 10 of 11

Sea-Haven
Mentor
Mentor

The obvious next question easily solved with UCS OB. Bit busy right now will do the rest.

 

SeaHaven_1-1633668072462.png

 

 

 

 

0 Likes
Message 11 of 11

Kent1Cooper
Consultant
Consultant

@nkohut wrote:

....

1. Could this lsp be modified to prompt the user to select the line to be offset rather than the most recent line drawn?

2. Could it be modified to prompt the user for a single distance so the distance is the same on all sides?

....


Try this [untested]:

(defun C:RAL ; = Rectangle Around Line
  (/ ent p1 p2 ang off)
  (setq
    ent (car (entsel "\nSelect Line or 1-line-segment Polyline: "))
    p1 (vlax-curve-getStartPoint ent)
    p2 (vlax-curve-getEndPoint ent)
    ang (angle p1 p2)
    off (getdist "\nOffset from Line/Polyline: ")
  ); setq
  (command "_.pline"
    "_none" (polar (polar p1 (+ ang pi) off) (+ ang (* pi 1.5)) off)
    "_none" (polar (polar p2 ang off) (+ ang (* pi 1.5)) off)
    "_none" (polar (polar p2 ang off) (+ ang (/ pi 2)) off)
    "_none" (polar (polar p1 (+ ang pi) off) (+ ang (/ pi 2)) off)
    "_close"
  ); command
  (princ)
); defun
Kent Cooper, AIA
0 Likes