;Modifyed by Igal Averbuh 2015: Add specifying offset distance by two points on drawing. Add possibility to make nested offset for spline, polyline and ellipse
(defun c:XOFF (/
os_sav Dis Obj Dat Typ side Flag Rad New Beg Last
)

(setvar 'OFFSETDIST
(cond ((getdist (strcat "\nSpecify Offset distance : ")))
((getvar 'OFFSETDIST))
)
)

(setq os_sav (getvar "OFFSETDIST")) ; save normal
offset distance fo later restoration
(if $#ox (= nil) (setq $#ox (rtos (getvar 'OFFSETDIST)))) ; default
global od offset distance for this session
(setq Dis (getreal (strcat "\nOffset distance : ")))
(if Dis (setq $#ox (rtos (getvar 'OFFSETDIST)))) ; set global od dist
to user input if there is one
(setq Obj (nentsel "\nSelect object to offset: "))
(while Obj ; allow
multiple offsets
(setq
Dat (entget (car Obj))
Typ (strcase (cdr (assoc 0 Dat)))
Flag nil
)
(cond
((= Typ "LWPOLYLINE")(setq Flag 1 side (getpoint "\nSide to offset:
")));test LWPOLYLINE
((= Typ "ELLIPSE")(setq Flag 1 side (getpoint "\nSide to offset:
")));test ELLIPSE
((= Typ "SPLINE")(setq Flag 1 side (getpoint "\nSide to offset:
")));test SPLINE
((= Typ "POLYLINE")(setq Flag 1 side (getpoint "\nSide to offset:
")));test POLYLINE
((= Typ "LINE") (setq Flag 1 side (getpoint "\nSide to offset:
")));test LINE
((= Typ "CIRCLE")
(setq
Flag 0
side (getpoint "\nSide to offset: ")
Rad (cdr (assoc 40 Dat))
New (if (< (distance (cdr (assoc 10 Dat)) Side) Rad) (- Rad (getvar 'OFFSETDIST))
(+ Rad (getvar 'OFFSETDIST)))
);setq
);test CIRCLE
((= Typ "ARC")
(setq
Flag 0
side (getpoint "\nSide to offset: ")
Rad (cdr (assoc 40 Dat))
New (if (< (distance (cdr (assoc 10 Dat)) Side) Rad) (- Rad (getvar 'OFFSETDIST))
(+ Rad (getvar 'OFFSETDIST)))
);setq
);test ARC
(T (setq Flag -1));test default
);cond
(setq Beg (subst (cons '8 (getvar "CLAYER"))(assoc 8 Dat) Dat))
(command "UNDO" "BE")
(cond
((= Flag 1) (entmake Beg) (setq Last (entlast)) (command "OFFSET"
(getvar 'OFFSETDIST) Last side "") (entdel Last))
((= Flag 0) (setq Beg (subst (cons '40 New)(assoc 40 Beg) Beg))
(entmake Beg))
((= Flag -1) (prompt "\nCannot offset that object."))
(T (alert "Error encountered"))
)
(setq Obj (nentsel "\nSelect object to offset: ")) ; input for
loop
(command "UNDO" "E")
);while
(setvar "OFFSETDIST" os_sav) ; restore
saved normal offset distance
(princ)
)
(c:XOFF)
;defun

Advertisements