Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How to create rectangle using a polyline (rectangle with different offsets of sides form the polyline) using LIPS.
Solved! Go to Solution.
How to create rectangle using a polyline (rectangle with different offsets of sides form the polyline) using LIPS.
Solved! Go to Solution.
Hi
Pls be more specific
Do you want a fixed size?
Do you want user input?
How many rectangles do you need to create?
.......
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.
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.
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.
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) )
@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.
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) ); defunIt 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....
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!
@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