# Thread: Offset rectangle into separate lines ?

1. ## Offset rectangle into separate lines ?

Registered forum members do not see this ad.

Hi ALL,

You know how when you offset a rectangle it it stay as a polyline? i need a lisp routine that i can use to offset the rectangle, set the new lines to current layer, and substract the offset distance from both end of the line. i know thats asking alot but has anyone seen a routine like this?

Thanks,
Brian

2. Explode then Offset.

3. Originally Posted by ReMark
Explode then Offset.
he's looking for something a bit more than that dude lol.

4. Yeah, it would probably be too tough to create a macro that would do that. Forget I suggested it.

5. I wonder what the OP could accomplish if they spent the same time learning how to do some of this themselves, instead of posting duplicate threads. Just saying .

6. Originally Posted by BrianTFC
Hi ALL,

You know how when you offset a rectangle it it stay as a polyline? i need a lisp routine that i can use to offset the rectangle, set the new lines to current layer, and substract the offset distance from both end of the line. i know thats asking alot but has anyone seen a routine like this?

Thanks,
Brian
If you are trying to automate drawing a steel beam you might look at....
http://www.draftsperson.net/index.ph...s_LISP_program

If not, tell us what you are trying to draw, maybe a lisp already exists.

7. Basic lisp pick two pts look up help about the polar command not very hard

Code:
```(setq pt1 (getpoint))
(setq pt2 (getpoint))
(setq offs (getreal))
(setq x1 (car pt1))

now look up polar, distance (hint x1-x2, y1-y2)
work out the 8 points.```

8. It's actually a fairly involved process:

Code:
```(defun c:offlin (/ fs fe fd el cf le en ed pl fl mp hd l10 l11)
(defun mid_pt (s e)
(mapcar '(lambda (a b) (* (+ a b) 0.5)) s e))

(if (and (princ "\nSelect PLINE To Offset")
(setq fs (ssget '((0 . "LWPOLYLINE"))))
(= (sslength fs) 1)
(setq fe (ssname fs 0)
fd (entget fe)
el (cdr (assoc 38 fd))
cf (if (= (logand (cdr (assoc 70 fd)) 1) 1) T nil)
le (entlast)))
(progn
(while (eq le (entlast))
(command "_.CMDECHO" 1
"_.OFFSET" pause fe pause)
(if (not (eq le (entlast)))
(command))
(command "_.CMDECHO" 0))
(setq en (entlast)
ed (entget en))
(entdel en)
(foreach p ed
(if (= 10 (car p))
(setq pl (cons (cdr p) pl))))
(foreach p fd
(if (= 10 (car p))
(setq fl (cons (cdr p) fl))))
(and cf (setq pl (cons (last pl) pl)
fl (cons (last fl) fl)))
(if (= (length pl) (length fl))
(progn
(while (> (length pl) 1)
(setq mp (mid_pt (car pl) (cadr pl))
hd (* (distance (car fl) (cadr fl)) 0.5)
l10 (polar mp (angle (car pl) (cadr pl)) hd)
l11 (polar mp (angle (cadr pl) (car pl)) hd))
(entmake (list (cons 0 "LINE")
(cons 10 (append l10 (list el)))
(cons 11 (append l11 (list el)))))
(setq pl (cdr pl)
fl (cdr fl)))))))
(prin1))```

error trapping with OFFSET type commands are NOT always accurate.

This makes the line segments the same length as original PLINE regardless if the offset side is to the inside or outside.

Have fun! -David

9. Hi-
This is what I thought of from reading your post. (see picture below) Let me know if I misunderstood you.

Offset Rectangle.jpg

This will work on rectangles only. They can be horizontal or rotated.
You need to enter an offset distance and select a rectangle. The routine stays open to allow you to select more than one rectangle. I hope that helps.

Code:
```(defun c:offsetpline (/ CurLayer OffsetDist VlaObj sset num Ang Ptdist StartPt EndPt)

(defun *error* (msg)
(princ)
); _end defun

(setq CurLayer (getvar "clayer"))
(setq OffsetDist (getreal "\nEnter an offset distance: "))

(while (setq VlaObj (vlax-ename->vla-object (car (entsel "Select a Rectangle: "))))
(setq Startpt (vlax-curve-getPointAtParam VlaObj 1))
(setq Ang (+ (angle (vlax-curve-getStartPoint VlaObj)(vlax-curve-getPointAtParam VlaObj 1))(* (/ pi 180) 90)))
(setq PtDist (distance Startpt (vlax-curve-getPointAtParam VlaObj 2)))

(if (equal (polar Startpt Ang PtDist)(vlax-curve-getPointAtParam VlaObj 2) 1.0)
(vl-catch-all-apply 'vlax-invoke-method (list VlaObj 'Offset OffsetDist))
(vl-catch-all-apply 'vlax-invoke-method (list VlaObj 'Offset (- OffsetDist)))
); _end if

(setq VlaObj (vlax-ename->vla-object (entlast)))
(vl-catch-all-apply 'vlax-put (list VlaObj 'Layer CurLayer))
(vl-cmdf "explode" (entlast) "")
(setq sset (ssget "_P"))
(setq num -1)

(repeat (sslength sset)
(setq VlaObj (vlax-ename->vla-object (ssname sset (setq num (1+ num)))))
(setq StartPt (polar (vlax-get VlaObj 'StartPoint)(vlax-get VlaObj 'Angle) OffsetDist))
(vl-catch-all-apply 'vlax-put (list VlaObj 'StartPoint StartPt))
(setq EndPt (polar (vlax-get VlaObj 'EndPoint)(- (vlax-get VlaObj 'Angle) pi) OffsetDist))
(vl-catch-all-apply 'vlax-put (list VlaObj 'EndPoint EndPt))
); _end repeat
); _end while

(princ)
); _end defun```

10. Registered forum members do not see this ad.

That works great thank you for your help.