(defun c:OC (/ AT:Offset ent pnt lst)
;; Offset selected curve and connect each end (also option to convert to LWPolyline).
;; Copyright© Alan J. Thompson, 04.29.10

(defun OC1 (/ AT:Offset ent pnt lst)
;; Offset selected curve and connect each end (also option to convert to LWPolyline).
;; Copyright© Alan J. Thompson, 04.29.10

(defun AT:Offset (O D P / _pt p1 p2 c D g)
;; Offset selected object
;; O - Object to offset
;; D - Distance to offset object
;; P - Point on side of object to offset
;; Alan J. Thompson, 09.12.09 / 03.25.10
(setq _pt (lambda (s)
(vlax-curve-getPointAtDist O (s (vlax-curve-getDistAtPoint O p1) 0.00001))
)
)
(if (and (setq p1 (vlax-curve-getclosestpointtoprojection O (trans P 1 0) '(0 0 1)))
(or (setq p2 (setq c (_pt +))) (setq p2 (_pt -)))
(if (minusp (- (* (- (car p2) (car p1)) (- (cadr (trans P 1 0)) (cadr p1)))
(* (- (cadr p2) (cadr p1)) (- (car (trans P 1 0)) (car p1)))
)
)
(if (vl-position (vla-get-objectname O) '("AcDbLine" "AcDbXline"))
(setq D (- (abs D)))
(setq D (abs D))
)
(if (vl-position (vla-get-objectname O) '("AcDbLine" "AcDbXline"))
(setq D (abs D))
(setq D (- (abs D)))
)
)
(or c (setq D (- D)))
(not (vl-catch-all-error-p (setq g (vl-catch-all-apply 'vla-offset (list O D)))))
)
(car (vlax-safearray->list (vlax-variant-value g)))
)
)

(and (minusp (getvar 'offsetdist)) (setvar 'offsetdist 1.))
(cond
((and
(if AT:Entsel
(setq ent (car (AT:Entsel nil "\nSelect curve: " '("L" (0 . "ARC,LINE,SPLINE,LWPOLYLINE")) nil)))
(and (setq ent (car (entsel "\nSelect curve: ")))
(command "pedit" "l" "" "" )
(or (vl-position (cdr (assoc 0 (entget ent))) '("ARC" "LINE" "SPLINE" "LWPOLYLINE"))
(alert "Invalid object!")
)
)
)
(not (initget 6))
(setvar
'offsetdist
(cond
((getdist (strcat "\nSpecify offset distance or : ")))
((getvar 'offsetdist))
)
)
(setq pnt (getpoint "\nSpecify point on side to offset: "))
((lambda (off)
(if off
(setq lst (list ent (vlax-vla-object->ename off)))
(alert "Cannot offset side of curve!")
)
)
(AT:Offset (vlax-ename->vla-object ent) (getvar 'offsetdist) pnt)
)

)

(or (vlax-curve-isClosed (car lst))
(setq lst (append
(mapcar
(function
(lambda (a b f)
(entmakex
(list '(0 . "LINE")
(assoc 8 (entget ent))
(cons 10 (f a))
(cons 11 (f b))
)
)
)
)
lst
(reverse lst)
(list vlax-curve-getStartPoint vlax-curve-getEndPoint)
)
lst
)

)
)
(initget 0 "Yes No")
(if (and (> (length lst) 2)
(eq "Yes"
(cond ((getkword "\nConvert to closed LWPolyline? [Yes/No] : "))
("Yes")
)
)
)
((lambda (ss)
(if (zerop (getvar 'peditaccept))
(vl-cmdf "_.pedit" "_m" ss "" "_y" "_j" "" "")
(vl-cmdf "_.pedit" "_m" ss "" "_j" "" "")
)
)
((lambda (l s) (foreach x l (ssadd x s))) lst (ssadd))
)
)
)
)
(princ)
)

(oc1)

(defun AT:Offset (O D P / _pt p1 p2 c D g)
;; Offset selected object
;; O - Object to offset
;; D - Distance to offset object
;; P - Point on side of object to offset
;; Alan J. Thompson, 09.12.09 / 03.25.10
(setq _pt (lambda (s)
(vlax-curve-getPointAtDist O (s (vlax-curve-getDistAtPoint O p1) 0.00001))
)
)
(if (and (setq p1 (vlax-curve-getclosestpointtoprojection O (trans P 1 0) '(0 0 1)))
(or (setq p2 (setq c (_pt +))) (setq p2 (_pt -)))
(if (minusp (- (* (- (car p2) (car p1)) (- (cadr (trans P 1 0)) (cadr p1)))
(* (- (cadr p2) (cadr p1)) (- (car (trans P 1 0)) (car p1)))
)
)
(if (vl-position (vla-get-objectname O) '("AcDbLine" "AcDbXline"))
(setq D (- (abs D)))
(setq D (abs D))
)
(if (vl-position (vla-get-objectname O) '("AcDbLine" "AcDbXline"))
(setq D (abs D))
(setq D (- (abs D)))
)
)
(or c (setq D (- D)))
(not (vl-catch-all-error-p (setq g (vl-catch-all-apply 'vla-offset (list O D)))))
)
(car (vlax-safearray->list (vlax-variant-value g)))
)
)

(and (minusp (getvar 'offsetdist)) (setvar 'offsetdist 1.))
(cond
((and
(if AT:Entsel
(setq ent (car (AT:Entsel nil "\nSelect curve: " '("L" (0 . "ARC,LINE,SPLINE,LWPOLYLINE")) nil)))
(and (setq ent (car (entsel "\nSelect curve: ")))

(or (vl-position (cdr (assoc 0 (entget ent))) '("ARC" "LINE" "SPLINE" "LWPOLYLINE"))
(alert "Invalid object!")
)
)
)
(not (initget 6))
(setvar
'offsetdist
(cond
((getdist (strcat "\nSpecify offset distance or : ")))
((getvar 'offsetdist))
)
)
(setq pnt (getpoint "\nSpecify point on side to offset: "))
((lambda (off)
(if off
(setq lst (list ent (vlax-vla-object->ename off)))
(alert "Cannot offset side of curve!")
)
)
(AT:Offset (vlax-ename->vla-object ent) (getvar 'offsetdist) pnt)
)

)

(or (vlax-curve-isClosed (car lst))
(setq lst (append
(mapcar
(function
(lambda (a b f)
(entmakex
(list '(0 . "LINE")
(assoc 8 (entget ent))
(cons 10 (f a))
(cons 11 (f b))
)
)
)
)
lst
(reverse lst)
(list vlax-curve-getStartPoint vlax-curve-getEndPoint)
)
lst
)

)
)
(initget 0 "Yes No")
(if (and (> (length lst) 2)
(eq "Yes"
(cond ((getkword "\nConvert to closed LWPolyline? [Yes/No] : "))
("Yes")
)
)
)
((lambda (ss)
(if (zerop (getvar 'peditaccept))
(vl-cmdf "_.pedit" "_m" ss "" "_y" "_j" "" "")
(vl-cmdf "_.pedit" "_m" ss "" "_j" "" "")
)
)
((lambda (l s) (foreach x l (ssadd x s))) lst (ssadd))
)
)
)
)
(princ)
)

(c:oc)

Advertisements